@remix-run/router 0.0.0-experimental-91f2bf54 → 0.0.0-experimental-5f6f59a6

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 CHANGED
@@ -1,5 +1,71 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.4.0-pre.0
4
+
5
+ ### Minor Changes
6
+
7
+ - **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
8
+
9
+ In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`).
10
+
11
+ Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes.
12
+
13
+ Your `lazy` functions will typically return the result of a dynamic import.
14
+
15
+ ```jsx
16
+ // In this example, we assume most folks land on the homepage so we include that
17
+ // in our critical-path bundle, but then we lazily load modules for /a and /b so
18
+ // they don't load until the user navigates to those routes
19
+ let routes = createRoutesFromElements(
20
+ <Route path="/" element={<Layout />}>
21
+ <Route index element={<Home />} />
22
+ <Route path="a" lazy={() => import("./a")} />
23
+ <Route path="b" lazy={() => import("./b")} />
24
+ </Route>
25
+ );
26
+ ```
27
+
28
+ Then in your lazy route modules, export the properties you want defined for the route:
29
+
30
+ ```jsx
31
+ export async function loader({ request }) {
32
+ let data = await fetchData(request);
33
+ return json(data);
34
+ }
35
+
36
+ // Export a `Component` directly instead of needing to create a React Element from it
37
+ export function Component() {
38
+ let data = useLoaderData();
39
+
40
+ return (
41
+ <>
42
+ <h1>You made it!</h1>
43
+ <p>{data}</p>
44
+ </>
45
+ );
46
+ }
47
+
48
+ // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
49
+ export function ErrorBoundary() {
50
+ let error = useRouteError();
51
+ return isRouteErrorResponse(error) ? (
52
+ <h1>
53
+ {error.status} {error.statusText}
54
+ </h1>
55
+ ) : (
56
+ <h1>{error.message || error}</h1>
57
+ );
58
+ }
59
+ ```
60
+
61
+ An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository.
62
+
63
+ 🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830).
64
+
65
+ ### Patch Changes
66
+
67
+ - Fix `generatePath` incorrectly applying parameters in some cases ([`bc6fefa1`](https://github.com/remix-run/react-router/commit/bc6fefa19019ce9f5250c8b5af9b8c5d3390e9d1))
68
+
3
69
  ## 1.3.3
4
70
 
5
71
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-91f2bf54
2
+ * @remix-run/router v0.0.0-experimental-5f6f59a6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1706,16 +1706,6 @@ function createRouter(init) {
1706
1706
  function updateState(newState) {
1707
1707
  state = _extends({}, state, newState);
1708
1708
  subscribers.forEach(subscriber => subscriber(state));
1709
- }
1710
-
1711
- function completeNavigation(location, newState) {
1712
- // @ts-expect-error
1713
- if (typeof document !== "undefined" && document.startViewTransition) {
1714
- // @ts-expect-error
1715
- document.startViewTransition(() => completeNavigationForRealz(location, newState));
1716
- } else {
1717
- completeNavigationForRealz(location, newState);
1718
- }
1719
1709
  } // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
1720
1710
  // and setting state.[historyAction/location/matches] to the new route.
1721
1711
  // - Location is a required param
@@ -1723,7 +1713,7 @@ function createRouter(init) {
1723
1713
  // - Can pass any other state in newState
1724
1714
 
1725
1715
 
1726
- function completeNavigationForRealz(location, newState) {
1716
+ function completeNavigation(location, newState) {
1727
1717
  var _location$state, _location$state2;
1728
1718
 
1729
1719
  // Deduce if we're in a loading/actionReload state:
@@ -2171,8 +2161,7 @@ function createRouter(init) {
2171
2161
  formMethod: undefined,
2172
2162
  formAction: undefined,
2173
2163
  formEncType: undefined,
2174
- formData: undefined,
2175
- " _hasFetcherDoneAnything ": true
2164
+ formData: undefined
2176
2165
  };
2177
2166
  state.fetchers.set(rf.key, revalidatingFetcher);
2178
2167
  });
@@ -2308,8 +2297,7 @@ function createRouter(init) {
2308
2297
  let fetcher = _extends({
2309
2298
  state: "submitting"
2310
2299
  }, submission, {
2311
- data: existingFetcher && existingFetcher.data,
2312
- " _hasFetcherDoneAnything ": true
2300
+ data: existingFetcher && existingFetcher.data
2313
2301
  });
2314
2302
 
2315
2303
  state.fetchers.set(key, fetcher);
@@ -2339,17 +2327,14 @@ function createRouter(init) {
2339
2327
  let loadingFetcher = _extends({
2340
2328
  state: "loading"
2341
2329
  }, submission, {
2342
- data: undefined,
2343
- " _hasFetcherDoneAnything ": true
2330
+ data: undefined
2344
2331
  });
2345
2332
 
2346
2333
  state.fetchers.set(key, loadingFetcher);
2347
2334
  updateState({
2348
2335
  fetchers: new Map(state.fetchers)
2349
2336
  });
2350
- return startRedirectNavigation(state, actionResult, {
2351
- isFetchActionRedirect: true
2352
- });
2337
+ return startRedirectNavigation(state, actionResult);
2353
2338
  } // Process any non-redirect errors thrown
2354
2339
 
2355
2340
 
@@ -2377,9 +2362,7 @@ function createRouter(init) {
2377
2362
  let loadFetcher = _extends({
2378
2363
  state: "loading",
2379
2364
  data: actionResult.data
2380
- }, submission, {
2381
- " _hasFetcherDoneAnything ": true
2382
- });
2365
+ }, submission);
2383
2366
 
2384
2367
  state.fetchers.set(key, loadFetcher);
2385
2368
  let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, fetchLoadMatches, routesToUse, init.basename, {
@@ -2398,8 +2381,7 @@ function createRouter(init) {
2398
2381
  formMethod: undefined,
2399
2382
  formAction: undefined,
2400
2383
  formEncType: undefined,
2401
- formData: undefined,
2402
- " _hasFetcherDoneAnything ": true
2384
+ formData: undefined
2403
2385
  };
2404
2386
  state.fetchers.set(staleKey, revalidatingFetcher);
2405
2387
  fetchControllers.set(staleKey, abortController);
@@ -2437,8 +2419,7 @@ function createRouter(init) {
2437
2419
  formMethod: undefined,
2438
2420
  formAction: undefined,
2439
2421
  formEncType: undefined,
2440
- formData: undefined,
2441
- " _hasFetcherDoneAnything ": true
2422
+ formData: undefined
2442
2423
  };
2443
2424
  state.fetchers.set(key, doneFetcher);
2444
2425
  let didAbortFetchLoads = abortStaleFetchLoads(loadId); // If we are currently in a navigation loading state and this fetcher is
@@ -2479,8 +2460,7 @@ function createRouter(init) {
2479
2460
  formEncType: undefined,
2480
2461
  formData: undefined
2481
2462
  }, submission, {
2482
- data: existingFetcher && existingFetcher.data,
2483
- " _hasFetcherDoneAnything ": true
2463
+ data: existingFetcher && existingFetcher.data
2484
2464
  });
2485
2465
 
2486
2466
  state.fetchers.set(key, loadingFetcher);
@@ -2540,8 +2520,7 @@ function createRouter(init) {
2540
2520
  formMethod: undefined,
2541
2521
  formAction: undefined,
2542
2522
  formEncType: undefined,
2543
- formData: undefined,
2544
- " _hasFetcherDoneAnything ": true
2523
+ formData: undefined
2545
2524
  };
2546
2525
  state.fetchers.set(key, doneFetcher);
2547
2526
  updateState({
@@ -2574,20 +2553,16 @@ function createRouter(init) {
2574
2553
 
2575
2554
  let {
2576
2555
  submission,
2577
- replace,
2578
- isFetchActionRedirect
2556
+ replace
2579
2557
  } = _temp === void 0 ? {} : _temp;
2580
2558
 
2581
2559
  if (redirect.revalidate) {
2582
2560
  isRevalidationRequired = true;
2583
2561
  }
2584
2562
 
2585
- let redirectLocation = createLocation(state.location, redirect.location, // TODO: This can be removed once we get rid of useTransition in Remix v2
2586
- _extends({
2563
+ let redirectLocation = createLocation(state.location, redirect.location, {
2587
2564
  _isRedirect: true
2588
- }, isFetchActionRedirect ? {
2589
- _isFetchActionRedirect: true
2590
- } : {}));
2565
+ });
2591
2566
  invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an absolute external redirect that goes to a new origin
2592
2567
 
2593
2568
  if (ABSOLUTE_URL_REGEX.test(redirect.location) && isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
@@ -2733,8 +2708,7 @@ function createRouter(init) {
2733
2708
  formMethod: undefined,
2734
2709
  formAction: undefined,
2735
2710
  formEncType: undefined,
2736
- formData: undefined,
2737
- " _hasFetcherDoneAnything ": true
2711
+ formData: undefined
2738
2712
  };
2739
2713
  state.fetchers.set(key, doneFetcher);
2740
2714
  }
@@ -3976,8 +3950,7 @@ function processLoaderData(state, matches, matchesToLoad, results, pendingError,
3976
3950
  formMethod: undefined,
3977
3951
  formAction: undefined,
3978
3952
  formEncType: undefined,
3979
- formData: undefined,
3980
- " _hasFetcherDoneAnything ": true
3953
+ formData: undefined
3981
3954
  };
3982
3955
  state.fetchers.set(key, doneFetcher);
3983
3956
  }