react-router 7.0.0-pre.1 → 7.0.0-pre.3

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