@modern-js/runtime 2.35.1 → 2.37.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 (261) hide show
  1. package/dist/cjs/cli/index.js +48 -30
  2. package/dist/cjs/common.js +27 -18
  3. package/dist/cjs/config.js +15 -3
  4. package/dist/cjs/core/appConfig.js +25 -15
  5. package/dist/cjs/core/compatible.js +60 -43
  6. package/dist/cjs/core/index.js +47 -40
  7. package/dist/cjs/core/loader/index.js +35 -9
  8. package/dist/cjs/core/loader/loaderManager.js +37 -18
  9. package/dist/cjs/core/loader/useLoader.js +45 -23
  10. package/dist/cjs/core/plugin.js +39 -31
  11. package/dist/cjs/core/types.js +15 -3
  12. package/dist/cjs/document/Body.js +35 -19
  13. package/dist/cjs/document/Comment.js +29 -14
  14. package/dist/cjs/document/DocumentContext.js +36 -10
  15. package/dist/cjs/document/DocumentStructureContext.js +36 -10
  16. package/dist/cjs/document/Head.js +40 -31
  17. package/dist/cjs/document/Html.js +34 -19
  18. package/dist/cjs/document/Links.js +28 -13
  19. package/dist/cjs/document/Root.js +37 -28
  20. package/dist/cjs/document/Script.js +29 -14
  21. package/dist/cjs/document/Scripts.js +28 -13
  22. package/dist/cjs/document/Style.js +29 -14
  23. package/dist/cjs/document/cli/index.js +68 -51
  24. package/dist/cjs/document/constants.js +64 -72
  25. package/dist/cjs/document/index.js +42 -15
  26. package/dist/cjs/exports/head.js +38 -11
  27. package/dist/cjs/exports/loadable.js +38 -11
  28. package/dist/cjs/exports/server.js +24 -7
  29. package/dist/cjs/exports/styled.js +38 -11
  30. package/dist/cjs/index.js +41 -38
  31. package/dist/cjs/router/cli/index.js +31 -22
  32. package/dist/cjs/router/index.js +39 -18
  33. package/dist/cjs/router/runtime/DefaultNotFound.js +26 -11
  34. package/dist/cjs/router/runtime/DeferredDataScripts.js +21 -8
  35. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +47 -34
  36. package/dist/cjs/router/runtime/PrefetchLink.js +81 -47
  37. package/dist/cjs/router/runtime/fetch.js +24 -7
  38. package/dist/cjs/router/runtime/fetch.node.js +25 -8
  39. package/dist/cjs/router/runtime/fetch.worker.js +24 -7
  40. package/dist/cjs/router/runtime/hooks.js +26 -9
  41. package/dist/cjs/router/runtime/index.js +158 -208
  42. package/dist/cjs/router/runtime/plugin.js +62 -46
  43. package/dist/cjs/router/runtime/plugin.node.js +65 -48
  44. package/dist/cjs/router/runtime/server.js +20 -4
  45. package/dist/cjs/router/runtime/shouldRevalidate.js +38 -0
  46. package/dist/cjs/router/runtime/types.js +15 -3
  47. package/dist/cjs/router/runtime/utils.js +61 -48
  48. package/dist/cjs/router/runtime/withRouter.js +30 -15
  49. package/dist/cjs/runtimeContext.js +28 -18
  50. package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +40 -23
  51. package/dist/cjs/ssr/cli/index.js +48 -30
  52. package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +31 -13
  53. package/dist/cjs/ssr/index.js +71 -52
  54. package/dist/cjs/ssr/index.node.js +44 -25
  55. package/dist/cjs/ssr/prefetch.js +29 -16
  56. package/dist/cjs/ssr/react/index.js +27 -17
  57. package/dist/cjs/ssr/react/nossr/index.js +38 -12
  58. package/dist/cjs/ssr/react/prerender/index.js +52 -27
  59. package/dist/cjs/ssr/react/prerender/type.js +15 -3
  60. package/dist/cjs/ssr/react/prerender/util.js +31 -24
  61. package/dist/cjs/ssr/react/withCallback/index.js +27 -11
  62. package/dist/cjs/ssr/serverRender/helmet.js +23 -15
  63. package/dist/cjs/ssr/serverRender/index.js +24 -11
  64. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +30 -13
  65. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.share.js +25 -15
  66. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +46 -20
  67. package/dist/cjs/ssr/serverRender/renderToStream/index.js +49 -23
  68. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +30 -17
  69. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +30 -17
  70. package/dist/cjs/ssr/serverRender/renderToStream/template.js +28 -11
  71. package/dist/cjs/ssr/serverRender/renderToString/buildHtml.js +31 -24
  72. package/dist/cjs/ssr/serverRender/renderToString/entry.js +81 -59
  73. package/dist/cjs/ssr/serverRender/renderToString/index.js +44 -18
  74. package/dist/cjs/ssr/serverRender/renderToString/loadable.js +33 -16
  75. package/dist/cjs/ssr/serverRender/renderToString/render.js +39 -13
  76. package/dist/cjs/ssr/serverRender/renderToString/styledComponent.js +28 -11
  77. package/dist/cjs/ssr/serverRender/renderToString/type.js +24 -7
  78. package/dist/cjs/ssr/serverRender/tracker.js +27 -18
  79. package/dist/cjs/ssr/serverRender/types.js +25 -8
  80. package/dist/cjs/ssr/serverRender/utils.js +31 -24
  81. package/dist/cjs/ssr/utils.js +42 -25
  82. package/dist/cjs/state/cli/index.js +28 -19
  83. package/dist/cjs/state/index.js +39 -18
  84. package/dist/cjs/state/plugins.js +46 -29
  85. package/dist/cjs/state/runtime/index.js +39 -11
  86. package/dist/cjs/state/runtime/plugin.js +55 -28
  87. package/dist/esm/cli/index.js +6 -2
  88. package/dist/esm/common.js +8 -3
  89. package/dist/esm/config.js +0 -1
  90. package/dist/esm/core/appConfig.js +6 -2
  91. package/dist/esm/core/compatible.js +20 -15
  92. package/dist/esm/core/index.js +13 -3
  93. package/dist/esm/core/loader/index.js +4 -1
  94. package/dist/esm/core/loader/loaderManager.js +13 -9
  95. package/dist/esm/core/loader/useLoader.js +5 -2
  96. package/dist/esm/core/plugin.js +15 -10
  97. package/dist/esm/core/types.js +0 -1
  98. package/dist/esm/document/Body.js +4 -1
  99. package/dist/esm/document/Comment.js +4 -1
  100. package/dist/esm/document/DocumentContext.js +4 -1
  101. package/dist/esm/document/DocumentStructureContext.js +4 -1
  102. package/dist/esm/document/Head.js +6 -2
  103. package/dist/esm/document/Html.js +9 -6
  104. package/dist/esm/document/Links.js +4 -1
  105. package/dist/esm/document/Root.js +6 -2
  106. package/dist/esm/document/Script.js +4 -1
  107. package/dist/esm/document/Scripts.js +4 -1
  108. package/dist/esm/document/Style.js +4 -1
  109. package/dist/esm/document/cli/index.js +14 -9
  110. package/dist/esm/document/constants.js +42 -20
  111. package/dist/esm/exports/head.js +4 -1
  112. package/dist/esm/exports/loadable.js +4 -1
  113. package/dist/esm/exports/server.js +4 -1
  114. package/dist/esm/exports/styled.js +4 -1
  115. package/dist/esm/index.js +13 -2
  116. package/dist/esm/router/cli/index.js +11 -7
  117. package/dist/esm/router/index.js +6 -2
  118. package/dist/esm/router/runtime/DefaultNotFound.js +4 -1
  119. package/dist/esm/router/runtime/DeferredDataScripts.js +4 -1
  120. package/dist/esm/router/runtime/DeferredDataScripts.node.js +10 -7
  121. package/dist/esm/router/runtime/PrefetchLink.js +31 -11
  122. package/dist/esm/router/runtime/fetch.js +3 -1
  123. package/dist/esm/router/runtime/fetch.node.js +3 -1
  124. package/dist/esm/router/runtime/fetch.worker.js +3 -1
  125. package/dist/esm/router/runtime/hooks.js +3 -1
  126. package/dist/esm/router/runtime/index.js +72 -6
  127. package/dist/esm/router/runtime/plugin.js +22 -16
  128. package/dist/esm/router/runtime/plugin.node.js +20 -15
  129. package/dist/esm/router/runtime/shouldRevalidate.js +14 -0
  130. package/dist/esm/router/runtime/types.js +0 -1
  131. package/dist/esm/router/runtime/utils.js +23 -14
  132. package/dist/esm/router/runtime/withRouter.js +7 -4
  133. package/dist/esm/runtimeContext.js +6 -2
  134. package/dist/esm/ssr/cli/babel-plugin-ssr-loader-id.js +107 -98
  135. package/dist/esm/ssr/cli/index.js +17 -13
  136. package/dist/esm/ssr/cli/loadable-bundler-plugin.js +105 -96
  137. package/dist/esm/ssr/index.js +18 -14
  138. package/dist/esm/ssr/index.node.js +14 -10
  139. package/dist/esm/ssr/prefetch.js +7 -4
  140. package/dist/esm/ssr/react/index.js +6 -2
  141. package/dist/esm/ssr/react/nossr/index.js +4 -1
  142. package/dist/esm/ssr/react/prerender/index.js +4 -1
  143. package/dist/esm/ssr/react/prerender/type.js +0 -1
  144. package/dist/esm/ssr/react/prerender/util.js +12 -5
  145. package/dist/esm/ssr/react/withCallback/index.js +4 -1
  146. package/dist/esm/ssr/serverRender/helmet.js +4 -1
  147. package/dist/esm/ssr/serverRender/index.js +4 -1
  148. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -4
  149. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.share.js +6 -2
  150. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -1
  151. package/dist/esm/ssr/serverRender/renderToStream/index.js +4 -1
  152. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +4 -1
  153. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -1
  154. package/dist/esm/ssr/serverRender/renderToStream/template.js +6 -3
  155. package/dist/esm/ssr/serverRender/renderToString/buildHtml.js +12 -5
  156. package/dist/esm/ssr/serverRender/renderToString/entry.js +5 -3
  157. package/dist/esm/ssr/serverRender/renderToString/index.js +6 -3
  158. package/dist/esm/ssr/serverRender/renderToString/loadable.js +5 -2
  159. package/dist/esm/ssr/serverRender/renderToString/render.js +4 -1
  160. package/dist/esm/ssr/serverRender/renderToString/styledComponent.js +4 -1
  161. package/dist/esm/ssr/serverRender/renderToString/type.js +4 -1
  162. package/dist/esm/ssr/serverRender/tracker.js +8 -3
  163. package/dist/esm/ssr/serverRender/types.js +3 -1
  164. package/dist/esm/ssr/serverRender/utils.js +12 -5
  165. package/dist/esm/ssr/utils.js +13 -7
  166. package/dist/esm/state/cli/index.js +10 -6
  167. package/dist/esm/state/index.js +6 -2
  168. package/dist/esm/state/plugins.js +10 -4
  169. package/dist/esm/state/runtime/index.js +4 -1
  170. package/dist/esm/state/runtime/plugin.js +10 -7
  171. package/dist/esm-node/cli/index.js +6 -2
  172. package/dist/esm-node/common.js +8 -3
  173. package/dist/esm-node/config.js +0 -1
  174. package/dist/esm-node/core/appConfig.js +6 -2
  175. package/dist/esm-node/core/compatible.js +8 -3
  176. package/dist/esm-node/core/index.js +13 -3
  177. package/dist/esm-node/core/loader/index.js +4 -1
  178. package/dist/esm-node/core/loader/loaderManager.js +6 -2
  179. package/dist/esm-node/core/loader/useLoader.js +4 -1
  180. package/dist/esm-node/core/plugin.js +9 -4
  181. package/dist/esm-node/core/types.js +0 -1
  182. package/dist/esm-node/document/Body.js +4 -1
  183. package/dist/esm-node/document/Comment.js +4 -1
  184. package/dist/esm-node/document/DocumentContext.js +4 -1
  185. package/dist/esm-node/document/DocumentStructureContext.js +4 -1
  186. package/dist/esm-node/document/Head.js +6 -2
  187. package/dist/esm-node/document/Html.js +4 -1
  188. package/dist/esm-node/document/Links.js +4 -1
  189. package/dist/esm-node/document/Root.js +6 -2
  190. package/dist/esm-node/document/Script.js +4 -1
  191. package/dist/esm-node/document/Scripts.js +4 -1
  192. package/dist/esm-node/document/Style.js +4 -1
  193. package/dist/esm-node/document/cli/index.js +8 -3
  194. package/dist/esm-node/document/constants.js +42 -20
  195. package/dist/esm-node/exports/head.js +4 -1
  196. package/dist/esm-node/exports/loadable.js +4 -1
  197. package/dist/esm-node/exports/server.js +4 -1
  198. package/dist/esm-node/exports/styled.js +4 -1
  199. package/dist/esm-node/index.js +13 -2
  200. package/dist/esm-node/router/cli/index.js +6 -2
  201. package/dist/esm-node/router/index.js +6 -2
  202. package/dist/esm-node/router/runtime/DefaultNotFound.js +4 -1
  203. package/dist/esm-node/router/runtime/DeferredDataScripts.js +4 -1
  204. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +4 -1
  205. package/dist/esm-node/router/runtime/PrefetchLink.js +27 -7
  206. package/dist/esm-node/router/runtime/fetch.js +3 -1
  207. package/dist/esm-node/router/runtime/fetch.node.js +3 -1
  208. package/dist/esm-node/router/runtime/fetch.worker.js +3 -1
  209. package/dist/esm-node/router/runtime/hooks.js +3 -1
  210. package/dist/esm-node/router/runtime/index.js +72 -6
  211. package/dist/esm-node/router/runtime/plugin.js +10 -4
  212. package/dist/esm-node/router/runtime/plugin.node.js +8 -3
  213. package/dist/esm-node/router/runtime/shouldRevalidate.js +14 -0
  214. package/dist/esm-node/router/runtime/types.js +0 -1
  215. package/dist/esm-node/router/runtime/utils.js +16 -7
  216. package/dist/esm-node/router/runtime/withRouter.js +4 -1
  217. package/dist/esm-node/runtimeContext.js +6 -2
  218. package/dist/esm-node/ssr/cli/babel-plugin-ssr-loader-id.js +108 -99
  219. package/dist/esm-node/ssr/cli/index.js +6 -2
  220. package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +92 -83
  221. package/dist/esm-node/ssr/index.js +6 -2
  222. package/dist/esm-node/ssr/index.node.js +6 -2
  223. package/dist/esm-node/ssr/prefetch.js +4 -1
  224. package/dist/esm-node/ssr/react/index.js +6 -2
  225. package/dist/esm-node/ssr/react/nossr/index.js +4 -1
  226. package/dist/esm-node/ssr/react/prerender/index.js +4 -1
  227. package/dist/esm-node/ssr/react/prerender/type.js +0 -1
  228. package/dist/esm-node/ssr/react/prerender/util.js +12 -5
  229. package/dist/esm-node/ssr/react/withCallback/index.js +4 -1
  230. package/dist/esm-node/ssr/serverRender/helmet.js +4 -1
  231. package/dist/esm-node/ssr/serverRender/index.js +4 -1
  232. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +4 -1
  233. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.share.js +6 -2
  234. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -1
  235. package/dist/esm-node/ssr/serverRender/renderToStream/index.js +4 -1
  236. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +4 -1
  237. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -1
  238. package/dist/esm-node/ssr/serverRender/renderToStream/template.js +4 -1
  239. package/dist/esm-node/ssr/serverRender/renderToString/buildHtml.js +12 -5
  240. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +3 -1
  241. package/dist/esm-node/ssr/serverRender/renderToString/index.js +4 -1
  242. package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +4 -1
  243. package/dist/esm-node/ssr/serverRender/renderToString/render.js +4 -1
  244. package/dist/esm-node/ssr/serverRender/renderToString/styledComponent.js +4 -1
  245. package/dist/esm-node/ssr/serverRender/renderToString/type.js +4 -1
  246. package/dist/esm-node/ssr/serverRender/tracker.js +8 -3
  247. package/dist/esm-node/ssr/serverRender/types.js +3 -1
  248. package/dist/esm-node/ssr/serverRender/utils.js +12 -5
  249. package/dist/esm-node/ssr/utils.js +10 -4
  250. package/dist/esm-node/state/cli/index.js +6 -2
  251. package/dist/esm-node/state/index.js +6 -2
  252. package/dist/esm-node/state/plugins.js +10 -4
  253. package/dist/esm-node/state/runtime/index.js +4 -1
  254. package/dist/esm-node/state/runtime/plugin.js +4 -1
  255. package/dist/types/router/runtime/index.d.ts +1 -0
  256. package/dist/types/router/runtime/shouldRevalidate.d.ts +2 -0
  257. package/package.json +10 -12
  258. package/dist/cjs/state/types.js +0 -4
  259. package/dist/esm/state/types.js +0 -1
  260. package/dist/esm-node/state/types.js +0 -1
  261. package/dist/types/state/types.d.ts +0 -16
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import React, { useContext, useMemo } from "react";
3
3
  import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches, NavLink as RouterNavLink } from "@modern-js/runtime-utils/router";
4
4
  import { RuntimeReactContext } from "../../core";
5
- export function composeEventHandlers(theirHandler, ourHandler) {
5
+ function composeEventHandlers(theirHandler, ourHandler) {
6
6
  return (event) => {
7
7
  theirHandler === null || theirHandler === void 0 ? void 0 : theirHandler(event);
8
8
  if (!event.defaultPrevented) {
@@ -98,7 +98,8 @@ const getDataHref = (route, pathname, basename) => {
98
98
  const url = getRequestUrl(path, id);
99
99
  return createDataHref(url.toString());
100
100
  };
101
- const PrefetchPageLinks = ({ pathname }) => {
101
+ const PrefetchPageLinks = ({ path }) => {
102
+ const { pathname } = path;
102
103
  const context = useContext(RuntimeReactContext);
103
104
  const { routeManifest, routes } = context;
104
105
  const { routeAssets } = routeManifest || {};
@@ -111,11 +112,12 @@ const PrefetchPageLinks = ({ pathname }) => {
111
112
  }
112
113
  return /* @__PURE__ */ _jsx(PrefetchDataLinks, {
113
114
  matches,
114
- pathname,
115
+ path,
115
116
  routeManifest
116
117
  });
117
118
  };
118
- const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
119
+ const PrefetchDataLinks = ({ matches, path, routeManifest }) => {
120
+ const { pathname, search, hash } = path;
119
121
  const currentMatches = useMatches();
120
122
  const basename = useHref("/");
121
123
  const dataHrefs = useMemo(() => {
@@ -123,6 +125,21 @@ const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
123
125
  if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
124
126
  return false;
125
127
  }
128
+ if (match.route.shouldRevalidate) {
129
+ var _currentMatches_;
130
+ const currentUrl = new URL(location.pathname + location.search + location.hash, window.origin);
131
+ const nextUrl = new URL(pathname + search + hash, window.origin);
132
+ const shouldLoad = match.route.shouldRevalidate({
133
+ currentUrl,
134
+ currentParams: ((_currentMatches_ = currentMatches[0]) === null || _currentMatches_ === void 0 ? void 0 : _currentMatches_.params) || {},
135
+ nextUrl,
136
+ nextParams: match.params,
137
+ defaultShouldRevalidate: true
138
+ });
139
+ if (typeof shouldLoad === "boolean") {
140
+ return shouldLoad;
141
+ }
142
+ }
126
143
  const currentMatch = currentMatches[index];
127
144
  if (!currentMatch || currentMatch.id !== match.route.id) {
128
145
  return true;
@@ -149,7 +166,6 @@ const createPrefetchLink = (Link2) => {
149
166
  const isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
150
167
  const [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior(prefetch, props);
151
168
  const resolvedPath = useResolvedPath(to);
152
- const { pathname } = resolvedPath;
153
169
  return /* @__PURE__ */ _jsxs(_Fragment, {
154
170
  children: [
155
171
  /* @__PURE__ */ _jsx(Link2, {
@@ -159,7 +175,7 @@ const createPrefetchLink = (Link2) => {
159
175
  ...prefetchHandlers
160
176
  }),
161
177
  shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /* @__PURE__ */ _jsx(PrefetchPageLinks, {
162
- pathname
178
+ path: resolvedPath
163
179
  }) : null
164
180
  ]
165
181
  });
@@ -169,4 +185,8 @@ const Link = createPrefetchLink(RouterLink);
169
185
  Link.displayName = "Link";
170
186
  const NavLink = createPrefetchLink(RouterNavLink);
171
187
  NavLink.displayName = "NavLink";
172
- export { Link, NavLink };
188
+ export {
189
+ Link,
190
+ NavLink,
191
+ composeEventHandlers
192
+ };
@@ -1,3 +1,5 @@
1
1
  function installGlobals() {
2
2
  }
3
- export { installGlobals };
3
+ export {
4
+ installGlobals
5
+ };
@@ -1,2 +1,4 @@
1
1
  import { installGlobals } from "@remix-run/node";
2
- export { installGlobals };
2
+ export {
3
+ installGlobals
4
+ };
@@ -1,3 +1,5 @@
1
1
  function installGlobals() {
2
2
  }
3
- export { installGlobals };
3
+ export {
4
+ installGlobals
5
+ };
@@ -1,3 +1,5 @@
1
1
  import { createWaterfall } from "@modern-js/plugin";
2
2
  const modifyRoutes = createWaterfall();
3
- export { modifyRoutes };
3
+ export {
4
+ modifyRoutes
5
+ };
@@ -1,15 +1,16 @@
1
1
  import { useRouteLoaderData as useRouteData } from "@modern-js/runtime-utils/router";
2
2
  import { routerPlugin } from "./plugin";
3
- export { renderRoutes } from "./utils";
4
- export default routerPlugin;
5
- export { modifyRoutes } from "./plugin";
3
+ import { renderRoutes } from "./utils";
4
+ var runtime_default = routerPlugin;
5
+ import { modifyRoutes } from "./plugin";
6
6
  export * from "./withRouter";
7
- export { Link, NavLink } from "./PrefetchLink";
8
- export const useRouteLoaderData = (routeId) => {
7
+ import { Link, NavLink } from "./PrefetchLink";
8
+ const useRouteLoaderData = (routeId) => {
9
9
  const realRouteId = routeId.replace(/\[(.*?)\]/g, "($1)");
10
10
  return useRouteData(realRouteId);
11
11
  };
12
- export {
12
+ import { createShouldRevalidate } from "./shouldRevalidate";
13
+ import {
13
14
  createBrowserRouter,
14
15
  createHashRouter,
15
16
  createMemoryRouter,
@@ -67,3 +68,68 @@ export {
67
68
  json,
68
69
  redirect
69
70
  } from "@modern-js/runtime-utils/router";
71
+ export {
72
+ Await,
73
+ BrowserRouter,
74
+ Form,
75
+ HashRouter,
76
+ Link,
77
+ MemoryRouter,
78
+ NavLink,
79
+ Navigate,
80
+ Outlet,
81
+ Route,
82
+ Router,
83
+ RouterProvider,
84
+ Routes,
85
+ ScrollRestoration,
86
+ createBrowserRouter,
87
+ createHashRouter,
88
+ createMemoryRouter,
89
+ createPath,
90
+ createRoutesFromChildren,
91
+ createRoutesFromElements,
92
+ createSearchParams,
93
+ createShouldRevalidate,
94
+ runtime_default as default,
95
+ defer,
96
+ generatePath,
97
+ isRouteErrorResponse,
98
+ json,
99
+ matchPath,
100
+ matchRoutes,
101
+ modifyRoutes,
102
+ redirect,
103
+ renderMatches,
104
+ renderRoutes,
105
+ resolvePath,
106
+ unstable_useBlocker,
107
+ unstable_usePrompt,
108
+ useActionData,
109
+ useAsyncError,
110
+ useAsyncValue,
111
+ useBeforeUnload,
112
+ useFetcher,
113
+ useFetchers,
114
+ useFormAction,
115
+ useHref,
116
+ useInRouterContext,
117
+ useLinkClickHandler,
118
+ useLoaderData,
119
+ useLocation,
120
+ useMatch,
121
+ useMatches,
122
+ useNavigate,
123
+ useNavigation,
124
+ useNavigationType,
125
+ useOutlet,
126
+ useOutletContext,
127
+ useParams,
128
+ useResolvedPath,
129
+ useRevalidator,
130
+ useRouteError,
131
+ useRouteLoaderData,
132
+ useRoutes,
133
+ useSearchParams,
134
+ useSubmit
135
+ };
@@ -6,11 +6,11 @@ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
6
6
  import { RuntimeReactContext } from "../../core";
7
7
  import { modifyRoutes as modifyRoutesHook } from "./hooks";
8
8
  import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
9
- export let finalRouteConfig = {
9
+ let finalRouteConfig = {
10
10
  routes: []
11
11
  };
12
- export let beforeCreateRouter = true;
13
- export function modifyRoutes(modifyFunction) {
12
+ let beforeCreateRouter = true;
13
+ function modifyRoutes(modifyFunction) {
14
14
  if (beforeCreateRouter) {
15
15
  const { routes: originRoutes } = finalRouteConfig;
16
16
  const newRoutes = modifyFunction(originRoutes);
@@ -19,7 +19,7 @@ export function modifyRoutes(modifyFunction) {
19
19
  console.error("It is not allowed to modify routes config after create router.");
20
20
  }
21
21
  }
22
- export const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes }) => {
22
+ const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes }) => {
23
23
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
24
24
  let routes = [];
25
25
  finalRouteConfig = routesConfig;
@@ -155,3 +155,9 @@ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, base
155
155
  }
156
156
  };
157
157
  };
158
+ export {
159
+ beforeCreateRouter,
160
+ finalRouteConfig,
161
+ modifyRoutes,
162
+ routerPlugin
163
+ };
@@ -23,7 +23,7 @@ function createFetchRequest(req) {
23
23
  };
24
24
  return new Request(url.href, init);
25
25
  }
26
- export function createFetchHeaders(requestHeaders) {
26
+ function createFetchHeaders(requestHeaders) {
27
27
  const headers = new Headers();
28
28
  for (const [key, values] of Object.entries(requestHeaders || {})) {
29
29
  if (values) {
@@ -38,7 +38,7 @@ export function createFetchHeaders(requestHeaders) {
38
38
  }
39
39
  return headers;
40
40
  }
41
- export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
41
+ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
42
42
  return {
43
43
  name: "@modern-js/plugin-router",
44
44
  registerHook: {
@@ -146,5 +146,10 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
146
146
  }
147
147
  };
148
148
  };
149
- export const modifyRoutes = () => {
149
+ const modifyRoutes = () => {
150
+ };
151
+ export {
152
+ createFetchHeaders,
153
+ modifyRoutes,
154
+ routerPlugin
150
155
  };
@@ -0,0 +1,14 @@
1
+ import { ROUTE_MODULES } from "@modern-js/utils/universal/constants";
2
+ const createShouldRevalidate = (routeId) => {
3
+ return (arg) => {
4
+ var _window_ROUTE_MODULES, _window;
5
+ const routeModule = (_window = window) === null || _window === void 0 ? void 0 : (_window_ROUTE_MODULES = _window[ROUTE_MODULES]) === null || _window_ROUTE_MODULES === void 0 ? void 0 : _window_ROUTE_MODULES[routeId];
6
+ if (routeModule && typeof routeModule.shouldRevalidate === "function") {
7
+ return routeModule.shouldRevalidate(arg);
8
+ }
9
+ return arg.defaultShouldRevalidate;
10
+ };
11
+ };
12
+ export {
13
+ createShouldRevalidate
14
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -4,7 +4,7 @@ import { ErrorResponse } from "@modern-js/runtime-utils/remix-router";
4
4
  import { renderNestedRoute } from "@modern-js/runtime-utils/browser";
5
5
  import { DefaultNotFound } from "./DefaultNotFound";
6
6
  import DeferredDataScripts from "./DeferredDataScripts";
7
- export function getRouteComponents(routes, { globalApp, ssrMode, props, reporter }) {
7
+ function getRouteComponents(routes, { globalApp, ssrMode, props, reporter }) {
8
8
  const Layout = ({ Component, ...props2 }) => {
9
9
  const GlobalLayout = globalApp;
10
10
  if (!GlobalLayout) {
@@ -42,7 +42,7 @@ export function getRouteComponents(routes, { globalApp, ssrMode, props, reporter
42
42
  }, "*"));
43
43
  return routeElements;
44
44
  }
45
- export function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
45
+ function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
46
46
  if (!routesConfig) {
47
47
  return null;
48
48
  }
@@ -58,7 +58,7 @@ export function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
58
58
  });
59
59
  return routeElements;
60
60
  }
61
- export function getLocation(serverContext) {
61
+ function getLocation(serverContext) {
62
62
  var _url_replace;
63
63
  const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
64
64
  const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
@@ -68,12 +68,12 @@ export function getLocation(serverContext) {
68
68
  }
69
69
  return cleanUrl.substring(index);
70
70
  }
71
- export const urlJoin = (...parts) => {
71
+ const urlJoin = (...parts) => {
72
72
  const separator = "/";
73
73
  const replace = new RegExp(`${separator}{1,}`, "g");
74
74
  return standardSlash(parts.join(separator).replace(replace, separator));
75
75
  };
76
- export function standardSlash(str) {
76
+ function standardSlash(str) {
77
77
  let addr = str;
78
78
  if (!addr || typeof addr !== "string") {
79
79
  return addr;
@@ -89,7 +89,7 @@ export function standardSlash(str) {
89
89
  }
90
90
  return addr;
91
91
  }
92
- export function serializeErrors(errors) {
92
+ function serializeErrors(errors) {
93
93
  if (!errors) {
94
94
  return null;
95
95
  }
@@ -113,7 +113,7 @@ export function serializeErrors(errors) {
113
113
  }
114
114
  return serialized;
115
115
  }
116
- export function deserializeErrors(errors) {
116
+ function deserializeErrors(errors) {
117
117
  if (!errors) {
118
118
  return null;
119
119
  }
@@ -132,3 +132,12 @@ export function deserializeErrors(errors) {
132
132
  }
133
133
  return serialized;
134
134
  }
135
+ export {
136
+ deserializeErrors,
137
+ getLocation,
138
+ getRouteComponents,
139
+ renderRoutes,
140
+ serializeErrors,
141
+ standardSlash,
142
+ urlJoin
143
+ };
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useLocation, useNavigate, useParams } from "@modern-js/runtime-utils/router";
3
- export const withRouter = (Component) => {
3
+ const withRouter = (Component) => {
4
4
  return (props) => {
5
5
  const location = useLocation();
6
6
  const params = useParams();
@@ -13,3 +13,6 @@ export const withRouter = (Component) => {
13
13
  });
14
14
  };
15
15
  };
16
+ export {
17
+ withRouter
18
+ };
@@ -1,3 +1,7 @@
1
1
  import { createContext } from "react";
2
- export const RuntimeReactContext = createContext({});
3
- export const ServerRouterContext = createContext({});
2
+ const RuntimeReactContext = createContext({});
3
+ const ServerRouterContext = createContext({});
4
+ export {
5
+ RuntimeReactContext,
6
+ ServerRouterContext
7
+ };
@@ -1,110 +1,119 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
1
5
  import crypto from "crypto";
2
- import { Buffer } from "buffer";
6
+ import { Buffer as Buffer2 } from "buffer";
3
7
  import * as t from "@babel/types";
4
8
  import { get } from "@modern-js/utils/lodash";
5
- const RUNTIME_PACKAGE_NAMES = [
6
- "@modern-js/runtime"
7
- ];
8
- const FUNCTION_USE_LOADER_NAME = "useLoader";
9
- function getHash(filepath) {
10
- const cwd = process.cwd();
11
- const point = filepath.indexOf(cwd);
12
- let relativePath = filepath;
13
- if (point !== -1) {
14
- relativePath = filepath.substring(point + cwd.length);
15
- }
16
- const fileBuf = Buffer.from(relativePath);
17
- const fsHash = crypto.createHash("md5");
18
- const md5 = fsHash.update(fileBuf).digest("hex");
19
- return md5;
20
- }
21
- function getUseLoaderPath(path, calleeName) {
22
- const { node } = path;
23
- if (!calleeName || node.callee.name !== calleeName) {
24
- return false;
25
- }
26
- const arg1 = get(node, "arguments.0");
27
- if (t.isFunction(arg1) || t.isFunctionExpression(arg1) || t.isArrowFunctionExpression(arg1) || t.isIdentifier(arg1) || t.isCallExpression(arg1) || t.isMemberExpression(arg1)) {
28
- const loaderPath = path.get("arguments.0");
29
- if (isDuplicateInnerLoader(loaderPath)) {
30
- return false;
31
- } else {
32
- return loaderPath;
33
- }
34
- }
35
- console.warn("useLoader 中 loaderId 生成失败,请检查 useLoader");
36
- throw path.buildCodeFrameError(`
37
- please check the usage of ${path.node.name}
38
- `);
39
- }
40
- function isDuplicateInnerLoader(path) {
41
- const { node } = path;
42
- if (t.isFunctionExpression(node.callee)) {
43
- if (t.isBlockStatement(node.callee.body)) {
44
- if (get(node.callee.body, "body.0.declarations.0.id.name") === "innerLoader" && get(node.callee.body, "body.2.argument.name") === "innerLoader") {
45
- return true;
9
+ var require_babel_plugin_ssr_loader_id = __commonJS({
10
+ "src/ssr/cli/babel-plugin-ssr-loader-id.ts"(exports, module) {
11
+ const RUNTIME_PACKAGE_NAMES = [
12
+ "@modern-js/runtime"
13
+ ];
14
+ const FUNCTION_USE_LOADER_NAME = "useLoader";
15
+ function getHash(filepath) {
16
+ const cwd = process.cwd();
17
+ const point = filepath.indexOf(cwd);
18
+ let relativePath = filepath;
19
+ if (point !== -1) {
20
+ relativePath = filepath.substring(point + cwd.length);
46
21
  }
22
+ const fileBuf = Buffer2.from(relativePath);
23
+ const fsHash = crypto.createHash("md5");
24
+ const md5 = fsHash.update(fileBuf).digest("hex");
25
+ return md5;
47
26
  }
48
- }
49
- return false;
50
- }
51
- function getSelfRunLoaderExpression(loaderExpression, id) {
52
- return t.callExpression(t.functionExpression(null, [], t.blockStatement([
53
- t.variableDeclaration("var", [
54
- t.variableDeclarator(t.identifier("innerLoader"), loaderExpression)
55
- ]),
56
- t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("innerLoader"), t.identifier("id")), t.stringLiteral(id))),
57
- t.returnStatement(t.identifier("innerLoader"))
58
- ])), []);
59
- }
60
- module.exports = function() {
61
- let useLoader = null;
62
- let hash = "";
63
- let index = 0;
64
- function genId() {
65
- return `${hash}_${index++}`;
66
- }
67
- return {
68
- name: "babel-plugin-ssr-loader-id",
69
- pre() {
70
- index = 0;
71
- useLoader = null;
72
- hash = "";
73
- },
74
- visitor: {
75
- ImportDeclaration(path, state) {
76
- if (useLoader) {
77
- return false;
78
- }
79
- if (!RUNTIME_PACKAGE_NAMES.includes(get(path, "node.source.value"))) {
27
+ function getUseLoaderPath(path, calleeName) {
28
+ const { node } = path;
29
+ if (!calleeName || node.callee.name !== calleeName) {
30
+ return false;
31
+ }
32
+ const arg1 = get(node, "arguments.0");
33
+ if (t.isFunction(arg1) || t.isFunctionExpression(arg1) || t.isArrowFunctionExpression(arg1) || t.isIdentifier(arg1) || t.isCallExpression(arg1) || t.isMemberExpression(arg1)) {
34
+ const loaderPath = path.get("arguments.0");
35
+ if (isDuplicateInnerLoader(loaderPath)) {
80
36
  return false;
37
+ } else {
38
+ return loaderPath;
81
39
  }
82
- hash = getHash(state.file.opts.filename);
83
- get(path, "node.specifiers", []).forEach(({ imported, local }) => {
84
- if (!imported) {
85
- throw path.buildCodeFrameError(`please \`import { useLoader } from ${RUNTIME_PACKAGE_NAMES[0]}\``);
86
- }
87
- if (!useLoader && imported.name === FUNCTION_USE_LOADER_NAME) {
88
- useLoader = local.name;
89
- }
90
- });
91
- return false;
92
- },
93
- CallExpression(path) {
94
- let loaderPath = getUseLoaderPath(path, useLoader);
95
- if (loaderPath) {
96
- if (!Array.isArray(loaderPath)) {
97
- loaderPath = [
98
- loaderPath
99
- ];
40
+ }
41
+ console.warn("useLoader loaderId 生成失败,请检查 useLoader");
42
+ throw path.buildCodeFrameError(`
43
+ please check the usage of ${path.node.name}
44
+ `);
45
+ }
46
+ function isDuplicateInnerLoader(path) {
47
+ const { node } = path;
48
+ if (t.isFunctionExpression(node.callee)) {
49
+ if (t.isBlockStatement(node.callee.body)) {
50
+ if (get(node.callee.body, "body.0.declarations.0.id.name") === "innerLoader" && get(node.callee.body, "body.2.argument.name") === "innerLoader") {
51
+ return true;
100
52
  }
101
- loaderPath.forEach((p) => {
102
- p.replaceWith(getSelfRunLoaderExpression(p.node, genId()));
103
- });
104
- return false;
105
53
  }
106
- return false;
107
54
  }
55
+ return false;
108
56
  }
109
- };
110
- };
57
+ function getSelfRunLoaderExpression(loaderExpression, id) {
58
+ return t.callExpression(t.functionExpression(null, [], t.blockStatement([
59
+ t.variableDeclaration("var", [
60
+ t.variableDeclarator(t.identifier("innerLoader"), loaderExpression)
61
+ ]),
62
+ t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("innerLoader"), t.identifier("id")), t.stringLiteral(id))),
63
+ t.returnStatement(t.identifier("innerLoader"))
64
+ ])), []);
65
+ }
66
+ module.exports = function() {
67
+ let useLoader = null;
68
+ let hash = "";
69
+ let index = 0;
70
+ function genId() {
71
+ return `${hash}_${index++}`;
72
+ }
73
+ return {
74
+ name: "babel-plugin-ssr-loader-id",
75
+ pre() {
76
+ index = 0;
77
+ useLoader = null;
78
+ hash = "";
79
+ },
80
+ visitor: {
81
+ ImportDeclaration(path, state) {
82
+ if (useLoader) {
83
+ return false;
84
+ }
85
+ if (!RUNTIME_PACKAGE_NAMES.includes(get(path, "node.source.value"))) {
86
+ return false;
87
+ }
88
+ hash = getHash(state.file.opts.filename);
89
+ get(path, "node.specifiers", []).forEach(({ imported, local }) => {
90
+ if (!imported) {
91
+ throw path.buildCodeFrameError(`please \`import { useLoader } from ${RUNTIME_PACKAGE_NAMES[0]}\``);
92
+ }
93
+ if (!useLoader && imported.name === FUNCTION_USE_LOADER_NAME) {
94
+ useLoader = local.name;
95
+ }
96
+ });
97
+ return false;
98
+ },
99
+ CallExpression(path) {
100
+ let loaderPath = getUseLoaderPath(path, useLoader);
101
+ if (loaderPath) {
102
+ if (!Array.isArray(loaderPath)) {
103
+ loaderPath = [
104
+ loaderPath
105
+ ];
106
+ }
107
+ loaderPath.forEach((p) => {
108
+ p.replaceWith(getSelfRunLoaderExpression(p.node, genId()));
109
+ });
110
+ return false;
111
+ }
112
+ return false;
113
+ }
114
+ }
115
+ };
116
+ };
117
+ }
118
+ });
119
+ export default require_babel_plugin_ssr_loader_id();
@@ -20,7 +20,7 @@ const checkUseStringSSR = (config) => {
20
20
  const { output } = config;
21
21
  return Boolean(output === null || output === void 0 ? void 0 : output.ssg) || hasStringSSREntry(config);
22
22
  };
23
- export const ssrPlugin = () => ({
23
+ const ssrPlugin = () => ({
24
24
  name: "@modern-js/plugin-ssr",
25
25
  required: [
26
26
  "@modern-js/runtime"
@@ -161,4 +161,8 @@ export const ssrPlugin = () => ({
161
161
  };
162
162
  }
163
163
  });
164
- export default ssrPlugin;
164
+ var cli_default = ssrPlugin;
165
+ export {
166
+ cli_default as default,
167
+ ssrPlugin
168
+ };