@remix-run/router 0.0.0-experimental-bcda00aaf → 0.0.0-experimental-1116190f7
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 +26 -0
- package/dist/router.cjs.js +163 -152
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +156 -149
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +163 -152
- 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 +198 -189
package/dist/router.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v0.0.0-experimental-
|
|
2
|
+
* @remix-run/router v0.0.0-experimental-1116190f7
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -1743,6 +1743,7 @@
|
|
|
1743
1743
|
// SSR did the initial scroll restoration.
|
|
1744
1744
|
let initialScrollRestored = init.hydrationData != null;
|
|
1745
1745
|
let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
|
1746
|
+
let initialMatchesIsFOW = false;
|
|
1746
1747
|
let initialErrors = null;
|
|
1747
1748
|
if (initialMatches == null && !patchRoutesOnNavigationImpl) {
|
|
1748
1749
|
// If we do not match a user-provided-route, fall back to the root
|
|
@@ -1783,6 +1784,7 @@
|
|
|
1783
1784
|
if (future.v7_partialHydration) {
|
|
1784
1785
|
let fogOfWar = checkFogOfWar(null, dataRoutes, init.history.location.pathname);
|
|
1785
1786
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
1787
|
+
initialMatchesIsFOW = true;
|
|
1786
1788
|
initialMatches = fogOfWar.matches;
|
|
1787
1789
|
}
|
|
1788
1790
|
}
|
|
@@ -1799,25 +1801,12 @@
|
|
|
1799
1801
|
// were marked for explicit hydration
|
|
1800
1802
|
let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
|
1801
1803
|
let errors = init.hydrationData ? init.hydrationData.errors : null;
|
|
1802
|
-
let isRouteInitialized = m => {
|
|
1803
|
-
// No loader, nothing to initialize
|
|
1804
|
-
if (!m.route.loader) {
|
|
1805
|
-
return true;
|
|
1806
|
-
}
|
|
1807
|
-
// Explicitly opting-in to running on hydration
|
|
1808
|
-
if (typeof m.route.loader === "function" && m.route.loader.hydrate === true) {
|
|
1809
|
-
return false;
|
|
1810
|
-
}
|
|
1811
|
-
// Otherwise, initialized if hydrated with data or an error
|
|
1812
|
-
return loaderData && loaderData[m.route.id] !== undefined || errors && errors[m.route.id] !== undefined;
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
1804
|
// If errors exist, don't consider routes below the boundary
|
|
1816
1805
|
if (errors) {
|
|
1817
1806
|
let idx = initialMatches.findIndex(m => errors[m.route.id] !== undefined);
|
|
1818
|
-
initialized = initialMatches.slice(0, idx + 1).every(
|
|
1807
|
+
initialized = initialMatches.slice(0, idx + 1).every(m => !shouldLoadRouteOnHydration(m.route, loaderData, errors));
|
|
1819
1808
|
} else {
|
|
1820
|
-
initialized = initialMatches.every(
|
|
1809
|
+
initialized = initialMatches.every(m => !shouldLoadRouteOnHydration(m.route, loaderData, errors));
|
|
1821
1810
|
}
|
|
1822
1811
|
} else {
|
|
1823
1812
|
// Without partial hydration - we're initialized if we were provided any
|
|
@@ -1917,10 +1906,6 @@
|
|
|
1917
1906
|
// we don't need to update UI state if they change
|
|
1918
1907
|
let blockerFunctions = new Map();
|
|
1919
1908
|
|
|
1920
|
-
// Map of pending patchRoutesOnNavigation() promises (keyed by path/matches) so
|
|
1921
|
-
// that we only kick them off once for a given combo
|
|
1922
|
-
let pendingPatchRoutes = new Map();
|
|
1923
|
-
|
|
1924
1909
|
// Flag to ignore the next history update, so we can revert the URL change on
|
|
1925
1910
|
// a POP navigation that was blocked by the user without touching router state
|
|
1926
1911
|
let unblockBlockerHistoryUpdate = undefined;
|
|
@@ -2316,7 +2301,9 @@
|
|
|
2316
2301
|
pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
|
2317
2302
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2318
2303
|
let loadingNavigation = opts && opts.overrideNavigation;
|
|
2319
|
-
let matches =
|
|
2304
|
+
let matches = opts != null && opts.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ?
|
|
2305
|
+
// `matchRoutes()` has already been called if we're in here via `router.initialize()`
|
|
2306
|
+
state.matches : matchRoutes(routesToUse, location, basename);
|
|
2320
2307
|
let flushSync = (opts && opts.flushSync) === true;
|
|
2321
2308
|
let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
|
2322
2309
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
@@ -2345,7 +2332,7 @@
|
|
|
2345
2332
|
// Short circuit if it's only a hash change and not a revalidation or
|
|
2346
2333
|
// mutation submission.
|
|
2347
2334
|
//
|
|
2348
|
-
// Ignore on initial page loads because since the initial
|
|
2335
|
+
// Ignore on initial page loads because since the initial hydration will always
|
|
2349
2336
|
// be "same hash". For example, on /page#hash and submit a <Form method="post">
|
|
2350
2337
|
// which will default to a navigation to /page
|
|
2351
2338
|
if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
|
@@ -2452,15 +2439,12 @@
|
|
|
2452
2439
|
shortCircuited: true
|
|
2453
2440
|
};
|
|
2454
2441
|
} else if (discoverResult.type === "error") {
|
|
2455
|
-
let
|
|
2456
|
-
boundaryId,
|
|
2457
|
-
error
|
|
2458
|
-
} = handleDiscoverRouteError(location.pathname, discoverResult);
|
|
2442
|
+
let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
|
2459
2443
|
return {
|
|
2460
2444
|
matches: discoverResult.partialMatches,
|
|
2461
2445
|
pendingActionResult: [boundaryId, {
|
|
2462
2446
|
type: ResultType.error,
|
|
2463
|
-
error
|
|
2447
|
+
error: discoverResult.error
|
|
2464
2448
|
}]
|
|
2465
2449
|
};
|
|
2466
2450
|
} else if (!discoverResult.matches) {
|
|
@@ -2590,15 +2574,12 @@
|
|
|
2590
2574
|
shortCircuited: true
|
|
2591
2575
|
};
|
|
2592
2576
|
} else if (discoverResult.type === "error") {
|
|
2593
|
-
let
|
|
2594
|
-
boundaryId,
|
|
2595
|
-
error
|
|
2596
|
-
} = handleDiscoverRouteError(location.pathname, discoverResult);
|
|
2577
|
+
let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
|
2597
2578
|
return {
|
|
2598
2579
|
matches: discoverResult.partialMatches,
|
|
2599
2580
|
loaderData: {},
|
|
2600
2581
|
errors: {
|
|
2601
|
-
[boundaryId]: error
|
|
2582
|
+
[boundaryId]: discoverResult.error
|
|
2602
2583
|
}
|
|
2603
2584
|
};
|
|
2604
2585
|
} else if (!discoverResult.matches) {
|
|
@@ -2664,9 +2645,7 @@
|
|
|
2664
2645
|
});
|
|
2665
2646
|
}
|
|
2666
2647
|
revalidatingFetchers.forEach(rf => {
|
|
2667
|
-
|
|
2668
|
-
abortFetcher(rf.key);
|
|
2669
|
-
}
|
|
2648
|
+
abortFetcher(rf.key);
|
|
2670
2649
|
if (rf.controller) {
|
|
2671
2650
|
// Fetchers use an independent AbortController so that aborting a fetcher
|
|
2672
2651
|
// (via deleteFetcher) does not abort the triggering navigation that
|
|
@@ -2726,7 +2705,7 @@
|
|
|
2726
2705
|
let {
|
|
2727
2706
|
loaderData,
|
|
2728
2707
|
errors
|
|
2729
|
-
} = processLoaderData(state, matches,
|
|
2708
|
+
} = processLoaderData(state, matches, loaderResults, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds);
|
|
2730
2709
|
|
|
2731
2710
|
// Wire up subscribers to update loaderData as promises settle
|
|
2732
2711
|
activeDeferreds.forEach((deferredData, routeId) => {
|
|
@@ -2740,17 +2719,9 @@
|
|
|
2740
2719
|
});
|
|
2741
2720
|
});
|
|
2742
2721
|
|
|
2743
|
-
//
|
|
2722
|
+
// Preserve SSR errors during partial hydration
|
|
2744
2723
|
if (future.v7_partialHydration && initialHydration && state.errors) {
|
|
2745
|
-
|
|
2746
|
-
let [id] = _ref2;
|
|
2747
|
-
return !matchesToLoad.some(m => m.route.id === id);
|
|
2748
|
-
}).forEach(_ref3 => {
|
|
2749
|
-
let [routeId, error] = _ref3;
|
|
2750
|
-
errors = Object.assign(errors || {}, {
|
|
2751
|
-
[routeId]: error
|
|
2752
|
-
});
|
|
2753
|
-
});
|
|
2724
|
+
errors = _extends({}, state.errors, errors);
|
|
2754
2725
|
}
|
|
2755
2726
|
let updatedFetchers = markFetchRedirectsDone();
|
|
2756
2727
|
let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId);
|
|
@@ -2793,7 +2764,7 @@
|
|
|
2793
2764
|
if (isServer) {
|
|
2794
2765
|
throw new Error("router.fetch() was called during the server render, but it shouldn't be. " + "You are likely calling a useFetcher() method in the body of your component. " + "Try moving it to a useEffect or a callback.");
|
|
2795
2766
|
}
|
|
2796
|
-
|
|
2767
|
+
abortFetcher(key);
|
|
2797
2768
|
let flushSync = (opts && opts.flushSync) === true;
|
|
2798
2769
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2799
2770
|
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative);
|
|
@@ -2822,9 +2793,9 @@
|
|
|
2822
2793
|
return;
|
|
2823
2794
|
}
|
|
2824
2795
|
let match = getTargetMatch(matches, path);
|
|
2825
|
-
|
|
2796
|
+
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
2826
2797
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
2827
|
-
handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
|
|
2798
|
+
handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
|
|
2828
2799
|
return;
|
|
2829
2800
|
}
|
|
2830
2801
|
|
|
@@ -2834,12 +2805,12 @@
|
|
|
2834
2805
|
routeId,
|
|
2835
2806
|
path
|
|
2836
2807
|
});
|
|
2837
|
-
handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
|
|
2808
|
+
handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
|
|
2838
2809
|
}
|
|
2839
2810
|
|
|
2840
2811
|
// Call the action for the matched fetcher.submit(), and then handle redirects,
|
|
2841
2812
|
// errors, and revalidation
|
|
2842
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, submission) {
|
|
2813
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
2843
2814
|
interruptActiveLoads();
|
|
2844
2815
|
fetchLoadMatches.delete(key);
|
|
2845
2816
|
function detectAndHandle405Error(m) {
|
|
@@ -2872,10 +2843,7 @@
|
|
|
2872
2843
|
if (discoverResult.type === "aborted") {
|
|
2873
2844
|
return;
|
|
2874
2845
|
} else if (discoverResult.type === "error") {
|
|
2875
|
-
|
|
2876
|
-
error
|
|
2877
|
-
} = handleDiscoverRouteError(path, discoverResult);
|
|
2878
|
-
setFetcherError(key, routeId, error, {
|
|
2846
|
+
setFetcherError(key, routeId, discoverResult.error, {
|
|
2879
2847
|
flushSync
|
|
2880
2848
|
});
|
|
2881
2849
|
return;
|
|
@@ -2932,7 +2900,8 @@
|
|
|
2932
2900
|
fetchRedirectIds.add(key);
|
|
2933
2901
|
updateFetcherState(key, getLoadingFetcher(submission));
|
|
2934
2902
|
return startRedirectNavigation(fetchRequest, actionResult, false, {
|
|
2935
|
-
fetcherSubmission: submission
|
|
2903
|
+
fetcherSubmission: submission,
|
|
2904
|
+
preventScrollReset
|
|
2936
2905
|
});
|
|
2937
2906
|
}
|
|
2938
2907
|
}
|
|
@@ -2970,9 +2939,7 @@
|
|
|
2970
2939
|
let existingFetcher = state.fetchers.get(staleKey);
|
|
2971
2940
|
let revalidatingFetcher = getLoadingFetcher(undefined, existingFetcher ? existingFetcher.data : undefined);
|
|
2972
2941
|
state.fetchers.set(staleKey, revalidatingFetcher);
|
|
2973
|
-
|
|
2974
|
-
abortFetcher(staleKey);
|
|
2975
|
-
}
|
|
2942
|
+
abortFetcher(staleKey);
|
|
2976
2943
|
if (rf.controller) {
|
|
2977
2944
|
fetchControllers.set(staleKey, rf.controller);
|
|
2978
2945
|
}
|
|
@@ -2995,7 +2962,9 @@
|
|
|
2995
2962
|
revalidatingFetchers.forEach(r => fetchControllers.delete(r.key));
|
|
2996
2963
|
let redirect = findRedirect(loaderResults);
|
|
2997
2964
|
if (redirect) {
|
|
2998
|
-
return startRedirectNavigation(revalidationRequest, redirect.result, false
|
|
2965
|
+
return startRedirectNavigation(revalidationRequest, redirect.result, false, {
|
|
2966
|
+
preventScrollReset
|
|
2967
|
+
});
|
|
2999
2968
|
}
|
|
3000
2969
|
redirect = findRedirect(fetcherResults);
|
|
3001
2970
|
if (redirect) {
|
|
@@ -3003,14 +2972,16 @@
|
|
|
3003
2972
|
// fetchRedirectIds so it doesn't get revalidated on the next set of
|
|
3004
2973
|
// loader executions
|
|
3005
2974
|
fetchRedirectIds.add(redirect.key);
|
|
3006
|
-
return startRedirectNavigation(revalidationRequest, redirect.result, false
|
|
2975
|
+
return startRedirectNavigation(revalidationRequest, redirect.result, false, {
|
|
2976
|
+
preventScrollReset
|
|
2977
|
+
});
|
|
3007
2978
|
}
|
|
3008
2979
|
|
|
3009
2980
|
// Process and commit output from loaders
|
|
3010
2981
|
let {
|
|
3011
2982
|
loaderData,
|
|
3012
2983
|
errors
|
|
3013
|
-
} = processLoaderData(state, matches,
|
|
2984
|
+
} = processLoaderData(state, matches, loaderResults, undefined, revalidatingFetchers, fetcherResults, activeDeferreds);
|
|
3014
2985
|
|
|
3015
2986
|
// Since we let revalidations complete even if the submitting fetcher was
|
|
3016
2987
|
// deleted, only put it back to idle if it hasn't been deleted
|
|
@@ -3046,7 +3017,7 @@
|
|
|
3046
3017
|
}
|
|
3047
3018
|
|
|
3048
3019
|
// Call the matched loader for fetcher.load(), handling redirects, errors, etc.
|
|
3049
|
-
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, submission) {
|
|
3020
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
3050
3021
|
let existingFetcher = state.fetchers.get(key);
|
|
3051
3022
|
updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : undefined), {
|
|
3052
3023
|
flushSync
|
|
@@ -3058,10 +3029,7 @@
|
|
|
3058
3029
|
if (discoverResult.type === "aborted") {
|
|
3059
3030
|
return;
|
|
3060
3031
|
} else if (discoverResult.type === "error") {
|
|
3061
|
-
|
|
3062
|
-
error
|
|
3063
|
-
} = handleDiscoverRouteError(path, discoverResult);
|
|
3064
|
-
setFetcherError(key, routeId, error, {
|
|
3032
|
+
setFetcherError(key, routeId, discoverResult.error, {
|
|
3065
3033
|
flushSync
|
|
3066
3034
|
});
|
|
3067
3035
|
return;
|
|
@@ -3117,7 +3085,9 @@
|
|
|
3117
3085
|
return;
|
|
3118
3086
|
} else {
|
|
3119
3087
|
fetchRedirectIds.add(key);
|
|
3120
|
-
await startRedirectNavigation(fetchRequest, result, false
|
|
3088
|
+
await startRedirectNavigation(fetchRequest, result, false, {
|
|
3089
|
+
preventScrollReset
|
|
3090
|
+
});
|
|
3121
3091
|
return;
|
|
3122
3092
|
}
|
|
3123
3093
|
}
|
|
@@ -3156,6 +3126,7 @@
|
|
|
3156
3126
|
let {
|
|
3157
3127
|
submission,
|
|
3158
3128
|
fetcherSubmission,
|
|
3129
|
+
preventScrollReset,
|
|
3159
3130
|
replace
|
|
3160
3131
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
3161
3132
|
if (redirect.response.headers.has("X-Remix-Revalidate")) {
|
|
@@ -3216,7 +3187,7 @@
|
|
|
3216
3187
|
formAction: location
|
|
3217
3188
|
}),
|
|
3218
3189
|
// Preserve these flags across redirects
|
|
3219
|
-
preventScrollReset: pendingPreventScrollReset,
|
|
3190
|
+
preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
|
3220
3191
|
enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined
|
|
3221
3192
|
});
|
|
3222
3193
|
} else {
|
|
@@ -3228,7 +3199,7 @@
|
|
|
3228
3199
|
// Send fetcher submissions through for shouldRevalidate
|
|
3229
3200
|
fetcherSubmission,
|
|
3230
3201
|
// Preserve these flags across redirects
|
|
3231
|
-
preventScrollReset: pendingPreventScrollReset,
|
|
3202
|
+
preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
|
3232
3203
|
enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined
|
|
3233
3204
|
});
|
|
3234
3205
|
}
|
|
@@ -3309,8 +3280,8 @@
|
|
|
3309
3280
|
fetchLoadMatches.forEach((_, key) => {
|
|
3310
3281
|
if (fetchControllers.has(key)) {
|
|
3311
3282
|
cancelledFetcherLoads.add(key);
|
|
3312
|
-
abortFetcher(key);
|
|
3313
3283
|
}
|
|
3284
|
+
abortFetcher(key);
|
|
3314
3285
|
});
|
|
3315
3286
|
}
|
|
3316
3287
|
function updateFetcherState(key, fetcher, opts) {
|
|
@@ -3383,9 +3354,10 @@
|
|
|
3383
3354
|
}
|
|
3384
3355
|
function abortFetcher(key) {
|
|
3385
3356
|
let controller = fetchControllers.get(key);
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3357
|
+
if (controller) {
|
|
3358
|
+
controller.abort();
|
|
3359
|
+
fetchControllers.delete(key);
|
|
3360
|
+
}
|
|
3389
3361
|
}
|
|
3390
3362
|
function markFetchersDone(keys) {
|
|
3391
3363
|
for (let key of keys) {
|
|
@@ -3450,12 +3422,12 @@
|
|
|
3450
3422
|
blockers
|
|
3451
3423
|
});
|
|
3452
3424
|
}
|
|
3453
|
-
function shouldBlockNavigation(
|
|
3425
|
+
function shouldBlockNavigation(_ref2) {
|
|
3454
3426
|
let {
|
|
3455
3427
|
currentLocation,
|
|
3456
3428
|
nextLocation,
|
|
3457
3429
|
historyAction
|
|
3458
|
-
} =
|
|
3430
|
+
} = _ref2;
|
|
3459
3431
|
if (blockerFunctions.size === 0) {
|
|
3460
3432
|
return;
|
|
3461
3433
|
}
|
|
@@ -3502,16 +3474,6 @@
|
|
|
3502
3474
|
error
|
|
3503
3475
|
};
|
|
3504
3476
|
}
|
|
3505
|
-
function handleDiscoverRouteError(pathname, discoverResult) {
|
|
3506
|
-
return {
|
|
3507
|
-
boundaryId: findNearestBoundary(discoverResult.partialMatches).route.id,
|
|
3508
|
-
error: getInternalRouterError(400, {
|
|
3509
|
-
type: "route-discovery",
|
|
3510
|
-
pathname,
|
|
3511
|
-
message: discoverResult.error != null && "message" in discoverResult.error ? discoverResult.error : String(discoverResult.error)
|
|
3512
|
-
})
|
|
3513
|
-
};
|
|
3514
|
-
}
|
|
3515
3477
|
function cancelActiveDeferreds(predicate) {
|
|
3516
3478
|
let cancelledRouteIds = [];
|
|
3517
3479
|
activeDeferreds.forEach((dfd, routeId) => {
|
|
@@ -3602,12 +3564,26 @@
|
|
|
3602
3564
|
};
|
|
3603
3565
|
}
|
|
3604
3566
|
async function discoverRoutes(matches, pathname, signal) {
|
|
3567
|
+
if (!patchRoutesOnNavigationImpl) {
|
|
3568
|
+
return {
|
|
3569
|
+
type: "success",
|
|
3570
|
+
matches
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3605
3573
|
let partialMatches = matches;
|
|
3606
3574
|
while (true) {
|
|
3607
3575
|
let isNonHMR = inFlightDataRoutes == null;
|
|
3608
3576
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
3577
|
+
let localManifest = manifest;
|
|
3609
3578
|
try {
|
|
3610
|
-
await
|
|
3579
|
+
await patchRoutesOnNavigationImpl({
|
|
3580
|
+
path: pathname,
|
|
3581
|
+
matches: partialMatches,
|
|
3582
|
+
patch: (routeId, children) => {
|
|
3583
|
+
if (signal.aborted) return;
|
|
3584
|
+
patchRoutesImpl(routeId, children, routesToUse, localManifest, mapRouteProperties);
|
|
3585
|
+
}
|
|
3586
|
+
});
|
|
3611
3587
|
} catch (e) {
|
|
3612
3588
|
return {
|
|
3613
3589
|
type: "error",
|
|
@@ -3621,7 +3597,7 @@
|
|
|
3621
3597
|
// trigger a re-run of memoized `router.routes` dependencies.
|
|
3622
3598
|
// HMR will already update the identity and reflow when it lands
|
|
3623
3599
|
// `inFlightDataRoutes` in `completeNavigation`
|
|
3624
|
-
if (isNonHMR) {
|
|
3600
|
+
if (isNonHMR && !signal.aborted) {
|
|
3625
3601
|
dataRoutes = [...dataRoutes];
|
|
3626
3602
|
}
|
|
3627
3603
|
}
|
|
@@ -4200,9 +4176,21 @@
|
|
|
4200
4176
|
path.hash = location.hash;
|
|
4201
4177
|
}
|
|
4202
4178
|
|
|
4203
|
-
//
|
|
4204
|
-
if ((to == null || to === "" || to === ".") && activeRouteMatch
|
|
4205
|
-
|
|
4179
|
+
// Account for `?index` params when routing to the current location
|
|
4180
|
+
if ((to == null || to === "" || to === ".") && activeRouteMatch) {
|
|
4181
|
+
let nakedIndex = hasNakedIndexQuery(path.search);
|
|
4182
|
+
if (activeRouteMatch.route.index && !nakedIndex) {
|
|
4183
|
+
// Add one when we're targeting an index route
|
|
4184
|
+
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
4185
|
+
} else if (!activeRouteMatch.route.index && nakedIndex) {
|
|
4186
|
+
// Remove existing ones when we're not
|
|
4187
|
+
let params = new URLSearchParams(path.search);
|
|
4188
|
+
let indexValues = params.getAll("index");
|
|
4189
|
+
params.delete("index");
|
|
4190
|
+
indexValues.filter(v => v).forEach(v => params.append("index", v));
|
|
4191
|
+
let qs = params.toString();
|
|
4192
|
+
path.search = qs ? "?" + qs : "";
|
|
4193
|
+
}
|
|
4206
4194
|
}
|
|
4207
4195
|
|
|
4208
4196
|
// If we're operating within a basename, prepend it to the pathname. If
|
|
@@ -4251,8 +4239,8 @@
|
|
|
4251
4239
|
}
|
|
4252
4240
|
let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ?
|
|
4253
4241
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
|
|
4254
|
-
Array.from(opts.body.entries()).reduce((acc,
|
|
4255
|
-
let [name, value] =
|
|
4242
|
+
Array.from(opts.body.entries()).reduce((acc, _ref3) => {
|
|
4243
|
+
let [name, value] = _ref3;
|
|
4256
4244
|
return "" + acc + name + "=" + value + "\n";
|
|
4257
4245
|
}, "") : String(opts.body);
|
|
4258
4246
|
return {
|
|
@@ -4342,26 +4330,37 @@
|
|
|
4342
4330
|
};
|
|
4343
4331
|
}
|
|
4344
4332
|
|
|
4345
|
-
// Filter out all routes below any caught error as they aren't going to
|
|
4333
|
+
// Filter out all routes at/below any caught error as they aren't going to
|
|
4346
4334
|
// render so we don't need to load them
|
|
4347
|
-
function getLoaderMatchesUntilBoundary(matches, boundaryId) {
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4335
|
+
function getLoaderMatchesUntilBoundary(matches, boundaryId, includeBoundary) {
|
|
4336
|
+
if (includeBoundary === void 0) {
|
|
4337
|
+
includeBoundary = false;
|
|
4338
|
+
}
|
|
4339
|
+
let index = matches.findIndex(m => m.route.id === boundaryId);
|
|
4340
|
+
if (index >= 0) {
|
|
4341
|
+
return matches.slice(0, includeBoundary ? index + 1 : index);
|
|
4354
4342
|
}
|
|
4355
|
-
return
|
|
4343
|
+
return matches;
|
|
4356
4344
|
}
|
|
4357
|
-
function getMatchesToLoad(history, state, matches, submission, location,
|
|
4345
|
+
function getMatchesToLoad(history, state, matches, submission, location, initialHydration, skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) {
|
|
4358
4346
|
let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : undefined;
|
|
4359
4347
|
let currentUrl = history.createURL(state.location);
|
|
4360
4348
|
let nextUrl = history.createURL(location);
|
|
4361
4349
|
|
|
4362
4350
|
// Pick navigation matches that are net-new or qualify for revalidation
|
|
4363
|
-
let
|
|
4364
|
-
|
|
4351
|
+
let boundaryMatches = matches;
|
|
4352
|
+
if (initialHydration && state.errors) {
|
|
4353
|
+
// On initial hydration, only consider matches up to _and including_ the boundary.
|
|
4354
|
+
// This is inclusive to handle cases where a server loader ran successfully,
|
|
4355
|
+
// a child server loader bubbled up to this route, but this route has
|
|
4356
|
+
// `clientLoader.hydrate` so we want to still run the `clientLoader` so that
|
|
4357
|
+
// we have a complete version of `loaderData`
|
|
4358
|
+
boundaryMatches = getLoaderMatchesUntilBoundary(matches, Object.keys(state.errors)[0], true);
|
|
4359
|
+
} else if (pendingActionResult && isErrorResult(pendingActionResult[1])) {
|
|
4360
|
+
// If an action threw an error, we call loaders up to, but not including the
|
|
4361
|
+
// boundary
|
|
4362
|
+
boundaryMatches = getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]);
|
|
4363
|
+
}
|
|
4365
4364
|
|
|
4366
4365
|
// Don't revalidate loaders by default after action 4xx/5xx responses
|
|
4367
4366
|
// when the flag is enabled. They can still opt-into revalidation via
|
|
@@ -4379,13 +4378,8 @@
|
|
|
4379
4378
|
if (route.loader == null) {
|
|
4380
4379
|
return false;
|
|
4381
4380
|
}
|
|
4382
|
-
if (
|
|
4383
|
-
|
|
4384
|
-
return true;
|
|
4385
|
-
}
|
|
4386
|
-
return state.loaderData[route.id] === undefined && (
|
|
4387
|
-
// Don't re-run if the loader ran and threw an error
|
|
4388
|
-
!state.errors || state.errors[route.id] === undefined);
|
|
4381
|
+
if (initialHydration) {
|
|
4382
|
+
return shouldLoadRouteOnHydration(route, state.loaderData, state.errors);
|
|
4389
4383
|
}
|
|
4390
4384
|
|
|
4391
4385
|
// Always call the loader on new route instances and pending defer cancellations
|
|
@@ -4419,11 +4413,11 @@
|
|
|
4419
4413
|
let revalidatingFetchers = [];
|
|
4420
4414
|
fetchLoadMatches.forEach((f, key) => {
|
|
4421
4415
|
// Don't revalidate:
|
|
4422
|
-
// - on initial
|
|
4416
|
+
// - on initial hydration (shouldn't be any fetchers then anyway)
|
|
4423
4417
|
// - if fetcher won't be present in the subsequent render
|
|
4424
4418
|
// - no longer matches the URL (v7_fetcherPersist=false)
|
|
4425
4419
|
// - was unmounted but persisted due to v7_fetcherPersist=true
|
|
4426
|
-
if (
|
|
4420
|
+
if (initialHydration || !matches.some(m => m.route.id === f.routeId) || deletedFetchers.has(key)) {
|
|
4427
4421
|
return;
|
|
4428
4422
|
}
|
|
4429
4423
|
let fetcherMatches = matchRoutes(routesToUse, f.path, basename);
|
|
@@ -4489,6 +4483,32 @@
|
|
|
4489
4483
|
});
|
|
4490
4484
|
return [navigationMatches, revalidatingFetchers];
|
|
4491
4485
|
}
|
|
4486
|
+
function shouldLoadRouteOnHydration(route, loaderData, errors) {
|
|
4487
|
+
// We dunno if we have a loader - gotta find out!
|
|
4488
|
+
if (route.lazy) {
|
|
4489
|
+
return true;
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
// No loader, nothing to initialize
|
|
4493
|
+
if (!route.loader) {
|
|
4494
|
+
return false;
|
|
4495
|
+
}
|
|
4496
|
+
let hasData = loaderData != null && loaderData[route.id] !== undefined;
|
|
4497
|
+
let hasError = errors != null && errors[route.id] !== undefined;
|
|
4498
|
+
|
|
4499
|
+
// Don't run if we error'd during SSR
|
|
4500
|
+
if (!hasData && hasError) {
|
|
4501
|
+
return false;
|
|
4502
|
+
}
|
|
4503
|
+
|
|
4504
|
+
// Explicitly opting-in to running on hydration
|
|
4505
|
+
if (typeof route.loader === "function" && route.loader.hydrate === true) {
|
|
4506
|
+
return true;
|
|
4507
|
+
}
|
|
4508
|
+
|
|
4509
|
+
// Otherwise, run if we're not yet initialized with anything
|
|
4510
|
+
return !hasData && !hasError;
|
|
4511
|
+
}
|
|
4492
4512
|
function isNewLoader(currentLoaderData, currentMatch, match) {
|
|
4493
4513
|
let isNew =
|
|
4494
4514
|
// [a] -> [a, b]
|
|
@@ -4522,34 +4542,6 @@
|
|
|
4522
4542
|
}
|
|
4523
4543
|
return arg.defaultShouldRevalidate;
|
|
4524
4544
|
}
|
|
4525
|
-
|
|
4526
|
-
/**
|
|
4527
|
-
* Idempotent utility to execute patchRoutesOnNavigation() to lazily load route
|
|
4528
|
-
* definitions and update the routes/routeManifest
|
|
4529
|
-
*/
|
|
4530
|
-
async function loadLazyRouteChildren(patchRoutesOnNavigationImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
|
|
4531
|
-
let key = [path, ...matches.map(m => m.route.id)].join("-");
|
|
4532
|
-
try {
|
|
4533
|
-
let pending = pendingRouteChildren.get(key);
|
|
4534
|
-
if (!pending) {
|
|
4535
|
-
pending = patchRoutesOnNavigationImpl({
|
|
4536
|
-
path,
|
|
4537
|
-
matches,
|
|
4538
|
-
patch: (routeId, children) => {
|
|
4539
|
-
if (!signal.aborted) {
|
|
4540
|
-
patchRoutesImpl(routeId, children, routes, manifest, mapRouteProperties);
|
|
4541
|
-
}
|
|
4542
|
-
}
|
|
4543
|
-
});
|
|
4544
|
-
pendingRouteChildren.set(key, pending);
|
|
4545
|
-
}
|
|
4546
|
-
if (pending && isPromise(pending)) {
|
|
4547
|
-
await pending;
|
|
4548
|
-
}
|
|
4549
|
-
} finally {
|
|
4550
|
-
pendingRouteChildren.delete(key);
|
|
4551
|
-
}
|
|
4552
|
-
}
|
|
4553
4545
|
function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) {
|
|
4554
4546
|
var _childrenToPatch;
|
|
4555
4547
|
let childrenToPatch;
|
|
@@ -4567,10 +4559,34 @@
|
|
|
4567
4559
|
// Don't patch in routes we already know about so that `patch` is idempotent
|
|
4568
4560
|
// to simplify user-land code. This is useful because we re-call the
|
|
4569
4561
|
// `patchRoutesOnNavigation` function for matched routes with params.
|
|
4570
|
-
let uniqueChildren = children.filter(
|
|
4562
|
+
let uniqueChildren = children.filter(newRoute => !childrenToPatch.some(existingRoute => isSameRoute(newRoute, existingRoute)));
|
|
4571
4563
|
let newRoutes = convertRoutesToDataRoutes(uniqueChildren, mapRouteProperties, [routeId || "_", "patch", String(((_childrenToPatch = childrenToPatch) == null ? void 0 : _childrenToPatch.length) || "0")], manifest);
|
|
4572
4564
|
childrenToPatch.push(...newRoutes);
|
|
4573
4565
|
}
|
|
4566
|
+
function isSameRoute(newRoute, existingRoute) {
|
|
4567
|
+
// Most optimal check is by id
|
|
4568
|
+
if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
|
|
4569
|
+
return true;
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4572
|
+
// Second is by pathing differences
|
|
4573
|
+
if (!(newRoute.index === existingRoute.index && newRoute.path === existingRoute.path && newRoute.caseSensitive === existingRoute.caseSensitive)) {
|
|
4574
|
+
return false;
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
// Pathless layout routes are trickier since we need to check children.
|
|
4578
|
+
// If they have no children then they're the same as far as we can tell
|
|
4579
|
+
if ((!newRoute.children || newRoute.children.length === 0) && (!existingRoute.children || existingRoute.children.length === 0)) {
|
|
4580
|
+
return true;
|
|
4581
|
+
}
|
|
4582
|
+
|
|
4583
|
+
// Otherwise, we look to see if every child in the new route is already
|
|
4584
|
+
// represented in the existing route's children
|
|
4585
|
+
return newRoute.children.every((aChild, i) => {
|
|
4586
|
+
var _existingRoute$childr;
|
|
4587
|
+
return (_existingRoute$childr = existingRoute.children) == null ? void 0 : _existingRoute$childr.some(bChild => isSameRoute(aChild, bChild));
|
|
4588
|
+
});
|
|
4589
|
+
}
|
|
4574
4590
|
|
|
4575
4591
|
/**
|
|
4576
4592
|
* Execute route.lazy() methods to lazily load route modules (loader, action,
|
|
@@ -4626,10 +4642,10 @@
|
|
|
4626
4642
|
}
|
|
4627
4643
|
|
|
4628
4644
|
// Default implementation of `dataStrategy` which fetches all loaders in parallel
|
|
4629
|
-
async function defaultDataStrategy(
|
|
4645
|
+
async function defaultDataStrategy(_ref4) {
|
|
4630
4646
|
let {
|
|
4631
4647
|
matches
|
|
4632
|
-
} =
|
|
4648
|
+
} = _ref4;
|
|
4633
4649
|
let matchesToLoad = matches.filter(m => m.shouldLoad);
|
|
4634
4650
|
let results = await Promise.all(matchesToLoad.map(m => m.resolve()));
|
|
4635
4651
|
return results.reduce((acc, result, i) => Object.assign(acc, {
|
|
@@ -5043,7 +5059,7 @@
|
|
|
5043
5059
|
loaderHeaders
|
|
5044
5060
|
};
|
|
5045
5061
|
}
|
|
5046
|
-
function processLoaderData(state, matches,
|
|
5062
|
+
function processLoaderData(state, matches, results, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds) {
|
|
5047
5063
|
let {
|
|
5048
5064
|
loaderData,
|
|
5049
5065
|
errors
|
|
@@ -5158,9 +5174,7 @@
|
|
|
5158
5174
|
let errorMessage = "Unknown @remix-run/router error";
|
|
5159
5175
|
if (status === 400) {
|
|
5160
5176
|
statusText = "Bad Request";
|
|
5161
|
-
if (
|
|
5162
|
-
errorMessage = "Unable to match URL \"" + pathname + "\" - the `patchRoutesOnNavigation()` " + ("function threw the following error:\n" + message);
|
|
5163
|
-
} else if (method && pathname && routeId) {
|
|
5177
|
+
if (method && pathname && routeId) {
|
|
5164
5178
|
errorMessage = "You made a " + method + " request to \"" + pathname + "\" but " + ("did not provide a `loader` for route \"" + routeId + "\", ") + "so there is no way to handle the request.";
|
|
5165
5179
|
} else if (type === "defer-action") {
|
|
5166
5180
|
errorMessage = "defer() is not supported in actions";
|
|
@@ -5222,9 +5236,6 @@
|
|
|
5222
5236
|
// /page#hash -> /page
|
|
5223
5237
|
return false;
|
|
5224
5238
|
}
|
|
5225
|
-
function isPromise(val) {
|
|
5226
|
-
return typeof val === "object" && val != null && "then" in val;
|
|
5227
|
-
}
|
|
5228
5239
|
function isDataStrategyResult(result) {
|
|
5229
5240
|
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === ResultType.data || result.type === ResultType.error);
|
|
5230
5241
|
}
|