@remix-run/router 1.3.0-pre.0 → 1.3.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.3.0-pre.0",
3
+ "version": "1.3.0-pre.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -371,6 +371,7 @@ type LinkNavigateOptions = {
371
371
  type SubmissionNavigateOptions = {
372
372
  replace?: boolean;
373
373
  state?: any;
374
+ preventScrollReset?: boolean;
374
375
  formMethod?: FormMethod;
375
376
  formEncType?: FormEncType;
376
377
  formData: FormData;
@@ -771,6 +772,14 @@ export function createRouter(init: RouterInit): Router {
771
772
  )
772
773
  : state.loaderData;
773
774
 
775
+ // Always respect the user flag. Otherwise don't reset on mutation
776
+ // submission navigations unless they redirect
777
+ let preventScrollReset =
778
+ pendingPreventScrollReset === true ||
779
+ (state.navigation.formMethod != null &&
780
+ isMutationMethod(state.navigation.formMethod) &&
781
+ location.state?._isRedirect !== true);
782
+
774
783
  updateState({
775
784
  ...newState, // matches, errors, fetchers go through as-is
776
785
  actionData,
@@ -780,11 +789,11 @@ export function createRouter(init: RouterInit): Router {
780
789
  initialized: true,
781
790
  navigation: IDLE_NAVIGATION,
782
791
  revalidation: "idle",
783
- // Don't restore on submission navigations
784
- restoreScrollPosition: state.navigation.formData
785
- ? false
786
- : getSavedScrollPosition(location, newState.matches || state.matches),
787
- preventScrollReset: pendingPreventScrollReset,
792
+ restoreScrollPosition: getSavedScrollPosition(
793
+ location,
794
+ newState.matches || state.matches
795
+ ),
796
+ preventScrollReset,
788
797
  });
789
798
 
790
799
  if (isUninterruptedRevalidation) {
@@ -1772,6 +1781,8 @@ export function createRouter(init: RouterInit): Router {
1772
1781
  ...submission,
1773
1782
  formAction: redirect.location,
1774
1783
  },
1784
+ // Preserve this flag across redirects
1785
+ preventScrollReset: pendingPreventScrollReset,
1775
1786
  });
1776
1787
  } else {
1777
1788
  // Otherwise, we kick off a new loading navigation, preserving the
@@ -1785,6 +1796,8 @@ export function createRouter(init: RouterInit): Router {
1785
1796
  formEncType: submission ? submission.formEncType : undefined,
1786
1797
  formData: submission ? submission.formData : undefined,
1787
1798
  },
1799
+ // Preserve this flag across redirects
1800
+ preventScrollReset: pendingPreventScrollReset,
1788
1801
  });
1789
1802
  }
1790
1803
  }