vite-react-ssg 0.8.1 → 0.8.3-beta.1

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 (33) hide show
  1. package/README.md +28 -0
  2. package/dist/client/single-page.cjs +5 -14
  3. package/dist/client/single-page.d.cts +2 -2
  4. package/dist/client/single-page.d.mts +2 -2
  5. package/dist/client/single-page.d.ts +2 -2
  6. package/dist/client/single-page.mjs +9 -14
  7. package/dist/index.cjs +11 -12
  8. package/dist/index.d.cts +2 -2
  9. package/dist/index.d.mts +2 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.mjs +15 -16
  12. package/dist/node/cli.cjs +1 -1
  13. package/dist/node/cli.mjs +1 -1
  14. package/dist/node.cjs +1 -1
  15. package/dist/node.d.cts +1 -1
  16. package/dist/node.d.mts +1 -1
  17. package/dist/node.d.ts +1 -1
  18. package/dist/node.mjs +1 -1
  19. package/dist/shared/vite-react-ssg.C2Pi5cFR.mjs +79 -0
  20. package/dist/shared/vite-react-ssg.CRjwV0we.cjs +102 -0
  21. package/dist/shared/{vite-react-ssg.BdRX-qCI.mjs → vite-react-ssg.DPcqaaWL.mjs} +12 -7
  22. package/dist/shared/{vite-react-ssg.MPbH7GTN.d.ts → vite-react-ssg.Di0pROyF.d.cts} +11 -3
  23. package/dist/shared/{vite-react-ssg.MPbH7GTN.d.cts → vite-react-ssg.Di0pROyF.d.mts} +11 -3
  24. package/dist/shared/{vite-react-ssg.MPbH7GTN.d.mts → vite-react-ssg.Di0pROyF.d.ts} +11 -3
  25. package/dist/shared/{vite-react-ssg.U7W0lHXm.cjs → vite-react-ssg.LHioe_9y.cjs} +25 -7
  26. package/dist/tanstack.cjs +13 -19
  27. package/dist/tanstack.d.cts +2 -2
  28. package/dist/tanstack.d.mts +2 -2
  29. package/dist/tanstack.d.ts +2 -2
  30. package/dist/tanstack.mjs +19 -21
  31. package/package.json +4 -4
  32. package/dist/shared/vite-react-ssg.DdDMKzrS.mjs +0 -43
  33. package/dist/shared/vite-react-ssg.yL7u7OP5.cjs +0 -47
package/README.md CHANGED
@@ -374,6 +374,29 @@ See: [react-router's create-browser-router](https://reactrouter.com/en/main/rout
374
374
 
375
375
  [Example](./examples/lazy-pages/vite.config.ts)
376
376
 
377
+ ## Future config
378
+
379
+ ```tsx
380
+ export const createRoot = ViteReactSSG(
381
+ {
382
+ routes,
383
+ basename: import.meta.env.BASE_URL,
384
+ future: {
385
+ v7_normalizeFormMethod: true,
386
+ v7_startTransition: true,
387
+ v7_fetcherPersist: true,
388
+ v7_relativeSplatPath: true,
389
+ v7_skipActionErrorRevalidation: true,
390
+ v7_partialHydration: true,
391
+ },
392
+ },
393
+ )
394
+ ```
395
+
396
+ See: [react-router's optsfuture](https://reactrouter.com/6.28.0/routers/create-browser-router#optsfuture)
397
+
398
+ [Example](./examples/lazy-pages/src/main.tsx)
399
+
377
400
  ## CSS in JS
378
401
 
379
402
  Use the `getStyleCollector` option to specify an SSR/SSG style collector. Currently only supports `styled-components`.
@@ -586,6 +609,11 @@ export default defineConfig({
586
609
  })
587
610
  ```
588
611
 
612
+ ### React17 Support
613
+
614
+ - for react18, with flag `useLegacyRender: true`, it will use the legacy `render` and `hydrate` methods.
615
+ - for react17, on top of above, you will need minor update to react and react-dom [example](https://github.com/jesse23/webpack-test-bed/blob/main/scripts/define-react-exports.js) to polyfill the mjs import and the `react-dom/client`.
616
+
589
617
  ## Roadmap
590
618
 
591
619
  - [x] Preload assets
@@ -1,15 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
- const client = require('react-dom/client');
5
4
  const reactHelmetAsync = require('react-helmet-async');
6
- const React = require('react');
7
- const ClientOnly = require('../shared/vite-react-ssg.yL7u7OP5.cjs');
5
+ const ClientOnly = require('../shared/vite-react-ssg.CRjwV0we.cjs');
8
6
  const state = require('../shared/vite-react-ssg.CjsEygxB.cjs');
9
-
10
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
-
12
- const React__default = /*#__PURE__*/_interopDefaultCompat(React);
7
+ require('react');
8
+ require('react-dom');
13
9
 
14
10
  function ViteReactSSG(App, fn, options = {}) {
15
11
  const {
@@ -65,14 +61,9 @@ function ViteReactSSG(App, fn, options = {}) {
65
61
  const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: App });
66
62
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
67
63
  if (!isSSR && process.env.NODE_ENV === "development") {
68
- const root = client.createRoot(container);
69
- React__default.startTransition(() => {
70
- root.render(app);
71
- });
64
+ ClientOnly.render(app, container, options);
72
65
  } else {
73
- React__default.startTransition(() => {
74
- client.hydrateRoot(container, app);
75
- });
66
+ ClientOnly.hydrate(app, container, options);
76
67
  }
77
68
  })();
78
69
  }
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.cjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.cjs';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Di0pROyF.cjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, d as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Di0pROyF.cjs';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.cjs';
5
5
  import 'react-router-dom';
6
6
  import 'beasties';
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.mjs';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Di0pROyF.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, d as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Di0pROyF.mjs';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.mjs';
5
5
  import 'react-router-dom';
6
6
  import 'beasties';
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.js';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Di0pROyF.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, d as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Di0pROyF.js';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.js';
5
5
  import 'react-router-dom';
6
6
  import 'beasties';
@@ -1,10 +1,10 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { createRoot, hydrateRoot } from 'react-dom/client';
3
2
  import { HelmetProvider } from 'react-helmet-async';
4
- import React from 'react';
5
- import { d as documentReady } from '../shared/vite-react-ssg.DdDMKzrS.mjs';
6
- export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.DdDMKzrS.mjs';
3
+ import { r as render, h as hydrate, d as documentReady } from '../shared/vite-react-ssg.C2Pi5cFR.mjs';
4
+ export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.C2Pi5cFR.mjs';
7
5
  import { d as deserializeState } from '../shared/vite-react-ssg.C6pK7rvr.mjs';
6
+ import 'react';
7
+ import 'react-dom';
8
8
 
9
9
  function ViteReactSSG(App, fn, options = {}) {
10
10
  const {
@@ -16,7 +16,7 @@ function ViteReactSSG(App, fn, options = {}) {
16
16
  if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
17
17
  console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
18
18
  const isClient = typeof window !== "undefined";
19
- async function createRoot$1(client = false, routePath) {
19
+ async function createRoot(client = false, routePath) {
20
20
  const appRenderCallbacks = [];
21
21
  const onSSRAppRendered = client ? () => {
22
22
  } : (cb) => appRenderCallbacks.push(cb);
@@ -56,22 +56,17 @@ function ViteReactSSG(App, fn, options = {}) {
56
56
  console.warn("[vite-react-ssg] Root container not found.");
57
57
  return;
58
58
  }
59
- await createRoot$1(true);
59
+ await createRoot(true);
60
60
  const app = /* @__PURE__ */ jsx(HelmetProvider, { children: App });
61
61
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
62
62
  if (!isSSR && process.env.NODE_ENV === "development") {
63
- const root = createRoot(container);
64
- React.startTransition(() => {
65
- root.render(app);
66
- });
63
+ render(app, container, options);
67
64
  } else {
68
- React.startTransition(() => {
69
- hydrateRoot(container, app);
70
- });
65
+ hydrate(app, container, options);
71
66
  }
72
67
  })();
73
68
  }
74
- return createRoot$1;
69
+ return createRoot;
75
70
  }
76
71
 
77
72
  export { ViteReactSSG };
package/dist/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
- const React = require('react');
5
- const client = require('react-dom/client');
6
4
  const reactHelmetAsync = require('react-helmet-async');
7
5
  const reactRouterDom = require('react-router-dom');
8
- const ClientOnly = require('./shared/vite-react-ssg.yL7u7OP5.cjs');
6
+ const ClientOnly = require('./shared/vite-react-ssg.CRjwV0we.cjs');
9
7
  const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
10
8
  const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
11
9
  const remixRouter = require('./shared/vite-react-ssg.C2GpVZF1.cjs');
10
+ const React = require('react');
11
+ require('react-dom');
12
12
 
13
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
14
 
@@ -88,8 +88,12 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
88
88
  console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
89
89
  const isClient = typeof window !== "undefined";
90
90
  const BASE_URL = routerOptions.basename ?? "/";
91
+ const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {};
91
92
  async function createRoot(client = false, routePath) {
92
- const browserRouter = client ? reactRouterDom.createBrowserRouter(remixRouter.convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute), { basename: BASE_URL }) : void 0;
93
+ const browserRouter = client ? reactRouterDom.createBrowserRouter(
94
+ remixRouter.convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
95
+ { basename: BASE_URL, future: routerFeature }
96
+ ) : void 0;
93
97
  const appRenderCallbacks = [];
94
98
  const onSSRAppRendered = client ? () => {
95
99
  } : (cb) => appRenderCallbacks.push(cb);
@@ -141,17 +145,12 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
141
145
  );
142
146
  }
143
147
  const { router } = await createRoot(true);
144
- const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.RouterProvider, { router }) });
148
+ const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.RouterProvider, { router, future: { v7_startTransition } }) });
145
149
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
146
150
  if (!isSSR && process.env.NODE_ENV === "development") {
147
- const root = client.createRoot(container);
148
- React__default.startTransition(() => {
149
- root.render(app);
150
- });
151
+ ClientOnly.render(app, container, options);
151
152
  } else {
152
- React__default.startTransition(() => {
153
- client.hydrateRoot(container, app);
154
- });
153
+ ClientOnly.hydrate(app, container, options);
155
154
  }
156
155
  })();
157
156
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
1
+ import { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.cjs';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
1
+ import { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.mjs';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.mjs';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.mjs';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
1
+ import { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.js';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.js';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.js';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import React, { forwardRef } from 'react';
3
- import { createRoot, hydrateRoot } from 'react-dom/client';
4
2
  import { HelmetProvider } from 'react-helmet-async';
5
3
  import { useLinkClickHandler, Link as Link$1, NavLink as NavLink$1, matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
6
- import { d as documentReady } from './shared/vite-react-ssg.DdDMKzrS.mjs';
7
- export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DdDMKzrS.mjs';
4
+ import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.C2Pi5cFR.mjs';
5
+ export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.C2Pi5cFR.mjs';
8
6
  import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
9
7
  import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
10
8
  import { c as convertRoutesToDataRoutes } from './shared/vite-react-ssg.C0y5wbxl.mjs';
9
+ import React, { forwardRef } from 'react';
10
+ import 'react-dom';
11
11
 
12
12
  const Link = forwardRef((props, ref) => {
13
13
  const {
@@ -83,8 +83,12 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
83
83
  console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
84
84
  const isClient = typeof window !== "undefined";
85
85
  const BASE_URL = routerOptions.basename ?? "/";
86
- async function createRoot$1(client = false, routePath) {
87
- const browserRouter = client ? createBrowserRouter(convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute), { basename: BASE_URL }) : void 0;
86
+ const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {};
87
+ async function createRoot(client = false, routePath) {
88
+ const browserRouter = client ? createBrowserRouter(
89
+ convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
90
+ { basename: BASE_URL, future: routerFeature }
91
+ ) : void 0;
88
92
  const appRenderCallbacks = [];
89
93
  const onSSRAppRendered = client ? () => {
90
94
  } : (cb) => appRenderCallbacks.push(cb);
@@ -135,22 +139,17 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
135
139
  })
136
140
  );
137
141
  }
138
- const { router } = await createRoot$1(true);
139
- const app = /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) });
142
+ const { router } = await createRoot(true);
143
+ const app = /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router, future: { v7_startTransition } }) });
140
144
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
141
145
  if (!isSSR && process.env.NODE_ENV === "development") {
142
- const root = createRoot(container);
143
- React.startTransition(() => {
144
- root.render(app);
145
- });
146
+ render(app, container, options);
146
147
  } else {
147
- React.startTransition(() => {
148
- hydrateRoot(container, app);
149
- });
148
+ hydrate(app, container, options);
150
149
  }
151
150
  })();
152
151
  }
153
- return createRoot$1;
152
+ return createRoot;
154
153
  function transformStaticLoaderRoute(route) {
155
154
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
156
155
  if (!isSSR) {
package/dist/node/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const kolorist = require('kolorist');
4
4
  const yargs = require('yargs');
5
5
  const helpers = require('yargs/helpers');
6
- const dev = require('../shared/vite-react-ssg.U7W0lHXm.cjs');
6
+ const dev = require('../shared/vite-react-ssg.LHioe_9y.cjs');
7
7
  const webFetch = require('@remix-run/web-fetch');
8
8
  require('node:path');
9
9
  require('node:module');
package/dist/node/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { gray, bold, red, reset, underline } from 'kolorist';
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
- import { b as build, d as dev } from '../shared/vite-react-ssg.BdRX-qCI.mjs';
4
+ import { b as build, d as dev } from '../shared/vite-react-ssg.DPcqaaWL.mjs';
5
5
  import { Headers, Request, Response, fetch, FormData } from '@remix-run/web-fetch';
6
6
  import 'node:path';
7
7
  import 'node:module';
package/dist/node.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const dev = require('./shared/vite-react-ssg.U7W0lHXm.cjs');
3
+ const dev = require('./shared/vite-react-ssg.LHioe_9y.cjs');
4
4
  require('node:path');
5
5
  require('node:module');
6
6
  require('kolorist');
package/dist/node.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
5
  import 'beasties';
package/dist/node.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.mjs';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
5
  import 'beasties';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.js';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
5
  import 'beasties';
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as build, d as dev } from './shared/vite-react-ssg.BdRX-qCI.mjs';
1
+ export { b as build, d as dev } from './shared/vite-react-ssg.DPcqaaWL.mjs';
2
2
  import 'node:path';
3
3
  import 'node:module';
4
4
  import 'kolorist';
@@ -0,0 +1,79 @@
1
+ import React, { useState, useEffect, isValidElement } from 'react';
2
+ import * as ReactDOM from 'react-dom';
3
+ import { jsx, Fragment } from 'react/jsx-runtime';
4
+ import { Helmet } from 'react-helmet-async';
5
+
6
+ const CopyReactDOM = {
7
+ ...ReactDOM
8
+ };
9
+ const { version, render: reactRender, hydrate: reactHydrate } = CopyReactDOM;
10
+ const isReact18 = Number((version || "").split(".")[0]) > 17;
11
+ function render(app, container, renderOptions = {}) {
12
+ const { useLegacyRender } = renderOptions;
13
+ if (useLegacyRender || !isReact18) {
14
+ reactRender(app, container);
15
+ } else {
16
+ const { createRoot } = CopyReactDOM;
17
+ if (!createRoot) {
18
+ throw new Error("createRoot not found");
19
+ }
20
+ const root = createRoot(container);
21
+ React.startTransition(() => {
22
+ root.render(app);
23
+ });
24
+ }
25
+ }
26
+ function hydrate(app, container, renderOptions = {}) {
27
+ const { useLegacyRender } = renderOptions;
28
+ if (useLegacyRender || !isReact18) {
29
+ reactHydrate(app, container);
30
+ } else {
31
+ const { hydrateRoot } = CopyReactDOM;
32
+ if (!hydrateRoot) {
33
+ throw new Error("hydrateRoot not found");
34
+ }
35
+ React.startTransition(() => {
36
+ hydrateRoot(container, app);
37
+ });
38
+ }
39
+ }
40
+
41
+ function documentReady(_passThrough) {
42
+ if (document.readyState === "loading") {
43
+ return new Promise((resolve) => {
44
+ document.addEventListener("DOMContentLoaded", () => resolve(_passThrough));
45
+ });
46
+ }
47
+ return Promise.resolve(_passThrough);
48
+ }
49
+
50
+ function Head(props) {
51
+ return /* @__PURE__ */ jsx(Helmet, { ...props });
52
+ }
53
+
54
+ function useIsClient() {
55
+ const [isBrowser, setIsBrowser] = useState(false);
56
+ useEffect(() => {
57
+ setIsBrowser(true);
58
+ }, []);
59
+ return isBrowser;
60
+ }
61
+
62
+ function ClientOnly({
63
+ children,
64
+ fallback
65
+ }) {
66
+ const isBrowser = useIsClient();
67
+ if (isBrowser) {
68
+ if (typeof children !== "function" && process.env.NODE_ENV === "development") {
69
+ throw new Error(
70
+ `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
71
+ Current type: ${isValidElement(children) ? "React element" : typeof children}`
72
+ );
73
+ }
74
+ return /* @__PURE__ */ jsx(Fragment, { children: children?.() });
75
+ }
76
+ return fallback ?? null;
77
+ }
78
+
79
+ export { ClientOnly as C, Head as H, documentReady as d, hydrate as h, render as r };
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ const React = require('react');
4
+ const ReactDOM = require('react-dom');
5
+ const jsxRuntime = require('react/jsx-runtime');
6
+ const reactHelmetAsync = require('react-helmet-async');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
+
10
+ function _interopNamespaceCompat(e) {
11
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
+ const n = Object.create(null);
13
+ if (e) {
14
+ for (const k in e) {
15
+ n[k] = e[k];
16
+ }
17
+ }
18
+ n.default = e;
19
+ return n;
20
+ }
21
+
22
+ const React__default = /*#__PURE__*/_interopDefaultCompat(React);
23
+ const ReactDOM__namespace = /*#__PURE__*/_interopNamespaceCompat(ReactDOM);
24
+
25
+ const CopyReactDOM = {
26
+ ...ReactDOM__namespace
27
+ };
28
+ const { version, render: reactRender, hydrate: reactHydrate } = CopyReactDOM;
29
+ const isReact18 = Number((version || "").split(".")[0]) > 17;
30
+ function render(app, container, renderOptions = {}) {
31
+ const { useLegacyRender } = renderOptions;
32
+ if (useLegacyRender || !isReact18) {
33
+ reactRender(app, container);
34
+ } else {
35
+ const { createRoot } = CopyReactDOM;
36
+ if (!createRoot) {
37
+ throw new Error("createRoot not found");
38
+ }
39
+ const root = createRoot(container);
40
+ React__default.startTransition(() => {
41
+ root.render(app);
42
+ });
43
+ }
44
+ }
45
+ function hydrate(app, container, renderOptions = {}) {
46
+ const { useLegacyRender } = renderOptions;
47
+ if (useLegacyRender || !isReact18) {
48
+ reactHydrate(app, container);
49
+ } else {
50
+ const { hydrateRoot } = CopyReactDOM;
51
+ if (!hydrateRoot) {
52
+ throw new Error("hydrateRoot not found");
53
+ }
54
+ React__default.startTransition(() => {
55
+ hydrateRoot(container, app);
56
+ });
57
+ }
58
+ }
59
+
60
+ function documentReady(_passThrough) {
61
+ if (document.readyState === "loading") {
62
+ return new Promise((resolve) => {
63
+ document.addEventListener("DOMContentLoaded", () => resolve(_passThrough));
64
+ });
65
+ }
66
+ return Promise.resolve(_passThrough);
67
+ }
68
+
69
+ function Head(props) {
70
+ return /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.Helmet, { ...props });
71
+ }
72
+
73
+ function useIsClient() {
74
+ const [isBrowser, setIsBrowser] = React.useState(false);
75
+ React.useEffect(() => {
76
+ setIsBrowser(true);
77
+ }, []);
78
+ return isBrowser;
79
+ }
80
+
81
+ function ClientOnly({
82
+ children,
83
+ fallback
84
+ }) {
85
+ const isBrowser = useIsClient();
86
+ if (isBrowser) {
87
+ if (typeof children !== "function" && process.env.NODE_ENV === "development") {
88
+ throw new Error(
89
+ `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
90
+ Current type: ${React.isValidElement(children) ? "React element" : typeof children}`
91
+ );
92
+ }
93
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.() });
94
+ }
95
+ return fallback ?? null;
96
+ }
97
+
98
+ exports.ClientOnly = ClientOnly;
99
+ exports.Head = Head;
100
+ exports.documentReady = documentReady;
101
+ exports.hydrate = hydrate;
102
+ exports.render = render;
@@ -7,15 +7,15 @@ import { resolveConfig, createLogger, build as build$1, mergeConfig, version as
7
7
  import { JSDOM } from 'jsdom';
8
8
  import { s as serializeState } from './vite-react-ssg.C6pK7rvr.mjs';
9
9
  import { a as withTrailingSlash, r as removeLeadingSlash, w as withLeadingSlash, s as stripBase, j as joinUrlSegments } from './vite-react-ssg.CjIppNIS.mjs';
10
- import { jsx } from 'react/jsx-runtime';
10
+ import { jsx, Fragment } from 'react/jsx-runtime';
11
11
  import { HelmetProvider } from 'react-helmet-async';
12
12
  import { Writable, Readable } from 'node:stream';
13
- import { renderToPipeableStream } from 'react-dom/server';
13
+ import * as ReactDomServer from 'react-dom/server';
14
14
  import { once } from 'node:events';
15
15
  import { c as convertRoutesToDataRoutes } from './vite-react-ssg.C0y5wbxl.mjs';
16
16
  import { M as META_CONTAINER_ID } from './vite-react-ssg.B-j07kW6.mjs';
17
17
 
18
- const version = "0.8.1";
18
+ const version = "0.8.3-beta.1";
19
19
 
20
20
  function buildLog(text, count) {
21
21
  console.log(`
@@ -297,8 +297,11 @@ function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
297
297
  }
298
298
 
299
299
  async function renderStaticApp(app) {
300
+ if (!ReactDomServer.renderToPipeableStream) {
301
+ return ReactDomServer.renderToString(/* @__PURE__ */ jsx(Fragment, { children: app }));
302
+ }
300
303
  const writableStream = new WritableAsPromise();
301
- const { pipe } = renderToPipeableStream(app, {
304
+ const { pipe } = ReactDomServer.renderToPipeableStream(app, {
302
305
  onError(error) {
303
306
  writableStream.destroy(error);
304
307
  },
@@ -450,7 +453,7 @@ class RemixAdapter {
450
453
  this.context = context;
451
454
  }
452
455
  async render(path) {
453
- const { base, routes, getStyleCollector } = this.context;
456
+ const { base, routes, getStyleCollector, routerOptions } = this.context;
454
457
  const fetchUrl = `${withTrailingSlash(base)}${removeLeadingSlash(path)}`;
455
458
  const request = createRequest(fetchUrl);
456
459
  const styleCollector = getStyleCollector ? await getStyleCollector() : null;
@@ -462,7 +465,7 @@ class RemixAdapter {
462
465
  if (_context instanceof Response)
463
466
  throw _context;
464
467
  routerContext = _context;
465
- const router = createStaticRouter(dataRoutes, routerContext);
468
+ const router = createStaticRouter(dataRoutes, routerContext, { future: routerOptions.future });
466
469
  let app = /* @__PURE__ */ jsx(HelmetProvider, { context: helmetContext, children: /* @__PURE__ */ jsx(StaticRouterProvider, { router, context: routerContext }) });
467
470
  if (styleCollector)
468
471
  app = styleCollector.collect(app);
@@ -922,9 +925,11 @@ function ssrServerPlugin({
922
925
  [ssrEntry, entry].map(async (entry2) => await server.moduleGraph.getModuleByUrl(entry2))
923
926
  );
924
927
  const assetsUrls = /* @__PURE__ */ new Set();
928
+ const collectedMods = /* @__PURE__ */ new Set();
925
929
  const collectAssets = async (mod) => {
926
- if (!mod || !mod?.ssrTransformResult)
930
+ if (!mod || !mod?.ssrTransformResult || collectedMods.has(mod))
927
931
  return;
932
+ collectedMods.add(mod);
928
933
  const { deps = [], dynamicDeps = [] } = mod?.ssrTransformResult;
929
934
  const allDeps = [...deps, ...dynamicDeps];
930
935
  for (const dep of allDeps) {
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
2
+ import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
3
  import { Options } from 'beasties';
4
4
 
5
5
  type Router = ReturnType<typeof createBrowserRouter>;
@@ -162,6 +162,7 @@ interface ViteReactSSGClientOptions {
162
162
  */
163
163
  ssrWhenDev?: boolean;
164
164
  getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
165
+ useLegacyRender?: boolean;
165
166
  }
166
167
  interface CommonRouteOptions {
167
168
  /**
@@ -187,10 +188,17 @@ type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
187
188
  } & CommonRouteOptions;
188
189
  type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
189
190
  type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
191
+ interface RouterFutureConfig {
192
+ v7_fetcherPersist?: boolean;
193
+ v7_normalizeFormMethod?: boolean;
194
+ v7_partialHydration?: boolean;
195
+ v7_relativeSplatPath?: boolean;
196
+ v7_skipActionErrorRevalidation?: boolean;
197
+ }
190
198
  interface RouterOptions {
191
199
  routes: RouteRecord[];
192
- createFetchRequest?: <T>(req: T) => Request;
193
200
  basename?: string;
201
+ future?: Partial<RouterFutureConfig & FutureConfig>;
194
202
  }
195
203
  interface StyleCollector {
196
204
  collect: (app: ReactElement) => ReactElement;
@@ -203,4 +211,4 @@ declare module 'vite' {
203
211
  }
204
212
  }
205
213
 
206
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
214
+ export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterFutureConfig as c, RouterOptions as d };
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
2
+ import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
3
  import { Options } from 'beasties';
4
4
 
5
5
  type Router = ReturnType<typeof createBrowserRouter>;
@@ -162,6 +162,7 @@ interface ViteReactSSGClientOptions {
162
162
  */
163
163
  ssrWhenDev?: boolean;
164
164
  getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
165
+ useLegacyRender?: boolean;
165
166
  }
166
167
  interface CommonRouteOptions {
167
168
  /**
@@ -187,10 +188,17 @@ type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
187
188
  } & CommonRouteOptions;
188
189
  type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
189
190
  type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
191
+ interface RouterFutureConfig {
192
+ v7_fetcherPersist?: boolean;
193
+ v7_normalizeFormMethod?: boolean;
194
+ v7_partialHydration?: boolean;
195
+ v7_relativeSplatPath?: boolean;
196
+ v7_skipActionErrorRevalidation?: boolean;
197
+ }
190
198
  interface RouterOptions {
191
199
  routes: RouteRecord[];
192
- createFetchRequest?: <T>(req: T) => Request;
193
200
  basename?: string;
201
+ future?: Partial<RouterFutureConfig & FutureConfig>;
194
202
  }
195
203
  interface StyleCollector {
196
204
  collect: (app: ReactElement) => ReactElement;
@@ -203,4 +211,4 @@ declare module 'vite' {
203
211
  }
204
212
  }
205
213
 
206
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
214
+ export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterFutureConfig as c, RouterOptions as d };
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
2
+ import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
3
  import { Options } from 'beasties';
4
4
 
5
5
  type Router = ReturnType<typeof createBrowserRouter>;
@@ -162,6 +162,7 @@ interface ViteReactSSGClientOptions {
162
162
  */
163
163
  ssrWhenDev?: boolean;
164
164
  getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
165
+ useLegacyRender?: boolean;
165
166
  }
166
167
  interface CommonRouteOptions {
167
168
  /**
@@ -187,10 +188,17 @@ type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
187
188
  } & CommonRouteOptions;
188
189
  type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
189
190
  type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
191
+ interface RouterFutureConfig {
192
+ v7_fetcherPersist?: boolean;
193
+ v7_normalizeFormMethod?: boolean;
194
+ v7_partialHydration?: boolean;
195
+ v7_relativeSplatPath?: boolean;
196
+ v7_skipActionErrorRevalidation?: boolean;
197
+ }
190
198
  interface RouterOptions {
191
199
  routes: RouteRecord[];
192
- createFetchRequest?: <T>(req: T) => Request;
193
200
  basename?: string;
201
+ future?: Partial<RouterFutureConfig & FutureConfig>;
194
202
  }
195
203
  interface StyleCollector {
196
204
  collect: (app: ReactElement) => ReactElement;
@@ -203,4 +211,4 @@ declare module 'vite' {
203
211
  }
204
212
  }
205
213
 
206
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
214
+ export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterFutureConfig as c, RouterOptions as d };
@@ -12,7 +12,7 @@ const path = require('./vite-react-ssg.CFQGqC60.cjs');
12
12
  const jsxRuntime = require('react/jsx-runtime');
13
13
  const reactHelmetAsync = require('react-helmet-async');
14
14
  const node_stream = require('node:stream');
15
- const server = require('react-dom/server');
15
+ const ReactDomServer = require('react-dom/server');
16
16
  const node_events = require('node:events');
17
17
  const remixRouter = require('./vite-react-ssg.C2GpVZF1.cjs');
18
18
  const tanstackRouter = require('./vite-react-ssg.DWHmkjdM.cjs');
@@ -20,10 +20,23 @@ const tanstackRouter = require('./vite-react-ssg.DWHmkjdM.cjs');
20
20
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
21
21
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
22
22
 
23
+ function _interopNamespaceCompat(e) {
24
+ if (e && typeof e === 'object' && 'default' in e) return e;
25
+ const n = Object.create(null);
26
+ if (e) {
27
+ for (const k in e) {
28
+ n[k] = e[k];
29
+ }
30
+ }
31
+ n.default = e;
32
+ return n;
33
+ }
34
+
23
35
  const PQueue__default = /*#__PURE__*/_interopDefaultCompat(PQueue);
24
36
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
37
+ const ReactDomServer__namespace = /*#__PURE__*/_interopNamespaceCompat(ReactDomServer);
25
38
 
26
- const version = "0.8.1";
39
+ const version = "0.8.3-beta.1";
27
40
 
28
41
  function buildLog(text, count) {
29
42
  console.log(`
@@ -305,8 +318,11 @@ function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
305
318
  }
306
319
 
307
320
  async function renderStaticApp(app) {
321
+ if (!ReactDomServer__namespace.renderToPipeableStream) {
322
+ return ReactDomServer__namespace.renderToString(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: app }));
323
+ }
308
324
  const writableStream = new WritableAsPromise();
309
- const { pipe } = server.renderToPipeableStream(app, {
325
+ const { pipe } = ReactDomServer__namespace.renderToPipeableStream(app, {
310
326
  onError(error) {
311
327
  writableStream.destroy(error);
312
328
  },
@@ -458,7 +474,7 @@ class RemixAdapter {
458
474
  this.context = context;
459
475
  }
460
476
  async render(path$1) {
461
- const { base, routes, getStyleCollector } = this.context;
477
+ const { base, routes, getStyleCollector, routerOptions } = this.context;
462
478
  const fetchUrl = `${path.withTrailingSlash(base)}${path.removeLeadingSlash(path$1)}`;
463
479
  const request = createRequest(fetchUrl);
464
480
  const styleCollector = getStyleCollector ? await getStyleCollector() : null;
@@ -470,7 +486,7 @@ class RemixAdapter {
470
486
  if (_context instanceof Response)
471
487
  throw _context;
472
488
  routerContext = _context;
473
- const router = createStaticRouter(dataRoutes, routerContext);
489
+ const router = createStaticRouter(dataRoutes, routerContext, { future: routerOptions.future });
474
490
  let app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { context: helmetContext, children: /* @__PURE__ */ jsxRuntime.jsx(StaticRouterProvider, { router, context: routerContext }) });
475
491
  if (styleCollector)
476
492
  app = styleCollector.collect(app);
@@ -793,7 +809,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
793
809
  const ext = format === "esm" ? ".mjs" : ".cjs";
794
810
  const serverEntry = node_path.join(prefix, ssgOut, node_path.parse(ssrEntry).name + ext);
795
811
  const serverManifest = JSON.parse(await fs__default.readFile(node_path.join(ssgOut, ...dotVitedir, "manifest.json"), "utf-8"));
796
- const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-react-ssg.U7W0lHXm.cjs', document.baseURI).href)));
812
+ const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-react-ssg.LHioe_9y.cjs', document.baseURI).href)));
797
813
  const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
798
814
  const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
799
815
  const { routes } = await createRoot(false);
@@ -930,9 +946,11 @@ function ssrServerPlugin({
930
946
  [ssrEntry, entry].map(async (entry2) => await server.moduleGraph.getModuleByUrl(entry2))
931
947
  );
932
948
  const assetsUrls = /* @__PURE__ */ new Set();
949
+ const collectedMods = /* @__PURE__ */ new Set();
933
950
  const collectAssets = async (mod) => {
934
- if (!mod || !mod?.ssrTransformResult)
951
+ if (!mod || !mod?.ssrTransformResult || collectedMods.has(mod))
935
952
  return;
953
+ collectedMods.add(mod);
936
954
  const { deps = [], dynamicDeps = [] } = mod?.ssrTransformResult;
937
955
  const allDeps = [...deps, ...dynamicDeps];
938
956
  for (const dep of allDeps) {
package/dist/tanstack.cjs CHANGED
@@ -1,19 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
- const React = require('react');
5
- const client = require('react-dom/client');
6
4
  const reactHelmetAsync = require('react-helmet-async');
7
5
  const reactRouter = require('@tanstack/react-router');
8
6
  const start = require('@tanstack/start');
9
- const ClientOnly = require('./shared/vite-react-ssg.yL7u7OP5.cjs');
7
+ const ClientOnly = require('./shared/vite-react-ssg.CRjwV0we.cjs');
10
8
  const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
11
9
  const tanstackRouter = require('./shared/vite-react-ssg.DWHmkjdM.cjs');
12
10
  const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
13
-
14
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
15
-
16
- const React__default = /*#__PURE__*/_interopDefaultCompat(React);
11
+ require('react');
12
+ require('react-dom');
17
13
 
18
14
  const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
19
15
  function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
@@ -125,19 +121,17 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
125
121
  const { router } = await createRoot(true);
126
122
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
127
123
  if (!isSSR && process.env.NODE_ENV === "development") {
128
- const root = client.createRoot(container);
129
- React__default.startTransition(() => {
130
- root.render(
131
- /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouter.RouterProvider, { router }) })
132
- );
133
- });
124
+ ClientOnly.render(
125
+ /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouter.RouterProvider, { router }) }),
126
+ container,
127
+ options
128
+ );
134
129
  } else {
135
- React__default.startTransition(() => {
136
- client.hydrateRoot(
137
- container,
138
- /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(start.StartClient, { router }) })
139
- );
140
- });
130
+ ClientOnly.hydrate(
131
+ /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(start.StartClient, { router }) }),
132
+ container,
133
+ options
134
+ );
141
135
  }
142
136
  })();
143
137
  }
@@ -1,6 +1,6 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.cjs';
5
5
  import 'react';
6
6
  import 'react-router-dom';
@@ -1,6 +1,6 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.mjs';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.mjs';
5
5
  import 'react';
6
6
  import 'react-router-dom';
@@ -1,6 +1,6 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Di0pROyF.js';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.js';
5
5
  import 'react';
6
6
  import 'react-router-dom';
package/dist/tanstack.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import React from 'react';
3
- import { createRoot, hydrateRoot } from 'react-dom/client';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
2
  import { HelmetProvider } from 'react-helmet-async';
5
3
  import { RouterProvider } from '@tanstack/react-router';
6
- import { StartClient, Meta } from '@tanstack/start';
7
- import { d as documentReady } from './shared/vite-react-ssg.DdDMKzrS.mjs';
8
- export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DdDMKzrS.mjs';
4
+ import { Meta, StartClient } from '@tanstack/start';
5
+ import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.C2Pi5cFR.mjs';
6
+ export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.C2Pi5cFR.mjs';
9
7
  import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
10
8
  import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.B-j07kW6.mjs';
11
9
  export { r as registerPaths } from './shared/vite-react-ssg.B-j07kW6.mjs';
12
10
  import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
11
+ import 'react';
12
+ import 'react-dom';
13
13
 
14
14
  const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
15
15
  function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
@@ -35,7 +35,7 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
35
35
  component
36
36
  });
37
37
  }
38
- async function createRoot$1(client = false, routePath) {
38
+ async function createRoot(client = false, routePath) {
39
39
  const routes = await convertRouteTreeToRouteOption(
40
40
  routerOptions.routes,
41
41
  client,
@@ -118,26 +118,24 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
118
118
  console.warn("[vite-react-ssg] Root container not found.");
119
119
  return;
120
120
  }
121
- const { router } = await createRoot$1(true);
121
+ const { router } = await createRoot(true);
122
122
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
123
123
  if (!isSSR && process.env.NODE_ENV === "development") {
124
- const root = createRoot(container);
125
- React.startTransition(() => {
126
- root.render(
127
- /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) })
128
- );
129
- });
124
+ render(
125
+ /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) }),
126
+ container,
127
+ options
128
+ );
130
129
  } else {
131
- React.startTransition(() => {
132
- hydrateRoot(
133
- container,
134
- /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(StartClient, { router }) })
135
- );
136
- });
130
+ hydrate(
131
+ /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(StartClient, { router }) }),
132
+ container,
133
+ options
134
+ );
137
135
  }
138
136
  })();
139
137
  }
140
- return createRoot$1;
138
+ return createRoot;
141
139
  }
142
140
 
143
141
  export { Experimental_ViteReactSSG };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.8.1",
4
+ "version": "0.8.3-beta.1",
5
5
  "packageManager": "pnpm@9.12.3",
6
6
  "description": "Static-site generation for React on Vite.",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",
@@ -85,8 +85,8 @@
85
85
  "beasties": "^0.1.0",
86
86
  "critters": "^0.0.24",
87
87
  "prettier": "*",
88
- "react": "^18.0.0",
89
- "react-dom": "^18.0.0",
88
+ "react": "^17.0.2||^18.0.0",
89
+ "react-dom": "^17.0.2||^18.0.0",
90
90
  "react-router-dom": "^6.14.1",
91
91
  "styled-components": "^6.0.0",
92
92
  "vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"
@@ -144,7 +144,7 @@
144
144
  "prettier": "^3.3.3",
145
145
  "react": "^18.2.0",
146
146
  "react-dom": "^18.2.0",
147
- "react-router-dom": "^6.26.2",
147
+ "react-router-dom": "^6.28.0",
148
148
  "rimraf": "5.0.1",
149
149
  "styled-components": "6.0.5",
150
150
  "typescript": "^5.6.2",
@@ -1,43 +0,0 @@
1
- import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { Helmet } from 'react-helmet-async';
3
- import { useState, useEffect, isValidElement } from 'react';
4
-
5
- function documentReady(_passThrough) {
6
- if (document.readyState === "loading") {
7
- return new Promise((resolve) => {
8
- document.addEventListener("DOMContentLoaded", () => resolve(_passThrough));
9
- });
10
- }
11
- return Promise.resolve(_passThrough);
12
- }
13
-
14
- function Head(props) {
15
- return /* @__PURE__ */ jsx(Helmet, { ...props });
16
- }
17
-
18
- function useIsClient() {
19
- const [isBrowser, setIsBrowser] = useState(false);
20
- useEffect(() => {
21
- setIsBrowser(true);
22
- }, []);
23
- return isBrowser;
24
- }
25
-
26
- function ClientOnly({
27
- children,
28
- fallback
29
- }) {
30
- const isBrowser = useIsClient();
31
- if (isBrowser) {
32
- if (typeof children !== "function" && process.env.NODE_ENV === "development") {
33
- throw new Error(
34
- `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
35
- Current type: ${isValidElement(children) ? "React element" : typeof children}`
36
- );
37
- }
38
- return /* @__PURE__ */ jsx(Fragment, { children: children?.() });
39
- }
40
- return fallback ?? null;
41
- }
42
-
43
- export { ClientOnly as C, Head as H, documentReady as d };
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- const jsxRuntime = require('react/jsx-runtime');
4
- const reactHelmetAsync = require('react-helmet-async');
5
- const React = require('react');
6
-
7
- function documentReady(_passThrough) {
8
- if (document.readyState === "loading") {
9
- return new Promise((resolve) => {
10
- document.addEventListener("DOMContentLoaded", () => resolve(_passThrough));
11
- });
12
- }
13
- return Promise.resolve(_passThrough);
14
- }
15
-
16
- function Head(props) {
17
- return /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.Helmet, { ...props });
18
- }
19
-
20
- function useIsClient() {
21
- const [isBrowser, setIsBrowser] = React.useState(false);
22
- React.useEffect(() => {
23
- setIsBrowser(true);
24
- }, []);
25
- return isBrowser;
26
- }
27
-
28
- function ClientOnly({
29
- children,
30
- fallback
31
- }) {
32
- const isBrowser = useIsClient();
33
- if (isBrowser) {
34
- if (typeof children !== "function" && process.env.NODE_ENV === "development") {
35
- throw new Error(
36
- `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
37
- Current type: ${React.isValidElement(children) ? "React element" : typeof children}`
38
- );
39
- }
40
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.() });
41
- }
42
- return fallback ?? null;
43
- }
44
-
45
- exports.ClientOnly = ClientOnly;
46
- exports.Head = Head;
47
- exports.documentReady = documentReady;