react-router 0.0.0-experimental-a26b992a1 → 0.0.0-experimental-3278f3ca6

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-a26b992a1
2
+ * React Router v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-a26b992a1
2
+ * React Router v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2275,9 +2275,9 @@ function createRouter(init) {
2275
2275
  return;
2276
2276
  }
2277
2277
  let match = getTargetMatch(matches, path);
2278
- pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
2278
+ let preventScrollReset = (opts && opts.preventScrollReset) === true;
2279
2279
  if (submission && isMutationMethod(submission.formMethod)) {
2280
- await handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
2280
+ await handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
2281
2281
  return;
2282
2282
  }
2283
2283
  // Store off the match so we can call it's shouldRevalidate on subsequent
@@ -2286,11 +2286,11 @@ function createRouter(init) {
2286
2286
  routeId,
2287
2287
  path
2288
2288
  });
2289
- await handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
2289
+ await handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
2290
2290
  }
2291
2291
  // Call the action for the matched fetcher.submit(), and then handle redirects,
2292
2292
  // errors, and revalidation
2293
- async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, submission) {
2293
+ async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
2294
2294
  interruptActiveLoads();
2295
2295
  fetchLoadMatches.delete(key);
2296
2296
  function detectAndHandle405Error(m) {
@@ -2379,7 +2379,8 @@ function createRouter(init) {
2379
2379
  fetchRedirectIds.add(key);
2380
2380
  updateFetcherState(key, getLoadingFetcher(submission));
2381
2381
  return startRedirectNavigation(fetchRequest, actionResult, false, {
2382
- fetcherSubmission: submission
2382
+ fetcherSubmission: submission,
2383
+ preventScrollReset
2383
2384
  });
2384
2385
  }
2385
2386
  }
@@ -2434,7 +2435,9 @@ function createRouter(init) {
2434
2435
  revalidatingFetchers.forEach(r => fetchControllers.delete(r.key));
2435
2436
  let redirect = findRedirect(loaderResults);
2436
2437
  if (redirect) {
2437
- return startRedirectNavigation(revalidationRequest, redirect.result, false);
2438
+ return startRedirectNavigation(revalidationRequest, redirect.result, false, {
2439
+ preventScrollReset
2440
+ });
2438
2441
  }
2439
2442
  redirect = findRedirect(fetcherResults);
2440
2443
  if (redirect) {
@@ -2442,7 +2445,9 @@ function createRouter(init) {
2442
2445
  // fetchRedirectIds so it doesn't get revalidated on the next set of
2443
2446
  // loader executions
2444
2447
  fetchRedirectIds.add(redirect.key);
2445
- return startRedirectNavigation(revalidationRequest, redirect.result, false);
2448
+ return startRedirectNavigation(revalidationRequest, redirect.result, false, {
2449
+ preventScrollReset
2450
+ });
2446
2451
  }
2447
2452
  // Process and commit output from loaders
2448
2453
  let {
@@ -2481,7 +2486,7 @@ function createRouter(init) {
2481
2486
  }
2482
2487
  }
2483
2488
  // Call the matched loader for fetcher.load(), handling redirects, errors, etc.
2484
- async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, submission) {
2489
+ async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
2485
2490
  let existingFetcher = state.fetchers.get(key);
2486
2491
  updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : undefined), {
2487
2492
  flushSync
@@ -2540,7 +2545,9 @@ function createRouter(init) {
2540
2545
  return;
2541
2546
  } else {
2542
2547
  fetchRedirectIds.add(key);
2543
- await startRedirectNavigation(fetchRequest, result, false);
2548
+ await startRedirectNavigation(fetchRequest, result, false, {
2549
+ preventScrollReset
2550
+ });
2544
2551
  return;
2545
2552
  }
2546
2553
  }
@@ -2575,6 +2582,7 @@ function createRouter(init) {
2575
2582
  let {
2576
2583
  submission,
2577
2584
  fetcherSubmission,
2585
+ preventScrollReset,
2578
2586
  replace
2579
2587
  } = _temp2 === void 0 ? {} : _temp2;
2580
2588
  if (redirect.response.headers.has("X-Remix-Revalidate")) {
@@ -2632,7 +2640,7 @@ function createRouter(init) {
2632
2640
  formAction: location
2633
2641
  }),
2634
2642
  // Preserve these flags across redirects
2635
- preventScrollReset: pendingPreventScrollReset,
2643
+ preventScrollReset: preventScrollReset || pendingPreventScrollReset,
2636
2644
  enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined
2637
2645
  });
2638
2646
  } else {
@@ -2644,7 +2652,7 @@ function createRouter(init) {
2644
2652
  // Send fetcher submissions through for shouldRevalidate
2645
2653
  fetcherSubmission,
2646
2654
  // Preserve these flags across redirects
2647
- preventScrollReset: pendingPreventScrollReset,
2655
+ preventScrollReset: preventScrollReset || pendingPreventScrollReset,
2648
2656
  enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined
2649
2657
  });
2650
2658
  }
@@ -3508,9 +3516,21 @@ function normalizeTo(location, matches, basename, to, fromRouteId, relative) {
3508
3516
  path.search = location.search;
3509
3517
  path.hash = location.hash;
3510
3518
  }
3511
- // Add an ?index param for matched index routes if we don't already have one
3512
- if ((to == null || to === "" || to === ".") && activeRouteMatch && activeRouteMatch.route.index && !hasNakedIndexQuery(path.search)) {
3513
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
3519
+ // Account for `?index` params when routing to the current location
3520
+ if ((to == null || to === "" || to === ".") && activeRouteMatch) {
3521
+ let nakedIndex = hasNakedIndexQuery(path.search);
3522
+ if (activeRouteMatch.route.index && !nakedIndex) {
3523
+ // Add one when we're targeting an index route
3524
+ path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
3525
+ } else if (!activeRouteMatch.route.index && nakedIndex) {
3526
+ // Remove existing ones when we're not
3527
+ let params = new URLSearchParams(path.search);
3528
+ let indexValues = params.getAll("index");
3529
+ params.delete("index");
3530
+ indexValues.filter(v => v).forEach(v => params.append("index", v));
3531
+ let qs = params.toString();
3532
+ path.search = qs ? "?" + qs : "";
3533
+ }
3514
3534
  }
3515
3535
  // If we're operating within a basename, prepend it to the pathname. If
3516
3536
  // this is a root navigation, then just use the raw basename which allows
@@ -9334,9 +9354,13 @@ action, _temp2) {
9334
9354
  // since it might not apply to our contextual route. We add it back based
9335
9355
  // on match.route.index below
9336
9356
  let params = new URLSearchParams(path.search);
9337
- if (params.has("index") && params.get("index") === "") {
9357
+ let indexValues = params.getAll("index");
9358
+ let hasNakedIndexParam = indexValues.some(v => v === "");
9359
+ if (hasNakedIndexParam) {
9338
9360
  params.delete("index");
9339
- path.search = params.toString() ? "?" + params.toString() : "";
9361
+ indexValues.filter(v => v).forEach(v => params.append("index", v));
9362
+ let qs = params.toString();
9363
+ path.search = qs ? "?" + qs : "";
9340
9364
  }
9341
9365
  }
9342
9366
  if ((!action || action === ".") && match.route.index) {