Don't call a route's init when staying on the same path.

This commit is contained in:
Dillon Kearns 2022-10-19 15:14:57 -07:00
parent 5ccf361985
commit 98736e0a39

View File

@ -423,9 +423,7 @@ update config appMsg model =
) )
else else
( { model ( model
| url = url
}
, NoEffect , NoEffect
) )
-- TODO is it reasonable to always re-fetch route data if you re-navigate to the current route? Might be a good -- TODO is it reasonable to always re-fetch route data if you re-navigate to the current route? Might be a good
@ -605,10 +603,14 @@ update config appMsg model =
, actionData = newActionData , actionData = newActionData
} }
( userModel, _ ) = ( userModel, userEffect ) =
-- TODO if urlWithoutRedirectResolution is different from the url with redirect resolution, then -- TODO if urlWithoutRedirectResolution is different from the url with redirect resolution, then
-- instead of calling update, call pushUrl (I think?) -- instead of calling update, call pushUrl (I think?)
-- TODO include user Cmd -- TODO include user Cmd
if stayingOnSamePath then
( previousPageData.userModel, NoEffect )
else
config.update model.pageFormState config.update model.pageFormState
(model.inFlightFetchers |> toFetcherState) (model.inFlightFetchers |> toFetcherState)
(model.transition |> Maybe.map Tuple.second) (model.transition |> Maybe.map Tuple.second)
@ -626,6 +628,7 @@ update config appMsg model =
} }
) )
previousPageData.userModel previousPageData.userModel
|> Tuple.mapSecond UserCmd
updatedModel : Model userModel pageData actionData sharedData updatedModel : Model userModel pageData actionData sharedData
updatedModel = updatedModel =
@ -656,10 +659,13 @@ update config appMsg model =
, currentPath = newUrl.path , currentPath = newUrl.path
} }
, if not stayingOnSamePath && scrollToTopWhenDone then , if not stayingOnSamePath && scrollToTopWhenDone then
ScrollToTop Batch
[ ScrollToTop
, userEffect
]
else else
NoEffect userEffect
) )
|> (case maybeUserMsg of |> (case maybeUserMsg of
Just userMsg -> Just userMsg ->
@ -1392,7 +1398,8 @@ loadDataAndUpdateUrl ( newPageData, newSharedData, newActionData ) maybeUserMsg
, actionData = newActionData , actionData = newActionData
} }
( userModel, _ ) = -- TODO use userEffect here?
( userModel, userEffect ) =
-- TODO if urlWithoutRedirectResolution is different from the url with redirect resolution, then -- TODO if urlWithoutRedirectResolution is different from the url with redirect resolution, then
-- instead of calling update, call pushUrl (I think?) -- instead of calling update, call pushUrl (I think?)
-- TODO include user Cmd -- TODO include user Cmd