react-router 7.0.0-pre.5 → 7.0.0

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 (42) hide show
  1. package/CHANGELOG.md +98 -184
  2. package/dist/{chunk-ICGFMBUV.mjs → development/chunk-U6WQEHBI.mjs} +4 -3
  3. package/dist/development/data-CQbyyGzl.d.mts +11 -0
  4. package/dist/development/data-CQbyyGzl.d.ts +11 -0
  5. package/dist/development/dom-export.d.mts +13 -0
  6. package/dist/{dom-export.d.ts → development/dom-export.d.ts} +2 -2
  7. package/dist/{dom-export.js → development/dom-export.js} +1 -1
  8. package/dist/{dom-export.mjs → development/dom-export.mjs} +2 -2
  9. package/dist/development/fog-of-war-BDQTYoRQ.d.mts +1595 -0
  10. package/dist/{fog-of-war-BijhfqFM.d.ts → development/fog-of-war-CbNQuoo8.d.ts} +2 -2
  11. package/dist/development/index.d.mts +840 -0
  12. package/dist/{index.d.ts → development/index.d.ts} +6 -5
  13. package/dist/{index.js → development/index.js} +4 -3
  14. package/dist/{index.mjs → development/index.mjs} +2 -2
  15. package/dist/development/lib/types/route-module.d.mts +102 -0
  16. package/dist/development/lib/types/route-module.d.ts +102 -0
  17. package/dist/{lib/types.js → development/lib/types/route-module.js} +4 -4
  18. package/dist/{lib/types.mjs → development/lib/types/route-module.mjs} +1 -1
  19. package/dist/{types-BlYP8xpH.d.mts → development/route-data-DuV3tXo2.d.mts} +20 -94
  20. package/dist/{types-BlYP8xpH.d.ts → development/route-data-DuV3tXo2.d.ts} +20 -94
  21. package/dist/production/chunk-L6MGG5FJ.mjs +9618 -0
  22. package/dist/production/data-CQbyyGzl.d.mts +11 -0
  23. package/dist/production/data-CQbyyGzl.d.ts +11 -0
  24. package/dist/production/dom-export.d.mts +13 -0
  25. package/dist/{dom-export.d.mts → production/dom-export.d.ts} +2 -2
  26. package/dist/production/dom-export.js +5502 -0
  27. package/dist/production/dom-export.mjs +199 -0
  28. package/dist/production/fog-of-war-BDQTYoRQ.d.mts +1595 -0
  29. package/dist/{fog-of-war-Bz_EDtxF.d.mts → production/fog-of-war-CbNQuoo8.d.ts} +2 -2
  30. package/dist/production/index.d.mts +840 -0
  31. package/dist/{index.d.mts → production/index.d.ts} +6 -5
  32. package/dist/production/index.js +9764 -0
  33. package/dist/production/index.mjs +235 -0
  34. package/dist/production/lib/types/route-module.d.mts +102 -0
  35. package/dist/production/lib/types/route-module.d.ts +102 -0
  36. package/dist/production/lib/types/route-module.js +28 -0
  37. package/dist/production/lib/types/route-module.mjs +10 -0
  38. package/dist/production/route-data-DuV3tXo2.d.mts +1546 -0
  39. package/dist/production/route-data-DuV3tXo2.d.ts +1546 -0
  40. package/package.json +37 -23
  41. package/dist/lib/types.d.mts +0 -2
  42. package/dist/lib/types.d.ts +0 -2
@@ -0,0 +1,199 @@
1
+ /**
2
+ * react-router v7.0.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
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-L6MGG5FJ.mjs";
29
+
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 });
35
+ }
36
+
37
+ // lib/dom-export/hydrated-router.tsx
38
+ import * as React2 from "react";
39
+ var ssrInfo = null;
40
+ var router = null;
41
+ function initSsrInfo() {
42
+ if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
43
+ ssrInfo = {
44
+ context: window.__reactRouterContext,
45
+ manifest: window.__reactRouterManifest,
46
+ routeModules: window.__reactRouterRouteModules,
47
+ stateDecodingPromise: void 0,
48
+ router: void 0,
49
+ routerInitialized: false
50
+ };
51
+ }
52
+ }
53
+ function createHydratedRouter() {
54
+ initSsrInfo();
55
+ if (!ssrInfo) {
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
+ );
59
+ }
60
+ let localSsrInfo = ssrInfo;
61
+ if (!ssrInfo.stateDecodingPromise) {
62
+ let stream = ssrInfo.context.stream;
63
+ invariant(stream, "No stream found for single fetch decoding");
64
+ ssrInfo.context.stream = void 0;
65
+ ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then((value) => {
66
+ ssrInfo.context.state = value.value;
67
+ localSsrInfo.stateDecodingPromise.value = true;
68
+ }).catch((e) => {
69
+ localSsrInfo.stateDecodingPromise.error = e;
70
+ });
71
+ }
72
+ if (ssrInfo.stateDecodingPromise.error) {
73
+ throw ssrInfo.stateDecodingPromise.error;
74
+ }
75
+ if (!ssrInfo.stateDecodingPromise.value) {
76
+ throw ssrInfo.stateDecodingPromise;
77
+ }
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;
85
+ if (!ssrInfo.context.isSpaMode) {
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
+ );
95
+ if (initialMatches) {
96
+ for (let match of initialMatches) {
97
+ let routeId = match.route.id;
98
+ let route = ssrInfo.routeModules[routeId];
99
+ let manifestRoute = ssrInfo.manifest.routes[routeId];
100
+ if (route && manifestRoute && shouldHydrateRouteLoader(
101
+ manifestRoute,
102
+ route,
103
+ ssrInfo.context.isSpaMode
104
+ ) && (route.HydrateFallback || !manifestRoute.hasLoader)) {
105
+ delete hydrationData.loaderData[routeId];
106
+ } else if (manifestRoute && !manifestRoute.hasLoader) {
107
+ hydrationData.loaderData[routeId] = null;
108
+ }
109
+ }
110
+ }
111
+ if (hydrationData && hydrationData.errors) {
112
+ hydrationData.errors = deserializeErrors(hydrationData.errors);
113
+ }
114
+ }
115
+ let router2 = createRouter({
116
+ routes,
117
+ history: createBrowserHistory(),
118
+ basename: ssrInfo.context.basename,
119
+ hydrationData,
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
+ )
132
+ });
133
+ ssrInfo.router = router2;
134
+ if (router2.state.initialized) {
135
+ ssrInfo.routerInitialized = true;
136
+ router2.initialize();
137
+ }
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;
142
+ }
143
+ function HydratedRouter() {
144
+ if (!router) {
145
+ router = createHydratedRouter();
146
+ }
147
+ let [criticalCss, setCriticalCss] = React2.useState(
148
+ process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0
149
+ );
150
+ if (process.env.NODE_ENV === "development") {
151
+ if (ssrInfo) {
152
+ window.__reactRouterClearCriticalCss = () => setCriticalCss(void 0);
153
+ }
154
+ }
155
+ let [location, setLocation] = React2.useState(router.state.location);
156
+ React2.useLayoutEffect(() => {
157
+ if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
158
+ ssrInfo.routerInitialized = true;
159
+ ssrInfo.router.initialize();
160
+ }
161
+ }, []);
162
+ React2.useLayoutEffect(() => {
163
+ if (ssrInfo && ssrInfo.router) {
164
+ return ssrInfo.router.subscribe((newState) => {
165
+ if (newState.location !== location) {
166
+ setLocation(newState.location);
167
+ }
168
+ });
169
+ }
170
+ }, [location]);
171
+ invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
172
+ useFogOFWarDiscovery(
173
+ router,
174
+ ssrInfo.manifest,
175
+ ssrInfo.routeModules,
176
+ ssrInfo.context.isSpaMode
177
+ );
178
+ return (
179
+ // This fragment is important to ensure we match the <ServerRouter> JSX
180
+ // structure so that useId values hydrate correctly
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))
194
+ );
195
+ }
196
+ export {
197
+ HydratedRouter,
198
+ RouterProvider2 as RouterProvider
199
+ };