@remix-run/router 0.0.0-experimental-91f2bf54 → 0.0.0-experimental-633882d6

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-633882d6
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:
@@ -2347,9 +2337,7 @@ function createRouter(init) {
2347
2337
  updateState({
2348
2338
  fetchers: new Map(state.fetchers)
2349
2339
  });
2350
- return startRedirectNavigation(state, actionResult, {
2351
- isFetchActionRedirect: true
2352
- });
2340
+ return startRedirectNavigation(state, actionResult);
2353
2341
  } // Process any non-redirect errors thrown
2354
2342
 
2355
2343
 
@@ -2574,20 +2562,16 @@ function createRouter(init) {
2574
2562
 
2575
2563
  let {
2576
2564
  submission,
2577
- replace,
2578
- isFetchActionRedirect
2565
+ replace
2579
2566
  } = _temp === void 0 ? {} : _temp;
2580
2567
 
2581
2568
  if (redirect.revalidate) {
2582
2569
  isRevalidationRequired = true;
2583
2570
  }
2584
2571
 
2585
- let redirectLocation = createLocation(state.location, redirect.location, // TODO: This can be removed once we get rid of useTransition in Remix v2
2586
- _extends({
2572
+ let redirectLocation = createLocation(state.location, redirect.location, {
2587
2573
  _isRedirect: true
2588
- }, isFetchActionRedirect ? {
2589
- _isFetchActionRedirect: true
2590
- } : {}));
2574
+ });
2591
2575
  invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an absolute external redirect that goes to a new origin
2592
2576
 
2593
2577
  if (ABSOLUTE_URL_REGEX.test(redirect.location) && isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {