react-router 7.0.0-pre.2 → 7.0.0-pre.4

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/chunk-FT3T2DDR.mjs +9617 -0
  3. package/dist/dom-export.d.mts +13 -0
  4. package/dist/dom-export.d.ts +13 -3
  5. package/dist/dom-export.js +5502 -0
  6. package/dist/dom-export.mjs +112 -126
  7. package/dist/{lib/dom/lib.d.ts → fog-of-war-BijhfqFM.d.ts} +699 -45
  8. package/dist/fog-of-war-Bz_EDtxF.d.mts +1595 -0
  9. package/dist/index.d.mts +839 -0
  10. package/dist/index.d.ts +839 -73
  11. package/dist/index.js +9763 -0
  12. package/dist/index.mjs +225 -12689
  13. package/dist/lib/types.d.mts +2 -0
  14. package/dist/lib/types.d.ts +2 -83
  15. package/dist/lib/types.js +28 -0
  16. package/dist/lib/types.mjs +1 -1
  17. package/dist/types-BlYP8xpH.d.mts +1620 -0
  18. package/dist/types-BlYP8xpH.d.ts +1620 -0
  19. package/package.json +52 -12
  20. package/dist/dom-export.mjs.map +0 -1
  21. package/dist/index.mjs.map +0 -1
  22. package/dist/lib/components.d.ts +0 -372
  23. package/dist/lib/context.d.ts +0 -115
  24. package/dist/lib/dom/dom.d.ts +0 -123
  25. package/dist/lib/dom/global.d.ts +0 -40
  26. package/dist/lib/dom/server.d.ts +0 -41
  27. package/dist/lib/dom/ssr/components.d.ts +0 -122
  28. package/dist/lib/dom/ssr/data.d.ts +0 -2
  29. package/dist/lib/dom/ssr/entry.d.ts +0 -48
  30. package/dist/lib/dom/ssr/errorBoundaries.d.ts +0 -36
  31. package/dist/lib/dom/ssr/errors.d.ts +0 -2
  32. package/dist/lib/dom/ssr/fallback.d.ts +0 -2
  33. package/dist/lib/dom/ssr/fog-of-war.d.ts +0 -28
  34. package/dist/lib/dom/ssr/invariant.d.ts +0 -2
  35. package/dist/lib/dom/ssr/links.d.ts +0 -25
  36. package/dist/lib/dom/ssr/markup.d.ts +0 -5
  37. package/dist/lib/dom/ssr/routeModules.d.ts +0 -183
  38. package/dist/lib/dom/ssr/routes-test-stub.d.ts +0 -59
  39. package/dist/lib/dom/ssr/routes.d.ts +0 -29
  40. package/dist/lib/dom/ssr/server.d.ts +0 -16
  41. package/dist/lib/dom/ssr/single-fetch.d.ts +0 -37
  42. package/dist/lib/dom-export/dom-router-provider.d.ts +0 -5
  43. package/dist/lib/dom-export/hydrated-router.d.ts +0 -5
  44. package/dist/lib/dom-export.d.ts +0 -3
  45. package/dist/lib/hooks.d.ts +0 -411
  46. package/dist/lib/router/history.d.ts +0 -253
  47. package/dist/lib/router/links.d.ts +0 -104
  48. package/dist/lib/router/router.d.ts +0 -544
  49. package/dist/lib/router/utils.d.ts +0 -497
  50. package/dist/lib/server-runtime/build.d.ts +0 -38
  51. package/dist/lib/server-runtime/cookies.d.ts +0 -62
  52. package/dist/lib/server-runtime/crypto.d.ts +0 -2
  53. package/dist/lib/server-runtime/data.d.ts +0 -11
  54. package/dist/lib/server-runtime/dev.d.ts +0 -8
  55. package/dist/lib/server-runtime/entry.d.ts +0 -3
  56. package/dist/lib/server-runtime/errors.d.ts +0 -51
  57. package/dist/lib/server-runtime/headers.d.ts +0 -3
  58. package/dist/lib/server-runtime/invariant.d.ts +0 -2
  59. package/dist/lib/server-runtime/markup.d.ts +0 -1
  60. package/dist/lib/server-runtime/mode.d.ts +0 -9
  61. package/dist/lib/server-runtime/routeMatching.d.ts +0 -8
  62. package/dist/lib/server-runtime/routeModules.d.ts +0 -40
  63. package/dist/lib/server-runtime/routes.d.ts +0 -11
  64. package/dist/lib/server-runtime/server.d.ts +0 -5
  65. package/dist/lib/server-runtime/serverHandoff.d.ts +0 -11
  66. package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +0 -19
  67. package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +0 -17
  68. package/dist/lib/server-runtime/sessions.d.ts +0 -140
  69. package/dist/lib/server-runtime/single-fetch.d.ts +0 -30
  70. package/dist/lib/server-runtime/typecheck.d.ts +0 -4
  71. package/dist/lib/server-runtime/warnings.d.ts +0 -1
  72. package/dist/main-dom-export.js +0 -19
  73. package/dist/main.js +0 -19
  74. package/dist/react-router-dom.development.js +0 -199
  75. package/dist/react-router-dom.development.js.map +0 -1
  76. package/dist/react-router-dom.production.min.js +0 -12
  77. package/dist/react-router-dom.production.min.js.map +0 -1
  78. package/dist/react-router.development.js +0 -12528
  79. package/dist/react-router.development.js.map +0 -1
  80. package/dist/react-router.production.min.js +0 -12
  81. package/dist/react-router.production.min.js.map +0 -1
  82. package/dist/umd/react-router-dom.development.js +0 -241
  83. package/dist/umd/react-router-dom.development.js.map +0 -1
  84. package/dist/umd/react-router-dom.production.min.js +0 -12
  85. package/dist/umd/react-router-dom.production.min.js.map +0 -1
  86. package/dist/umd/react-router.development.js +0 -12834
  87. package/dist/umd/react-router.development.js.map +0 -1
  88. package/dist/umd/react-router.production.min.js +0 -12
  89. package/dist/umd/react-router.production.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v7.0.0-pre.2
2
+ * react-router v7.0.0-pre.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,35 +8,44 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import * as React from 'react';
12
- import * as ReactDOM from 'react-dom';
13
- import { UNSAFE_invariant, UNSAFE_useFogOFWarDiscovery, UNSAFE_FrameworkContext, UNSAFE_RemixErrorBoundary, UNSAFE_decodeViaTurboStream, UNSAFE_createClientRoutes, matchRoutes, UNSAFE_shouldHydrateRouteLoader, UNSAFE_deserializeErrors, UNSAFE_createRouter, UNSAFE_createBrowserHistory, UNSAFE_mapRouteProperties, UNSAFE_getSingleFetchDataStrategy, UNSAFE_getPatchRoutesOnNavigationFunction, UNSAFE_createClientRoutesWithHMRRevalidationOptOut, RouterProvider as RouterProvider$1 } from 'react-router';
11
+ import {
12
+ FrameworkContext,
13
+ RemixErrorBoundary,
14
+ RouterProvider,
15
+ createBrowserHistory,
16
+ createClientRoutes,
17
+ createClientRoutesWithHMRRevalidationOptOut,
18
+ createRouter,
19
+ decodeViaTurboStream,
20
+ deserializeErrors,
21
+ getPatchRoutesOnNavigationFunction,
22
+ getSingleFetchDataStrategy,
23
+ invariant,
24
+ mapRouteProperties,
25
+ matchRoutes,
26
+ shouldHydrateRouteLoader,
27
+ useFogOFWarDiscovery
28
+ } from "./chunk-FT3T2DDR.mjs";
14
29
 
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
- for (var key in source) {
20
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21
- target[key] = source[key];
22
- }
23
- }
24
- }
25
- return target;
26
- };
27
- return _extends.apply(this, arguments);
30
+ // lib/dom-export/dom-router-provider.tsx
31
+ import * as React from "react";
32
+ import * as ReactDOM from "react-dom";
33
+ function RouterProvider2(props) {
34
+ return /* @__PURE__ */ React.createElement(RouterProvider, { flushSync: ReactDOM.flushSync, ...props });
28
35
  }
29
36
 
30
- let ssrInfo = null;
31
- let router = null;
37
+ // lib/dom-export/hydrated-router.tsx
38
+ import * as React2 from "react";
39
+ var ssrInfo = null;
40
+ var router = null;
32
41
  function initSsrInfo() {
33
42
  if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
34
43
  ssrInfo = {
35
44
  context: window.__reactRouterContext,
36
45
  manifest: window.__reactRouterManifest,
37
46
  routeModules: window.__reactRouterRouteModules,
38
- stateDecodingPromise: undefined,
39
- router: undefined,
47
+ stateDecodingPromise: void 0,
48
+ router: void 0,
40
49
  routerInitialized: false
41
50
  };
42
51
  }
@@ -44,24 +53,19 @@ function initSsrInfo() {
44
53
  function createHydratedRouter() {
45
54
  initSsrInfo();
46
55
  if (!ssrInfo) {
47
- throw new Error("You must be using the SSR features of React Router in order to skip " + "passing a `router` prop to `<RouterProvider>`");
56
+ throw new Error(
57
+ "You must be using the SSR features of React Router in order to skip passing a `router` prop to `<RouterProvider>`"
58
+ );
48
59
  }
49
-
50
- // We need to suspend until the initial state snapshot is decoded into
51
- // window.__reactRouterContext.state
52
-
53
60
  let localSsrInfo = ssrInfo;
54
- // Note: `stateDecodingPromise` is not coupled to `router` - we'll reach this
55
- // code potentially many times waiting for our state to arrive, but we'll
56
- // then only get past here and create the `router` one time
57
61
  if (!ssrInfo.stateDecodingPromise) {
58
62
  let stream = ssrInfo.context.stream;
59
- !stream ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No stream found for single fetch decoding") : UNSAFE_invariant(false) : void 0;
60
- ssrInfo.context.stream = undefined;
61
- ssrInfo.stateDecodingPromise = UNSAFE_decodeViaTurboStream(stream, window).then(value => {
63
+ invariant(stream, "No stream found for single fetch decoding");
64
+ ssrInfo.context.stream = void 0;
65
+ ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then((value) => {
62
66
  ssrInfo.context.state = value.value;
63
67
  localSsrInfo.stateDecodingPromise.value = true;
64
- }).catch(e => {
68
+ }).catch((e) => {
65
69
  localSsrInfo.stateDecodingPromise.error = e;
66
70
  });
67
71
  }
@@ -71,143 +75,125 @@ function createHydratedRouter() {
71
75
  if (!ssrInfo.stateDecodingPromise.value) {
72
76
  throw ssrInfo.stateDecodingPromise;
73
77
  }
74
- let routes = UNSAFE_createClientRoutes(ssrInfo.manifest.routes, ssrInfo.routeModules, ssrInfo.context.state, ssrInfo.context.isSpaMode);
75
- let hydrationData = undefined;
78
+ let routes = createClientRoutes(
79
+ ssrInfo.manifest.routes,
80
+ ssrInfo.routeModules,
81
+ ssrInfo.context.state,
82
+ ssrInfo.context.isSpaMode
83
+ );
84
+ let hydrationData = void 0;
76
85
  if (!ssrInfo.context.isSpaMode) {
77
- var _window$__reactRouter;
78
- // Create a shallow clone of `loaderData` we can mutate for partial hydration.
79
- // When a route exports a `clientLoader` and a `HydrateFallback`, the SSR will
80
- // render the fallback so we need the client to do the same for hydration.
81
- // The server loader data has already been exposed to these route `clientLoader`'s
82
- // in `createClientRoutes` above, so we need to clear out the version we pass to
83
- // `createBrowserRouter` so it initializes and runs the client loaders.
84
- hydrationData = _extends({}, ssrInfo.context.state, {
85
- loaderData: _extends({}, ssrInfo.context.state.loaderData)
86
- });
87
- let initialMatches = matchRoutes(routes, window.location, (_window$__reactRouter = window.__reactRouterContext) == null ? void 0 : _window$__reactRouter.basename);
86
+ hydrationData = {
87
+ ...ssrInfo.context.state,
88
+ loaderData: { ...ssrInfo.context.state.loaderData }
89
+ };
90
+ let initialMatches = matchRoutes(
91
+ routes,
92
+ window.location,
93
+ window.__reactRouterContext?.basename
94
+ );
88
95
  if (initialMatches) {
89
96
  for (let match of initialMatches) {
90
97
  let routeId = match.route.id;
91
98
  let route = ssrInfo.routeModules[routeId];
92
99
  let manifestRoute = ssrInfo.manifest.routes[routeId];
93
- // Clear out the loaderData to avoid rendering the route component when the
94
- // route opted into clientLoader hydration and either:
95
- // * gave us a HydrateFallback
96
- // * or doesn't have a server loader and we have no data to render
97
- if (route && manifestRoute && UNSAFE_shouldHydrateRouteLoader(manifestRoute, route, ssrInfo.context.isSpaMode) && (route.HydrateFallback || !manifestRoute.hasLoader)) {
100
+ if (route && manifestRoute && shouldHydrateRouteLoader(
101
+ manifestRoute,
102
+ route,
103
+ ssrInfo.context.isSpaMode
104
+ ) && (route.HydrateFallback || !manifestRoute.hasLoader)) {
98
105
  delete hydrationData.loaderData[routeId];
99
106
  } else if (manifestRoute && !manifestRoute.hasLoader) {
100
- // Since every Remix route gets a `loader` on the client side to load
101
- // the route JS module, we need to add a `null` value to `loaderData`
102
- // for any routes that don't have server loaders so our partial
103
- // hydration logic doesn't kick off the route module loaders during
104
- // hydration
105
107
  hydrationData.loaderData[routeId] = null;
106
108
  }
107
109
  }
108
110
  }
109
111
  if (hydrationData && hydrationData.errors) {
110
- // TODO: De-dup this or remove entirely in v7 where single fetch is the
111
- // only approach and we have already serialized or deserialized on the server
112
- hydrationData.errors = UNSAFE_deserializeErrors(hydrationData.errors);
112
+ hydrationData.errors = deserializeErrors(hydrationData.errors);
113
113
  }
114
114
  }
115
-
116
- // We don't use createBrowserRouter here because we need fine-grained control
117
- // over initialization to support synchronous `clientLoader` flows.
118
- let router = UNSAFE_createRouter({
115
+ let router2 = createRouter({
119
116
  routes,
120
- history: UNSAFE_createBrowserHistory(),
117
+ history: createBrowserHistory(),
121
118
  basename: ssrInfo.context.basename,
122
119
  hydrationData,
123
- mapRouteProperties: UNSAFE_mapRouteProperties,
124
- dataStrategy: UNSAFE_getSingleFetchDataStrategy(ssrInfo.manifest, ssrInfo.routeModules, () => router),
125
- patchRoutesOnNavigation: UNSAFE_getPatchRoutesOnNavigationFunction(ssrInfo.manifest, ssrInfo.routeModules, ssrInfo.context.isSpaMode, ssrInfo.context.basename)
120
+ mapRouteProperties,
121
+ dataStrategy: getSingleFetchDataStrategy(
122
+ ssrInfo.manifest,
123
+ ssrInfo.routeModules,
124
+ () => router2
125
+ ),
126
+ patchRoutesOnNavigation: getPatchRoutesOnNavigationFunction(
127
+ ssrInfo.manifest,
128
+ ssrInfo.routeModules,
129
+ ssrInfo.context.isSpaMode,
130
+ ssrInfo.context.basename
131
+ )
126
132
  });
127
- ssrInfo.router = router;
128
-
129
- // We can call initialize() immediately if the router doesn't have any
130
- // loaders to run on hydration
131
- if (router.state.initialized) {
133
+ ssrInfo.router = router2;
134
+ if (router2.state.initialized) {
132
135
  ssrInfo.routerInitialized = true;
133
- router.initialize();
136
+ router2.initialize();
134
137
  }
135
-
136
- // @ts-ignore
137
- router.createRoutesForHMR = /* spacer so ts-ignore does not affect the right hand of the assignment */
138
- UNSAFE_createClientRoutesWithHMRRevalidationOptOut;
139
- window.__reactRouterDataRouter = router;
140
- return router;
138
+ router2.createRoutesForHMR = /* spacer so ts-ignore does not affect the right hand of the assignment */
139
+ createClientRoutesWithHMRRevalidationOptOut;
140
+ window.__reactRouterDataRouter = router2;
141
+ return router2;
141
142
  }
142
-
143
- /**
144
- * @category Router Components
145
- */
146
143
  function HydratedRouter() {
147
- var _ssrInfo;
148
144
  if (!router) {
149
145
  router = createHydratedRouter();
150
146
  }
151
-
152
- // Critical CSS can become stale after code changes, e.g. styles might be
153
- // removed from a component, but the styles will still be present in the
154
- // server HTML. This allows our HMR logic to clear the critical CSS state.
155
- let [criticalCss, setCriticalCss] = React.useState(process.env.NODE_ENV === "development" ? (_ssrInfo = ssrInfo) == null ? void 0 : _ssrInfo.context.criticalCss : undefined);
147
+ let [criticalCss, setCriticalCss] = React2.useState(
148
+ process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0
149
+ );
156
150
  if (process.env.NODE_ENV === "development") {
157
151
  if (ssrInfo) {
158
- window.__reactRouterClearCriticalCss = () => setCriticalCss(undefined);
152
+ window.__reactRouterClearCriticalCss = () => setCriticalCss(void 0);
159
153
  }
160
154
  }
161
- let [location, setLocation] = React.useState(router.state.location);
162
- React.useLayoutEffect(() => {
163
- // If we had to run clientLoaders on hydration, we delay initialization until
164
- // after we've hydrated to avoid hydration issues from synchronous client loaders
155
+ let [location, setLocation] = React2.useState(router.state.location);
156
+ React2.useLayoutEffect(() => {
165
157
  if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
166
158
  ssrInfo.routerInitialized = true;
167
159
  ssrInfo.router.initialize();
168
160
  }
169
161
  }, []);
170
- React.useLayoutEffect(() => {
162
+ React2.useLayoutEffect(() => {
171
163
  if (ssrInfo && ssrInfo.router) {
172
- return ssrInfo.router.subscribe(newState => {
164
+ return ssrInfo.router.subscribe((newState) => {
173
165
  if (newState.location !== location) {
174
166
  setLocation(newState.location);
175
167
  }
176
168
  });
177
169
  }
178
170
  }, [location]);
179
- !ssrInfo ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "ssrInfo unavailable for HydratedRouter") : UNSAFE_invariant(false) : void 0;
180
- UNSAFE_useFogOFWarDiscovery(router, ssrInfo.manifest, ssrInfo.routeModules, ssrInfo.context.isSpaMode);
181
-
182
- // We need to include a wrapper RemixErrorBoundary here in case the root error
183
- // boundary also throws and we need to bubble up outside of the router entirely.
184
- // Then we need a stateful location here so the user can back-button navigate
185
- // out of there
171
+ invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
172
+ useFogOFWarDiscovery(
173
+ router,
174
+ ssrInfo.manifest,
175
+ ssrInfo.routeModules,
176
+ ssrInfo.context.isSpaMode
177
+ );
186
178
  return (
187
- /*#__PURE__*/
188
179
  // This fragment is important to ensure we match the <ServerRouter> JSX
189
180
  // structure so that useId values hydrate correctly
190
- React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UNSAFE_FrameworkContext.Provider, {
191
- value: {
192
- manifest: ssrInfo.manifest,
193
- routeModules: ssrInfo.routeModules,
194
- future: ssrInfo.context.future,
195
- criticalCss,
196
- isSpaMode: ssrInfo.context.isSpaMode
197
- }
198
- }, /*#__PURE__*/React.createElement(UNSAFE_RemixErrorBoundary, {
199
- location: location
200
- }, /*#__PURE__*/React.createElement(RouterProvider, {
201
- router: router
202
- }))), /*#__PURE__*/React.createElement(React.Fragment, null))
181
+ /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
182
+ FrameworkContext.Provider,
183
+ {
184
+ value: {
185
+ manifest: ssrInfo.manifest,
186
+ routeModules: ssrInfo.routeModules,
187
+ future: ssrInfo.context.future,
188
+ criticalCss,
189
+ isSpaMode: ssrInfo.context.isSpaMode
190
+ }
191
+ },
192
+ /* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location }, /* @__PURE__ */ React2.createElement(RouterProvider2, { router }))
193
+ ), /* @__PURE__ */ React2.createElement(React2.Fragment, null))
203
194
  );
204
195
  }
205
-
206
- function RouterProvider(props) {
207
- return /*#__PURE__*/React.createElement(RouterProvider$1, _extends({
208
- flushSync: ReactDOM.flushSync
209
- }, props));
210
- }
211
-
212
- export { HydratedRouter, RouterProvider };
213
- //# sourceMappingURL=dom-export.mjs.map
196
+ export {
197
+ HydratedRouter,
198
+ RouterProvider2 as RouterProvider
199
+ };