react-router 8.0.0 → 8.1.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 (143) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/development/dom-export.js +1 -1
  3. package/dist/development/index-react-server-client.js +1 -1
  4. package/dist/development/index-react-server.d.ts +32 -7
  5. package/dist/development/index-react-server.js +180 -152
  6. package/dist/development/index.d.ts +2 -3
  7. package/dist/development/index.js +1 -1
  8. package/dist/development/lib/actions.js +1 -1
  9. package/dist/development/lib/components.js +1 -1
  10. package/dist/development/lib/context.js +1 -1
  11. package/dist/development/lib/dom/dom.js +1 -1
  12. package/dist/development/lib/dom/lib.js +2 -2
  13. package/dist/development/lib/dom/server.js +1 -1
  14. package/dist/development/lib/dom/ssr/components.js +1 -1
  15. package/dist/development/lib/dom/ssr/data.js +1 -1
  16. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  17. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  18. package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
  19. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  20. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  21. package/dist/development/lib/dom/ssr/links.js +1 -1
  22. package/dist/development/lib/dom/ssr/markup.js +1 -1
  23. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  24. package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
  25. package/dist/development/lib/dom/ssr/routes.js +1 -1
  26. package/dist/development/lib/dom/ssr/server.js +1 -1
  27. package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
  28. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  29. package/dist/development/lib/dom-export/hydrated-router.js +1 -1
  30. package/dist/development/lib/errors.js +1 -1
  31. package/dist/development/lib/hooks.js +1 -1
  32. package/dist/development/lib/href.js +1 -1
  33. package/dist/development/lib/router/history.js +1 -1
  34. package/dist/development/lib/router/instrumentation.d.ts +33 -8
  35. package/dist/development/lib/router/instrumentation.js +176 -99
  36. package/dist/development/lib/router/router.js +19 -19
  37. package/dist/development/lib/router/url.js +1 -1
  38. package/dist/development/lib/router/utils.js +17 -2
  39. package/dist/development/lib/rsc/browser.js +3 -4
  40. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  41. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  42. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  43. package/dist/development/lib/rsc/route-modules.js +1 -1
  44. package/dist/development/lib/rsc/server.ssr.js +1 -1
  45. package/dist/development/lib/server-runtime/cookies.js +1 -1
  46. package/dist/development/lib/server-runtime/crypto.js +1 -1
  47. package/dist/development/lib/server-runtime/data.js +1 -1
  48. package/dist/development/lib/server-runtime/dev.js +1 -1
  49. package/dist/development/lib/server-runtime/entry.js +1 -1
  50. package/dist/development/lib/server-runtime/errors.js +1 -1
  51. package/dist/development/lib/server-runtime/headers.js +1 -1
  52. package/dist/development/lib/server-runtime/invariant.js +1 -1
  53. package/dist/development/lib/server-runtime/mode.js +1 -1
  54. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  55. package/dist/development/lib/server-runtime/routes.js +1 -1
  56. package/dist/development/lib/server-runtime/server.js +12 -5
  57. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  58. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  59. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  60. package/dist/development/lib/server-runtime/sessions.js +1 -1
  61. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  62. package/dist/development/lib/server-runtime/urls.js +1 -1
  63. package/dist/development/lib/server-runtime/warnings.js +1 -1
  64. package/dist/development/lib/types/internal.js +1 -1
  65. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  66. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  67. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  68. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  69. package/dist/production/dom-export.js +1 -1
  70. package/dist/production/index-react-server-client.js +1 -1
  71. package/dist/production/index-react-server.d.ts +32 -7
  72. package/dist/production/index-react-server.js +180 -152
  73. package/dist/production/index.d.ts +2 -3
  74. package/dist/production/index.js +1 -1
  75. package/dist/production/lib/actions.js +1 -1
  76. package/dist/production/lib/components.js +1 -1
  77. package/dist/production/lib/context.js +1 -1
  78. package/dist/production/lib/dom/dom.js +1 -1
  79. package/dist/production/lib/dom/lib.js +2 -2
  80. package/dist/production/lib/dom/server.js +1 -1
  81. package/dist/production/lib/dom/ssr/components.js +1 -1
  82. package/dist/production/lib/dom/ssr/data.js +1 -1
  83. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  84. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  85. package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
  86. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  87. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  88. package/dist/production/lib/dom/ssr/links.js +1 -1
  89. package/dist/production/lib/dom/ssr/markup.js +1 -1
  90. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  91. package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
  92. package/dist/production/lib/dom/ssr/routes.js +1 -1
  93. package/dist/production/lib/dom/ssr/server.js +1 -1
  94. package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
  95. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  96. package/dist/production/lib/dom-export/hydrated-router.js +1 -1
  97. package/dist/production/lib/errors.js +1 -1
  98. package/dist/production/lib/hooks.js +1 -1
  99. package/dist/production/lib/href.js +1 -1
  100. package/dist/production/lib/router/history.js +1 -1
  101. package/dist/production/lib/router/instrumentation.d.ts +33 -8
  102. package/dist/production/lib/router/instrumentation.js +176 -99
  103. package/dist/production/lib/router/router.js +19 -19
  104. package/dist/production/lib/router/url.js +1 -1
  105. package/dist/production/lib/router/utils.js +17 -2
  106. package/dist/production/lib/rsc/browser.js +3 -4
  107. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  108. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  109. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  110. package/dist/production/lib/rsc/route-modules.js +1 -1
  111. package/dist/production/lib/rsc/server.ssr.js +1 -1
  112. package/dist/production/lib/server-runtime/cookies.js +1 -1
  113. package/dist/production/lib/server-runtime/crypto.js +1 -1
  114. package/dist/production/lib/server-runtime/data.js +1 -1
  115. package/dist/production/lib/server-runtime/dev.js +1 -1
  116. package/dist/production/lib/server-runtime/entry.js +1 -1
  117. package/dist/production/lib/server-runtime/errors.js +1 -1
  118. package/dist/production/lib/server-runtime/headers.js +1 -1
  119. package/dist/production/lib/server-runtime/invariant.js +1 -1
  120. package/dist/production/lib/server-runtime/mode.js +1 -1
  121. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  122. package/dist/production/lib/server-runtime/routes.js +1 -1
  123. package/dist/production/lib/server-runtime/server.js +12 -5
  124. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  125. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  126. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  127. package/dist/production/lib/server-runtime/sessions.js +1 -1
  128. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  129. package/dist/production/lib/server-runtime/urls.js +1 -1
  130. package/dist/production/lib/server-runtime/warnings.js +1 -1
  131. package/dist/production/lib/types/internal.js +1 -1
  132. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  133. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  134. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  135. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  136. package/docs/how-to/instrumentation.md +131 -26
  137. package/docs/how-to/middleware.md +1 -1
  138. package/docs/how-to/route-module-type-safety.md +1 -16
  139. package/docs/upgrading/component-routes.md +1 -1
  140. package/docs/upgrading/router-provider.md +1 -1
  141. package/package.json +1 -1
  142. package/dist/development/lib/server-runtime/data.d.ts +0 -13
  143. package/dist/production/lib/server-runtime/data.d.ts +0 -13
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -12,6 +12,19 @@ type ClientInstrumentation = {
12
12
  type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
13
13
  type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
14
14
  type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
15
+ /**
16
+ * Route metadata available after React Router has matched an instrumented
17
+ * request, navigation, or fetcher call.
18
+ */
19
+ type InstrumentationResultMeta = {
20
+ url: LoaderFunctionArgs["url"];
21
+ pattern: string;
22
+ params: LoaderFunctionArgs["params"];
23
+ };
24
+ /**
25
+ * Result returned by route-level instrumented handler calls, such as
26
+ * instrumented loaders, actions, middleware, and lazy route functions.
27
+ */
15
28
  type InstrumentationHandlerResult = {
16
29
  status: "success";
17
30
  error: undefined;
@@ -19,7 +32,21 @@ type InstrumentationHandlerResult = {
19
32
  status: "error";
20
33
  error: Error;
21
34
  };
22
- type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
35
+ /**
36
+ * Result returned by client-side router instrumented navigation and fetcher
37
+ * calls.
38
+ */
39
+ type InstrumentationClientRouterResult = InstrumentationHandlerResult & {
40
+ meta: InstrumentationResultMeta | undefined;
41
+ };
42
+ /**
43
+ * Result returned by server request handler instrumentation.
44
+ */
45
+ type InstrumentationServerHandlerResult = InstrumentationHandlerResult & {
46
+ statusCode: number;
47
+ meta: InstrumentationResultMeta | undefined;
48
+ };
49
+ type InstrumentFunction<T, TInnerResult = InstrumentationHandlerResult> = (handler: () => Promise<TInnerResult>, info: T) => Promise<void>;
23
50
  type ReadonlyRequest = {
24
51
  method: string;
25
52
  url: string;
@@ -42,18 +69,16 @@ type RouteInstrumentations = {
42
69
  action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
43
70
  };
44
71
  type RouteLazyInstrumentationInfo = undefined;
45
- type RouteHandlerInstrumentationInfo = Readonly<{
72
+ type RouteHandlerInstrumentationInfo = Readonly<Omit<LoaderFunctionArgs, "request" | "context"> & {
46
73
  request: ReadonlyRequest;
47
- params: LoaderFunctionArgs["params"];
48
- pattern: string;
49
74
  context: ReadonlyContext;
50
75
  }>;
51
76
  type InstrumentableRouter = {
52
77
  instrument(instrumentations: RouterInstrumentations): void;
53
78
  };
54
79
  type RouterInstrumentations = {
55
- navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
56
- fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
80
+ navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo, InstrumentationClientRouterResult>;
81
+ fetch?: InstrumentFunction<RouterFetchInstrumentationInfo, InstrumentationClientRouterResult>;
57
82
  };
58
83
  type RouterNavigationInstrumentationInfo = Readonly<{
59
84
  to: string | number;
@@ -76,11 +101,11 @@ type InstrumentableRequestHandler = {
76
101
  instrument(instrumentations: RequestHandlerInstrumentations): void;
77
102
  };
78
103
  type RequestHandlerInstrumentations = {
79
- request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
104
+ request?: InstrumentFunction<RequestHandlerInstrumentationInfo, InstrumentationServerHandlerResult>;
80
105
  };
81
106
  type RequestHandlerInstrumentationInfo = Readonly<{
82
107
  request: ReadonlyRequest;
83
108
  context: ReadonlyContext | undefined;
84
109
  }>;
85
110
  //#endregion
86
- export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationHandlerResult, ServerInstrumentation };
111
+ export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationClientRouterResult, InstrumentationHandlerResult, InstrumentationServerHandlerResult, ServerInstrumentation };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,8 +9,11 @@
9
9
  * @license MIT
10
10
  */
11
11
  import { createPath, invariant } from "./history.js";
12
+ import { RouterContextProvider, createContext } from "./utils.js";
12
13
  //#region lib/router/instrumentation.ts
13
14
  const UninstrumentedSymbol = Symbol("Uninstrumented");
15
+ const instrumentationResultMetaContext = createContext();
16
+ let instrumentationClientResultMetaReceivers = /* @__PURE__ */ new WeakMap();
14
17
  function getRouteInstrumentationUpdates(fns, route) {
15
18
  let aggregated = {
16
19
  lazy: [],
@@ -26,50 +29,67 @@ function getRouteInstrumentationUpdates(fns, route) {
26
29
  index: route.index,
27
30
  path: route.path,
28
31
  instrument(i) {
29
- let keys = Object.keys(aggregated);
30
- for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
32
+ if (i.lazy != null) aggregated.lazy.push(i.lazy);
33
+ if (i["lazy.loader"] != null) aggregated["lazy.loader"].push(i["lazy.loader"]);
34
+ if (i["lazy.action"] != null) aggregated["lazy.action"].push(i["lazy.action"]);
35
+ if (i["lazy.middleware"] != null) aggregated["lazy.middleware"].push(i["lazy.middleware"]);
36
+ if (i.middleware != null) aggregated.middleware.push(i.middleware);
37
+ if (i.loader != null) aggregated.loader.push(i.loader);
38
+ if (i.action != null) aggregated.action.push(i.action);
31
39
  }
32
40
  }));
33
41
  let updates = {};
34
42
  if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
35
- let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
36
- if (instrumented) updates.lazy = instrumented;
43
+ let lazy = route.lazy;
44
+ updates.lazy = async (...args) => {
45
+ return throwOrReturnResult(await recurseRight(aggregated.lazy, void 0, () => lazy(...args), getInstrumentationInnerResult));
46
+ };
37
47
  }
38
48
  if (typeof route.lazy === "object") {
39
49
  let lazyObject = route.lazy;
40
- [
41
- "middleware",
42
- "loader",
43
- "action"
44
- ].forEach((key) => {
45
- let lazyFn = lazyObject[key];
46
- let instrumentations = aggregated[`lazy.${key}`];
47
- if (typeof lazyFn === "function" && instrumentations.length > 0) {
48
- let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
49
- if (instrumented) updates.lazy = Object.assign(updates.lazy || {}, { [key]: instrumented });
50
- }
51
- });
52
- }
53
- ["loader", "action"].forEach((key) => {
54
- let handler = route[key];
55
- if (typeof handler === "function" && aggregated[key].length > 0) {
56
- let original = handler[UninstrumentedSymbol] ?? handler;
57
- let instrumented = wrapImpl(aggregated[key], original, (...args) => getHandlerInfo(args[0]));
58
- if (instrumented) {
59
- if (key === "loader" && original.hydrate === true) instrumented.hydrate = true;
60
- instrumented[UninstrumentedSymbol] = original;
61
- updates[key] = instrumented;
62
- }
50
+ if (typeof lazyObject.middleware === "function" && aggregated["lazy.middleware"].length > 0) {
51
+ let middleware = lazyObject.middleware;
52
+ updates.lazy = Object.assign(updates.lazy || {}, { middleware: async (...args) => {
53
+ return throwOrReturnResult(await recurseRight(aggregated["lazy.middleware"], void 0, () => middleware(...args), getInstrumentationInnerResult));
54
+ } });
63
55
  }
64
- });
65
- if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) updates.middleware = route.middleware.map((middleware) => {
66
- let original = middleware[UninstrumentedSymbol] ?? middleware;
67
- let instrumented = wrapImpl(aggregated.middleware, original, (...args) => getHandlerInfo(args[0]));
68
- if (instrumented) {
69
- instrumented[UninstrumentedSymbol] = original;
70
- return instrumented;
56
+ if (typeof lazyObject.loader === "function" && aggregated["lazy.loader"].length > 0) {
57
+ let loader = lazyObject.loader;
58
+ updates.lazy = Object.assign(updates.lazy || {}, { loader: async (...args) => {
59
+ return throwOrReturnResult(await recurseRight(aggregated["lazy.loader"], void 0, () => loader(...args), getInstrumentationInnerResult));
60
+ } });
61
+ }
62
+ if (typeof lazyObject.action === "function" && aggregated["lazy.action"].length > 0) {
63
+ let action = lazyObject.action;
64
+ updates.lazy = Object.assign(updates.lazy || {}, { action: async (...args) => {
65
+ return throwOrReturnResult(await recurseRight(aggregated["lazy.action"], void 0, () => action(...args), getInstrumentationInnerResult));
66
+ } });
71
67
  }
72
- return middleware;
68
+ }
69
+ if (typeof route.loader === "function" && aggregated.loader.length > 0) {
70
+ let original = getUninstrumentedHandler(route.loader);
71
+ let instrumented = async (...args) => {
72
+ return throwOrReturnResult(await recurseRight(aggregated.loader, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
73
+ };
74
+ if (original.hydrate === true) instrumented.hydrate = true;
75
+ setUninstrumentedHandler(instrumented, original);
76
+ updates.loader = instrumented;
77
+ }
78
+ if (typeof route.action === "function" && aggregated.action.length > 0) {
79
+ let original = getUninstrumentedHandler(route.action);
80
+ let instrumented = async (...args) => {
81
+ return throwOrReturnResult(await recurseRight(aggregated.action, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
82
+ };
83
+ setUninstrumentedHandler(instrumented, original);
84
+ updates.action = instrumented;
85
+ }
86
+ if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) updates.middleware = route.middleware.map((middleware) => {
87
+ let original = getUninstrumentedHandler(middleware);
88
+ let instrumented = async (...args) => {
89
+ return throwOrReturnResult(await recurseRight(aggregated.middleware, getHandlerInfo(args[0]), () => original(...args), getInstrumentationInnerResult));
90
+ };
91
+ setUninstrumentedHandler(instrumented, original);
92
+ return instrumented;
73
93
  });
74
94
  return updates;
75
95
  }
@@ -79,93 +99,138 @@ function instrumentClientSideRouter(router, fns) {
79
99
  fetch: []
80
100
  };
81
101
  fns.forEach((fn) => fn({ instrument(i) {
82
- let keys = Object.keys(i);
83
- for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
102
+ if (i.navigate != null) aggregated.navigate.push(i.navigate);
103
+ if (i.fetch != null) aggregated.fetch.push(i.fetch);
84
104
  } }));
85
105
  if (aggregated.navigate.length > 0) {
86
- let navigate = router.navigate[UninstrumentedSymbol] ?? router.navigate;
87
- let instrumentedNavigate = wrapImpl(aggregated.navigate, navigate, (...args) => {
106
+ let navigate = getUninstrumentedHandler(router.navigate);
107
+ let instrumentedNavigate = async (...args) => {
88
108
  let [to, opts] = args;
89
- return {
109
+ let meta;
110
+ let info = {
90
111
  to: typeof to === "number" || typeof to === "string" ? to : to ? createPath(to) : ".",
91
112
  ...getRouterInfo(router, opts ?? {})
92
113
  };
93
- });
94
- if (instrumentedNavigate) {
95
- instrumentedNavigate[UninstrumentedSymbol] = navigate;
96
- router.navigate = instrumentedNavigate;
97
- }
114
+ return throwOrReturnResult(await recurseRight(aggregated.navigate, info, async () => {
115
+ if (typeof to === "number") return await navigate(...args);
116
+ let cleanup = setInstrumentationClientResultMetaReceiver(router, (value) => {
117
+ meta = value;
118
+ });
119
+ try {
120
+ return await navigate(...args);
121
+ } finally {
122
+ cleanup();
123
+ }
124
+ }, (result) => ({
125
+ ...getInstrumentationInnerResult(result),
126
+ meta
127
+ })));
128
+ };
129
+ setUninstrumentedHandler(instrumentedNavigate, navigate);
130
+ router.navigate = instrumentedNavigate;
98
131
  }
99
132
  if (aggregated.fetch.length > 0) {
100
- let fetch = router.fetch[UninstrumentedSymbol] ?? router.fetch;
101
- let instrumentedFetch = wrapImpl(aggregated.fetch, fetch, (...args) => {
102
- let [key, , href, opts] = args;
103
- return {
133
+ let fetch = getUninstrumentedHandler(router.fetch);
134
+ let instrumentedFetch = async (...args) => {
135
+ let [key, _, href, opts] = args;
136
+ let meta;
137
+ return throwOrReturnResult(await recurseRight(aggregated.fetch, {
104
138
  href: href ?? ".",
105
139
  fetcherKey: key,
106
140
  ...getRouterInfo(router, opts ?? {})
107
- };
108
- });
109
- if (instrumentedFetch) {
110
- instrumentedFetch[UninstrumentedSymbol] = fetch;
111
- router.fetch = instrumentedFetch;
112
- }
141
+ }, async () => {
142
+ let cleanup = setInstrumentationClientResultMetaReceiver(router, (value) => {
143
+ meta = value;
144
+ });
145
+ try {
146
+ return await fetch(...args);
147
+ } finally {
148
+ cleanup();
149
+ }
150
+ }, (result) => ({
151
+ ...getInstrumentationInnerResult(result),
152
+ meta
153
+ })));
154
+ };
155
+ setUninstrumentedHandler(instrumentedFetch, fetch);
156
+ router.fetch = instrumentedFetch;
113
157
  }
114
158
  return router;
115
159
  }
116
160
  function instrumentHandler(handler, fns) {
117
161
  let aggregated = { request: [] };
118
162
  fns.forEach((fn) => fn({ instrument(i) {
119
- let keys = Object.keys(i);
120
- for (let key of keys) if (i[key]) aggregated[key].push(i[key]);
163
+ if (i.request != null) aggregated.request.push(i.request);
121
164
  } }));
122
165
  let instrumentedHandler = handler;
123
- if (aggregated.request.length > 0) instrumentedHandler = wrapImpl(aggregated.request, handler, (...args) => {
166
+ if (aggregated.request.length > 0) instrumentedHandler = async (...args) => {
124
167
  let [request, context] = args;
125
- return {
168
+ let instrumentationContext = context ?? new RouterContextProvider();
169
+ return throwOrReturnResult(await recurseRight(aggregated.request, {
126
170
  request: getReadonlyRequest(request),
127
- context: context != null ? getReadonlyContext(context) : context
128
- };
129
- });
171
+ context: getReadonlyContext(instrumentationContext)
172
+ }, () => handler(request, instrumentationContext), (result, info) => {
173
+ let meta;
174
+ try {
175
+ meta = info.context?.get(instrumentationResultMetaContext);
176
+ } catch {}
177
+ invariant(result.value instanceof Response, "Expected a Response from the request handler");
178
+ return {
179
+ ...getInstrumentationInnerResult(result),
180
+ statusCode: result.value.status,
181
+ meta
182
+ };
183
+ }));
184
+ };
130
185
  return instrumentedHandler;
131
186
  }
132
- function wrapImpl(impls, handler, getInfo) {
133
- if (impls.length === 0) return null;
134
- return async (...args) => {
135
- let result = await recurseRight(impls, getInfo(...args), () => handler(...args), impls.length - 1);
136
- if (result.type === "error") throw result.value;
137
- return result.value;
187
+ function getUninstrumentedHandler(handler) {
188
+ return handler[UninstrumentedSymbol] ?? handler;
189
+ }
190
+ function setUninstrumentedHandler(handler, uninstrumentedHandler) {
191
+ handler[UninstrumentedSymbol] = uninstrumentedHandler;
192
+ }
193
+ function setInstrumentationClientResultMetaReceiver(router, receiver) {
194
+ instrumentationClientResultMetaReceivers.set(router, receiver);
195
+ return () => {
196
+ if (instrumentationClientResultMetaReceivers.get(router) === receiver) instrumentationClientResultMetaReceivers.delete(router);
138
197
  };
139
198
  }
140
- async function recurseRight(impls, info, handler, index) {
199
+ function consumeInstrumentationClientResultMetaReceiver(router) {
200
+ let receiver = instrumentationClientResultMetaReceivers.get(router);
201
+ instrumentationClientResultMetaReceivers.delete(router);
202
+ return receiver;
203
+ }
204
+ function throwOrReturnResult(result) {
205
+ if (result.type === "error") throw result.value;
206
+ return result.value;
207
+ }
208
+ async function recurseRight(impls, info, handler, getInnerResult, state = {
209
+ result: null,
210
+ innerResult: null
211
+ }, index = impls.length - 1) {
141
212
  let impl = impls[index];
142
- let result;
143
- if (!impl) try {
144
- result = {
145
- type: "success",
146
- value: await handler()
147
- };
148
- } catch (e) {
149
- result = {
150
- type: "error",
151
- value: e
152
- };
153
- }
154
- else {
213
+ if (!impl) {
214
+ try {
215
+ state.result = {
216
+ type: "success",
217
+ value: await handler()
218
+ };
219
+ } catch (e) {
220
+ state.result = {
221
+ type: "error",
222
+ value: e
223
+ };
224
+ }
225
+ state.innerResult = getInnerResult(state.result, info);
226
+ } else {
155
227
  let handlerPromise = void 0;
156
228
  let callHandler = async () => {
157
229
  if (handlerPromise) console.error("You cannot call instrumented handlers more than once");
158
- else handlerPromise = recurseRight(impls, info, handler, index - 1);
159
- result = await handlerPromise;
160
- invariant(result, "Expected a result");
161
- if (result.type === "error" && result.value instanceof Error) return {
162
- status: "error",
163
- error: result.value
164
- };
165
- return {
166
- status: "success",
167
- error: void 0
168
- };
230
+ else handlerPromise = recurseRight(impls, info, handler, getInnerResult, state, index - 1);
231
+ await handlerPromise;
232
+ invariant(state.innerResult, "Expected an inner result");
233
+ return state.innerResult;
169
234
  };
170
235
  try {
171
236
  await impl(callHandler, info);
@@ -175,18 +240,30 @@ async function recurseRight(impls, info, handler, index) {
175
240
  if (!handlerPromise) await callHandler();
176
241
  await handlerPromise;
177
242
  }
178
- if (result) return result;
179
- return {
243
+ if (state.result) return state.result;
244
+ state.result = {
180
245
  type: "error",
181
246
  value: /* @__PURE__ */ new Error("No result assigned in instrumentation chain.")
182
247
  };
248
+ state.innerResult = getInnerResult(state.result, info);
249
+ return state.result;
250
+ }
251
+ function getInstrumentationInnerResult(result) {
252
+ if (result.type === "error" && result.value instanceof Error) return {
253
+ status: "error",
254
+ error: result.value
255
+ };
256
+ return {
257
+ status: "success",
258
+ error: void 0
259
+ };
183
260
  }
184
261
  function getHandlerInfo(args) {
185
- let { request, context, params, pattern } = args;
262
+ let { request, context, params } = args;
186
263
  return {
264
+ ...args,
187
265
  request: getReadonlyRequest(request),
188
266
  params: { ...params },
189
- pattern,
190
267
  context: getReadonlyContext(context)
191
268
  };
192
269
  }
@@ -210,4 +287,4 @@ function getReadonlyContext(context) {
210
287
  return { get: (ctx) => context.get(ctx) };
211
288
  }
212
289
  //#endregion
213
- export { getRouteInstrumentationUpdates, instrumentClientSideRouter, instrumentHandler };
290
+ export { consumeInstrumentationClientResultMetaReceiver, getRouteInstrumentationUpdates, instrumentClientSideRouter, instrumentHandler, instrumentationResultMetaContext };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,8 +10,8 @@
10
10
  */
11
11
  import { PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
12
12
  import { createBrowserURLImpl, createLocation, createPath, invariant, parsePath, warning } from "./history.js";
13
- import { ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, flattenAndRankRoutes, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, matchRoutesImpl, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
14
- import { getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
13
+ import { ErrorResponseImpl, RouterContextProvider, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createDataFunctionUrl, flattenAndRankRoutes, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, matchRoutesImpl, prependBasename, removeDoubleSlashes, resolveTo, stripBasename } from "./utils.js";
14
+ import { consumeInstrumentationClientResultMetaReceiver, getRouteInstrumentationUpdates, instrumentClientSideRouter } from "./instrumentation.js";
15
15
  //#region lib/router/router.ts
16
16
  const validMutationMethodsArr = [
17
17
  "POST",
@@ -409,6 +409,7 @@ function createRouter(init) {
409
409
  init.history.go(to);
410
410
  return promise;
411
411
  }
412
+ let instrumentationNavigateMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
412
413
  let { path, submission, error } = normalizeNavigateOptions(false, normalizeTo(state.location, state.matches, basename, to, opts?.fromRouteId, opts?.relative), opts);
413
414
  let maskPath;
414
415
  if (opts?.mask) maskPath = {
@@ -465,7 +466,8 @@ function createRouter(init) {
465
466
  replace: opts && opts.replace,
466
467
  enableViewTransition: opts && opts.viewTransition,
467
468
  flushSync,
468
- callSiteDefaultShouldRevalidate: opts && opts.defaultShouldRevalidate
469
+ callSiteDefaultShouldRevalidate: opts && opts.defaultShouldRevalidate,
470
+ instrumentationNavigateMetaReceiver
469
471
  });
470
472
  }
471
473
  function revalidate() {
@@ -501,6 +503,10 @@ function createRouter(init) {
501
503
  }
502
504
  let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
503
505
  if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
506
+ if (opts?.instrumentationNavigateMetaReceiver) {
507
+ let meta = getInstrumentationNavigateMeta(init.history, location, matches);
508
+ opts.instrumentationNavigateMetaReceiver(meta);
509
+ }
504
510
  if (!matches) {
505
511
  let { error, notFoundMatches, route } = handleNavigational404(location.pathname);
506
512
  completeNavigation(location, {
@@ -760,11 +766,13 @@ function createRouter(init) {
760
766
  async function fetch(key, routeId, href, opts) {
761
767
  abortFetcher(key);
762
768
  let flushSync = (opts && opts.flushSync) === true;
769
+ let instrumentationResultMetaReceiver = consumeInstrumentationClientResultMetaReceiver(router);
763
770
  let routesToUse = dataRoutes.activeRoutes;
764
771
  let normalizedPath = normalizeTo(state.location, state.matches, basename, href, routeId, opts?.relative);
765
772
  let matches = matchRoutesImpl(routesToUse, normalizedPath, basename, false, dataRoutes.branches);
766
773
  let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
767
774
  if (fogOfWar.active && fogOfWar.matches) matches = fogOfWar.matches;
775
+ if (instrumentationResultMetaReceiver) instrumentationResultMetaReceiver(getInstrumentationNavigateMeta(init.history, normalizedPath, matches));
768
776
  if (!matches) {
769
777
  setFetcherError(key, routeId, getInternalRouterError(404, { pathname: normalizedPath }), { flushSync });
770
778
  return;
@@ -2608,21 +2616,6 @@ function createClientSideRequest(history, location, signal, submission) {
2608
2616
  }
2609
2617
  return new Request(url, init);
2610
2618
  }
2611
- function createDataFunctionUrl(request, path) {
2612
- let url = new URL(request.url);
2613
- let parsed = typeof path === "string" ? parsePath(path) : path;
2614
- url.pathname = parsed.pathname || "/";
2615
- if (parsed.search) {
2616
- let searchParams = new URLSearchParams(parsed.search);
2617
- let indexValues = searchParams.getAll("index");
2618
- searchParams.delete("index");
2619
- for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
2620
- let search = searchParams.toString();
2621
- url.search = search ? `?${search}` : "";
2622
- } else url.search = "";
2623
- url.hash = parsed.hash || "";
2624
- return url;
2625
- }
2626
2619
  function convertFormDataToSearchParams(formData) {
2627
2620
  let searchParams = new URLSearchParams();
2628
2621
  for (let [key, value] of formData.entries()) searchParams.append(key, typeof value === "string" ? value : value.name);
@@ -2827,6 +2820,13 @@ function getTargetMatch(matches, location) {
2827
2820
  let pathMatches = getPathContributingMatches(matches);
2828
2821
  return pathMatches[pathMatches.length - 1];
2829
2822
  }
2823
+ function getInstrumentationNavigateMeta(history, location, matches) {
2824
+ return {
2825
+ url: createDataFunctionUrl(history.createURL(location), location),
2826
+ pattern: matches ? getRoutePattern(matches) : "",
2827
+ params: matches?.[0]?.params ? { ...matches[0].params } : {}
2828
+ };
2829
+ }
2830
2830
  function getSubmissionFromNavigation(navigation) {
2831
2831
  let { formMethod, formAction, formEncType, text, formData, json } = navigation;
2832
2832
  if (!formMethod || !formAction || !formEncType) return;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.0
2
+ * react-router v8.1.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -781,6 +781,21 @@ function isRouteErrorResponse(error) {
781
781
  function getRoutePattern(matches) {
782
782
  return joinPaths(matches.map((m) => m.route.path).filter(Boolean)) || "/";
783
783
  }
784
+ function createDataFunctionUrl(request, path) {
785
+ let url = new URL(typeof request === "string" || request instanceof URL ? request : request.url);
786
+ let parsed = typeof path === "string" ? parsePath(path) : path;
787
+ url.pathname = parsed.pathname || "/";
788
+ if (parsed.search) {
789
+ let searchParams = new URLSearchParams(parsed.search);
790
+ let indexValues = searchParams.getAll("index");
791
+ searchParams.delete("index");
792
+ for (let value of indexValues.filter(Boolean)) searchParams.append("index", value);
793
+ let search = searchParams.toString();
794
+ url.search = search ? `?${search}` : "";
795
+ } else url.search = "";
796
+ url.hash = parsed.hash || "";
797
+ return url;
798
+ }
784
799
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
785
800
  function parseToInfo(_to, basename) {
786
801
  let to = _to;
@@ -807,4 +822,4 @@ function parseToInfo(_to, basename) {
807
822
  };
808
823
  }
809
824
  //#endregion
810
- export { ErrorResponseImpl, RouterContextProvider, SUPPORTED_ERROR_TYPES, compilePath, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createContext, data, decodePath, defaultMapRouteProperties, flattenAndRankRoutes, generatePath, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isBrowser, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, joinPaths, matchPath, matchRoutes, matchRoutesImpl, parseToInfo, prependBasename, redirect, redirectDocument, removeDoubleSlashes, removeTrailingSlash, replace, resolvePath, resolveTo, stripBasename };
825
+ export { ErrorResponseImpl, RouterContextProvider, SUPPORTED_ERROR_TYPES, compilePath, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createContext, createDataFunctionUrl, data, decodePath, defaultMapRouteProperties, flattenAndRankRoutes, generatePath, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isBrowser, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, joinPaths, matchPath, matchRoutes, matchRoutesImpl, parseToInfo, prependBasename, redirect, redirectDocument, removeDoubleSlashes, removeTrailingSlash, replace, resolvePath, resolveTo, stripBasename };