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,27 +603,32 @@ 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
config.update model.pageFormState if stayingOnSamePath then
(model.inFlightFetchers |> toFetcherState) ( previousPageData.userModel, NoEffect )
(model.transition |> Maybe.map Tuple.second)
newSharedData else
newPageData config.update model.pageFormState
model.key (model.inFlightFetchers |> toFetcherState)
(config.onPageChange (model.transition |> Maybe.map Tuple.second)
{ protocol = model.url.protocol newSharedData
, host = model.url.host newPageData
, port_ = model.url.port_ model.key
, path = urlPathToPath urlWithoutRedirectResolution (config.onPageChange
, query = urlWithoutRedirectResolution.query { protocol = model.url.protocol
, fragment = urlWithoutRedirectResolution.fragment , host = model.url.host
, metadata = config.urlToRoute urlWithoutRedirectResolution , port_ = model.url.port_
} , path = urlPathToPath urlWithoutRedirectResolution
) , query = urlWithoutRedirectResolution.query
previousPageData.userModel , fragment = urlWithoutRedirectResolution.fragment
, metadata = config.urlToRoute urlWithoutRedirectResolution
}
)
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