Skip to content

Commit

Permalink
Extract entire restoreScrollPosition variable
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jan 10, 2023
1 parent 0cdb3ac commit 859b093
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,12 @@ export function createRouter(init: RouterInit): Router {
)
: state.loaderData;

// Don't restore on submission navigations when no redirection
let preventScrollRestoration =
state.navigation.formData && location.state?._isRedirect !== true;
// Don't restore on submission navigations unless they redirect
let restoreScrollPosition =
state.navigation.formData && location.state?._isRedirect !== true
? false
: getSavedScrollPosition(location, newState.matches || state.matches);

updateState({
...newState, // matches, errors, fetchers go through as-is
actionData,
Expand All @@ -783,9 +786,7 @@ export function createRouter(init: RouterInit): Router {
initialized: true,
navigation: IDLE_NAVIGATION,
revalidation: "idle",
restoreScrollPosition: preventScrollRestoration
? false
: getSavedScrollPosition(location, newState.matches || state.matches),
restoreScrollPosition,
preventScrollReset: pendingPreventScrollReset,
});

Expand Down

0 comments on commit 859b093

Please sign in to comment.