@remix-run/router 0.0.0-experimental-f92aa2e1 → 0.0.0-experimental-dc8656c8
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/CHANGELOG.md +29 -0
- package/LICENSE.md +3 -2
- package/dist/router.cjs.js +50 -56
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +0 -3
- package/dist/router.js +50 -56
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +50 -56
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/router.ts +53 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
+
## 1.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix `basename` handling when navigating without a path ([#10433](https://github.com/remix-run/react-router/pull/10433))
|
|
8
|
+
- "Same hash" navigations no longer re-run loaders to match browser behavior (i.e. `/path#hash -> /path#hash`) ([#10408](https://github.com/remix-run/react-router/pull/10408))
|
|
9
|
+
|
|
10
|
+
## 1.6.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Enable relative routing in the `@remix-run/router` when providing a source route ID from which the path is relative to: ([#10336](https://github.com/remix-run/react-router/pull/10336))
|
|
15
|
+
|
|
16
|
+
- Example: `router.navigate("../path", { fromRouteId: "some-route" })`.
|
|
17
|
+
- This also applies to `router.fetch` which already receives a source route ID
|
|
18
|
+
|
|
19
|
+
- Introduce a new `@remix-run/router` `future.v7_prependBasename` flag to enable `basename` prefixing to all paths coming into `router.navigate` and `router.fetch`.
|
|
20
|
+
|
|
21
|
+
- Previously the `basename` was prepended in the React Router layer, but now that relative routing is being handled by the router we need prepend the `basename` _after_ resolving any relative paths
|
|
22
|
+
- This also enables `basename` support in `useFetcher` as well
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Enhance `LoaderFunction`/`ActionFunction` return type to prevent `undefined` from being a valid return value ([#10267](https://github.com/remix-run/react-router/pull/10267))
|
|
27
|
+
- Ensure proper 404 error on `fetcher.load` call to a route without a `loader` ([#10345](https://github.com/remix-run/react-router/pull/10345))
|
|
28
|
+
- Deprecate the `createRouter` `detectErrorBoundary` option in favor of the new `mapRouteProperties` option for converting a framework-agnostic route to a framework-aware route. This allows us to set more than just the `hasErrorBoundary` property during route pre-processing, and is now used for mapping `Component -> element` and `ErrorBoundary -> errorElement` in `react-router`. ([#10287](https://github.com/remix-run/react-router/pull/10287))
|
|
29
|
+
- Fixed a bug where fetchers were incorrectly attempting to revalidate on search params changes or routing to the same URL (using the same logic for route `loader` revalidations). However, since fetchers have a static href, they should only revalidate on `action` submissions or `router.revalidate` calls. ([#10344](https://github.com/remix-run/react-router/pull/10344))
|
|
30
|
+
- Decouple `AbortController` usage between revalidating fetchers and the thing that triggered them such that the unmount/deletion of a revalidating fetcher doesn't impact the ongoing triggering navigation/revalidation ([#10271](https://github.com/remix-run/react-router/pull/10271))
|
|
31
|
+
|
|
3
32
|
## 1.5.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) React Training 2015-2019
|
|
4
|
-
Copyright (c) Remix Software 2020-
|
|
3
|
+
Copyright (c) React Training LLC 2015-2019
|
|
4
|
+
Copyright (c) Remix Software Inc. 2020-2021
|
|
5
|
+
Copyright (c) Shopify Inc. 2022-2023
|
|
5
6
|
|
|
6
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v0.0.0-experimental-
|
|
2
|
+
* @remix-run/router v0.0.0-experimental-dc8656c8
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -1936,12 +1936,14 @@ function createRouter(init) {
|
|
|
1936
1936
|
}
|
|
1937
1937
|
});
|
|
1938
1938
|
return;
|
|
1939
|
-
} // Short circuit if it's only a hash change and not a mutation submission
|
|
1939
|
+
} // Short circuit if it's only a hash change and not a mutation submission.
|
|
1940
|
+
// Ignore on initial page loads because since the initial load will always
|
|
1941
|
+
// be "same hash".
|
|
1940
1942
|
// For example, on /page#hash and submit a <Form method="post"> which will
|
|
1941
1943
|
// default to a navigation to /page
|
|
1942
1944
|
|
|
1943
1945
|
|
|
1944
|
-
if (isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
|
1946
|
+
if (state.initialized && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
|
1945
1947
|
completeNavigation(location, {
|
|
1946
1948
|
matches
|
|
1947
1949
|
});
|
|
@@ -2167,8 +2169,7 @@ function createRouter(init) {
|
|
|
2167
2169
|
formMethod: undefined,
|
|
2168
2170
|
formAction: undefined,
|
|
2169
2171
|
formEncType: undefined,
|
|
2170
|
-
formData: undefined
|
|
2171
|
-
" _hasFetcherDoneAnything ": true
|
|
2172
|
+
formData: undefined
|
|
2172
2173
|
};
|
|
2173
2174
|
state.fetchers.set(rf.key, revalidatingFetcher);
|
|
2174
2175
|
});
|
|
@@ -2324,8 +2325,7 @@ function createRouter(init) {
|
|
|
2324
2325
|
let fetcher = _extends({
|
|
2325
2326
|
state: "submitting"
|
|
2326
2327
|
}, submission, {
|
|
2327
|
-
data: existingFetcher && existingFetcher.data
|
|
2328
|
-
" _hasFetcherDoneAnything ": true
|
|
2328
|
+
data: existingFetcher && existingFetcher.data
|
|
2329
2329
|
});
|
|
2330
2330
|
|
|
2331
2331
|
state.fetchers.set(key, fetcher);
|
|
@@ -2355,8 +2355,7 @@ function createRouter(init) {
|
|
|
2355
2355
|
let loadingFetcher = _extends({
|
|
2356
2356
|
state: "loading"
|
|
2357
2357
|
}, submission, {
|
|
2358
|
-
data: undefined
|
|
2359
|
-
" _hasFetcherDoneAnything ": true
|
|
2358
|
+
data: undefined
|
|
2360
2359
|
});
|
|
2361
2360
|
|
|
2362
2361
|
state.fetchers.set(key, loadingFetcher);
|
|
@@ -2364,8 +2363,7 @@ function createRouter(init) {
|
|
|
2364
2363
|
fetchers: new Map(state.fetchers)
|
|
2365
2364
|
});
|
|
2366
2365
|
return startRedirectNavigation(state, actionResult, {
|
|
2367
|
-
submission
|
|
2368
|
-
isFetchActionRedirect: true
|
|
2366
|
+
fetcherSubmission: submission
|
|
2369
2367
|
});
|
|
2370
2368
|
} // Process any non-redirect errors thrown
|
|
2371
2369
|
|
|
@@ -2394,9 +2392,7 @@ function createRouter(init) {
|
|
|
2394
2392
|
let loadFetcher = _extends({
|
|
2395
2393
|
state: "loading",
|
|
2396
2394
|
data: actionResult.data
|
|
2397
|
-
}, submission
|
|
2398
|
-
" _hasFetcherDoneAnything ": true
|
|
2399
|
-
});
|
|
2395
|
+
}, submission);
|
|
2400
2396
|
|
|
2401
2397
|
state.fetchers.set(key, loadFetcher);
|
|
2402
2398
|
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, fetchLoadMatches, routesToUse, basename, {
|
|
@@ -2415,8 +2411,7 @@ function createRouter(init) {
|
|
|
2415
2411
|
formMethod: undefined,
|
|
2416
2412
|
formAction: undefined,
|
|
2417
2413
|
formEncType: undefined,
|
|
2418
|
-
formData: undefined
|
|
2419
|
-
" _hasFetcherDoneAnything ": true
|
|
2414
|
+
formData: undefined
|
|
2420
2415
|
};
|
|
2421
2416
|
state.fetchers.set(staleKey, revalidatingFetcher);
|
|
2422
2417
|
|
|
@@ -2462,8 +2457,7 @@ function createRouter(init) {
|
|
|
2462
2457
|
formMethod: undefined,
|
|
2463
2458
|
formAction: undefined,
|
|
2464
2459
|
formEncType: undefined,
|
|
2465
|
-
formData: undefined
|
|
2466
|
-
" _hasFetcherDoneAnything ": true
|
|
2460
|
+
formData: undefined
|
|
2467
2461
|
};
|
|
2468
2462
|
state.fetchers.set(key, doneFetcher);
|
|
2469
2463
|
let didAbortFetchLoads = abortStaleFetchLoads(loadId); // If we are currently in a navigation loading state and this fetcher is
|
|
@@ -2504,8 +2498,7 @@ function createRouter(init) {
|
|
|
2504
2498
|
formEncType: undefined,
|
|
2505
2499
|
formData: undefined
|
|
2506
2500
|
}, submission, {
|
|
2507
|
-
data: existingFetcher && existingFetcher.data
|
|
2508
|
-
" _hasFetcherDoneAnything ": true
|
|
2501
|
+
data: existingFetcher && existingFetcher.data
|
|
2509
2502
|
});
|
|
2510
2503
|
|
|
2511
2504
|
state.fetchers.set(key, loadingFetcher);
|
|
@@ -2566,8 +2559,7 @@ function createRouter(init) {
|
|
|
2566
2559
|
formMethod: undefined,
|
|
2567
2560
|
formAction: undefined,
|
|
2568
2561
|
formEncType: undefined,
|
|
2569
|
-
formData: undefined
|
|
2570
|
-
" _hasFetcherDoneAnything ": true
|
|
2562
|
+
formData: undefined
|
|
2571
2563
|
};
|
|
2572
2564
|
state.fetchers.set(key, doneFetcher);
|
|
2573
2565
|
updateState({
|
|
@@ -2600,20 +2592,17 @@ function createRouter(init) {
|
|
|
2600
2592
|
|
|
2601
2593
|
let {
|
|
2602
2594
|
submission,
|
|
2603
|
-
|
|
2604
|
-
|
|
2595
|
+
fetcherSubmission,
|
|
2596
|
+
replace
|
|
2605
2597
|
} = _temp === void 0 ? {} : _temp;
|
|
2606
2598
|
|
|
2607
2599
|
if (redirect.revalidate) {
|
|
2608
2600
|
isRevalidationRequired = true;
|
|
2609
2601
|
}
|
|
2610
2602
|
|
|
2611
|
-
let redirectLocation = createLocation(state.location, redirect.location,
|
|
2612
|
-
_extends({
|
|
2603
|
+
let redirectLocation = createLocation(state.location, redirect.location, {
|
|
2613
2604
|
_isRedirect: true
|
|
2614
|
-
}
|
|
2615
|
-
_isFetchActionRedirect: true
|
|
2616
|
-
} : {}));
|
|
2605
|
+
});
|
|
2617
2606
|
invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an absolute external redirect that goes to a new origin
|
|
2618
2607
|
|
|
2619
2608
|
if (ABSOLUTE_URL_REGEX.test(redirect.location) && isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
|
|
@@ -2644,7 +2633,7 @@ function createRouter(init) {
|
|
|
2644
2633
|
formData
|
|
2645
2634
|
} = state.navigation;
|
|
2646
2635
|
|
|
2647
|
-
if (!submission && formMethod && formAction && formData && formEncType) {
|
|
2636
|
+
if (!submission && !fetcherSubmission && formMethod && formAction && formData && formEncType) {
|
|
2648
2637
|
submission = {
|
|
2649
2638
|
formMethod,
|
|
2650
2639
|
formAction,
|
|
@@ -2656,30 +2645,16 @@ function createRouter(init) {
|
|
|
2656
2645
|
// redirected location
|
|
2657
2646
|
|
|
2658
2647
|
|
|
2659
|
-
|
|
2648
|
+
let activeSubmission = submission || fetcherSubmission;
|
|
2649
|
+
|
|
2650
|
+
if (redirectPreserveMethodStatusCodes.has(redirect.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
|
|
2660
2651
|
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
2661
|
-
submission: _extends({},
|
|
2652
|
+
submission: _extends({}, activeSubmission, {
|
|
2662
2653
|
formAction: redirect.location
|
|
2663
2654
|
}),
|
|
2664
2655
|
// Preserve this flag across redirects
|
|
2665
2656
|
preventScrollReset: pendingPreventScrollReset
|
|
2666
2657
|
});
|
|
2667
|
-
} else if (isFetchActionRedirect) {
|
|
2668
|
-
// For a fetch action redirect, we kick off a new loading navigation
|
|
2669
|
-
// without the fetcher submission, but we send it along for shouldRevalidate
|
|
2670
|
-
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
2671
|
-
overrideNavigation: {
|
|
2672
|
-
state: "loading",
|
|
2673
|
-
location: redirectLocation,
|
|
2674
|
-
formMethod: undefined,
|
|
2675
|
-
formAction: undefined,
|
|
2676
|
-
formEncType: undefined,
|
|
2677
|
-
formData: undefined
|
|
2678
|
-
},
|
|
2679
|
-
fetcherSubmission: submission,
|
|
2680
|
-
// Preserve this flag across redirects
|
|
2681
|
-
preventScrollReset: pendingPreventScrollReset
|
|
2682
|
-
});
|
|
2683
2658
|
} else {
|
|
2684
2659
|
// Otherwise, we kick off a new loading navigation, preserving the
|
|
2685
2660
|
// submission info for the duration of this navigation
|
|
@@ -2687,11 +2662,14 @@ function createRouter(init) {
|
|
|
2687
2662
|
overrideNavigation: {
|
|
2688
2663
|
state: "loading",
|
|
2689
2664
|
location: redirectLocation,
|
|
2665
|
+
// Only include navigational submissions on the navigation
|
|
2690
2666
|
formMethod: submission ? submission.formMethod : undefined,
|
|
2691
2667
|
formAction: submission ? submission.formAction : undefined,
|
|
2692
2668
|
formEncType: submission ? submission.formEncType : undefined,
|
|
2693
2669
|
formData: submission ? submission.formData : undefined
|
|
2694
2670
|
},
|
|
2671
|
+
// Send fetcher submissions through for shouldRevalidate
|
|
2672
|
+
fetcherSubmission,
|
|
2695
2673
|
// Preserve this flag across redirects
|
|
2696
2674
|
preventScrollReset: pendingPreventScrollReset
|
|
2697
2675
|
});
|
|
@@ -2775,8 +2753,7 @@ function createRouter(init) {
|
|
|
2775
2753
|
formMethod: undefined,
|
|
2776
2754
|
formAction: undefined,
|
|
2777
2755
|
formEncType: undefined,
|
|
2778
|
-
formData: undefined
|
|
2779
|
-
" _hasFetcherDoneAnything ": true
|
|
2756
|
+
formData: undefined
|
|
2780
2757
|
};
|
|
2781
2758
|
state.fetchers.set(key, doneFetcher);
|
|
2782
2759
|
}
|
|
@@ -2953,7 +2930,8 @@ function createRouter(init) {
|
|
|
2953
2930
|
}
|
|
2954
2931
|
|
|
2955
2932
|
function _internalSetRoutes(newRoutes) {
|
|
2956
|
-
|
|
2933
|
+
manifest = {};
|
|
2934
|
+
inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);
|
|
2957
2935
|
}
|
|
2958
2936
|
|
|
2959
2937
|
router = {
|
|
@@ -3454,7 +3432,7 @@ function normalizeTo(location, matches, basename, prependBasename, to, fromRoute
|
|
|
3454
3432
|
} // Resolve the relative path
|
|
3455
3433
|
|
|
3456
3434
|
|
|
3457
|
-
let path = resolveTo(to ? to : ".", getPathContributingMatches(contextualMatches).map(m => m.pathnameBase), location.pathname, relative === "path"); // When `to` is not specified we inherit search/hash from the current
|
|
3435
|
+
let path = resolveTo(to ? to : ".", getPathContributingMatches(contextualMatches).map(m => m.pathnameBase), stripBasename(location.pathname, basename) || location.pathname, relative === "path"); // When `to` is not specified we inherit search/hash from the current
|
|
3458
3436
|
// location, unlike when to="." and we just inherit the path.
|
|
3459
3437
|
// See https://github.com/remix-run/remix/issues/927
|
|
3460
3438
|
|
|
@@ -3588,7 +3566,7 @@ function getMatchesToLoad(history, state, matches, submission, location, isReval
|
|
|
3588
3566
|
actionResult,
|
|
3589
3567
|
defaultShouldRevalidate: // Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate
|
|
3590
3568
|
isRevalidationRequired || // Clicked the same link, resubmitted a GET form
|
|
3591
|
-
currentUrl.
|
|
3569
|
+
currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search || // Search params affect all loaders
|
|
3592
3570
|
currentUrl.search !== nextUrl.search || isNewRouteInstance(currentRouteMatch, nextRouteMatch)
|
|
3593
3571
|
}));
|
|
3594
3572
|
}); // Pick fetcher.loads that need to be revalidated
|
|
@@ -4085,8 +4063,7 @@ function processLoaderData(state, matches, matchesToLoad, results, pendingError,
|
|
|
4085
4063
|
formMethod: undefined,
|
|
4086
4064
|
formAction: undefined,
|
|
4087
4065
|
formEncType: undefined,
|
|
4088
|
-
formData: undefined
|
|
4089
|
-
" _hasFetcherDoneAnything ": true
|
|
4066
|
+
formData: undefined
|
|
4090
4067
|
};
|
|
4091
4068
|
state.fetchers.set(key, doneFetcher);
|
|
4092
4069
|
}
|
|
@@ -4203,7 +4180,24 @@ function stripHashFromPath(path) {
|
|
|
4203
4180
|
}
|
|
4204
4181
|
|
|
4205
4182
|
function isHashChangeOnly(a, b) {
|
|
4206
|
-
|
|
4183
|
+
if (a.pathname !== b.pathname || a.search !== b.search) {
|
|
4184
|
+
return false;
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
if (a.hash === "") {
|
|
4188
|
+
// /page -> /page#hash
|
|
4189
|
+
return b.hash !== "";
|
|
4190
|
+
} else if (a.hash === b.hash) {
|
|
4191
|
+
// /page#hash -> /page#hash
|
|
4192
|
+
return true;
|
|
4193
|
+
} else if (b.hash !== "") {
|
|
4194
|
+
// /page#hash -> /page#other
|
|
4195
|
+
return true;
|
|
4196
|
+
} // If the hash is removed the browser will re-perform a request to the server
|
|
4197
|
+
// /page#hash -> /page
|
|
4198
|
+
|
|
4199
|
+
|
|
4200
|
+
return false;
|
|
4207
4201
|
}
|
|
4208
4202
|
|
|
4209
4203
|
function isDeferredResult(result) {
|