vite-react-ssg 0.8.2 → 0.8.3-beta.2
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.
- package/README.md +5 -0
- package/dist/client/single-page.cjs +5 -14
- package/dist/client/single-page.d.cts +2 -2
- package/dist/client/single-page.d.mts +2 -2
- package/dist/client/single-page.d.ts +2 -2
- package/dist/client/single-page.mjs +9 -14
- package/dist/index.cjs +5 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +9 -14
- package/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/vite-react-ssg.0S4Yj_HC.cjs +102 -0
- package/dist/shared/{vite-react-ssg.BEenhaUp.cjs → vite-react-ssg.CjMwYAJ_.cjs} +20 -4
- package/dist/shared/{vite-react-ssg.CCvTYWeJ.mjs → vite-react-ssg.DH605nuR.mjs} +7 -4
- package/dist/shared/vite-react-ssg.DQEe2Gi_.mjs +79 -0
- package/dist/shared/{vite-react-ssg.WtHsP9dD.d.mts → vite-react-ssg.Di0pROyF.d.cts} +1 -0
- package/dist/shared/{vite-react-ssg.WtHsP9dD.d.ts → vite-react-ssg.Di0pROyF.d.mts} +1 -0
- package/dist/shared/{vite-react-ssg.WtHsP9dD.d.cts → vite-react-ssg.Di0pROyF.d.ts} +1 -0
- package/dist/tanstack.cjs +13 -19
- package/dist/tanstack.d.cts +2 -2
- package/dist/tanstack.d.mts +2 -2
- package/dist/tanstack.d.ts +2 -2
- package/dist/tanstack.mjs +19 -21
- package/package.json +3 -3
- package/dist/shared/vite-react-ssg.DdDMKzrS.mjs +0 -43
- package/dist/shared/vite-react-ssg.yL7u7OP5.cjs +0 -47
package/README.md
CHANGED
|
@@ -609,6 +609,11 @@ export default defineConfig({
|
|
|
609
609
|
})
|
|
610
610
|
```
|
|
611
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
|
+
|
|
612
617
|
## Roadmap
|
|
613
618
|
|
|
614
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
|
|
7
|
-
const ClientOnly = require('../shared/vite-react-ssg.yL7u7OP5.cjs');
|
|
5
|
+
const ClientOnly = require('../shared/vite-react-ssg.0S4Yj_HC.cjs');
|
|
8
6
|
const state = require('../shared/vite-react-ssg.CjsEygxB.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
69
|
-
React__default.startTransition(() => {
|
|
70
|
-
root.render(app);
|
|
71
|
-
});
|
|
64
|
+
ClientOnly.render(app, container, options);
|
|
72
65
|
} else {
|
|
73
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
5
|
-
|
|
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.DQEe2Gi_.mjs';
|
|
4
|
+
export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.DQEe2Gi_.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
|
|
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
|
|
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
|
-
|
|
64
|
-
React.startTransition(() => {
|
|
65
|
-
root.render(app);
|
|
66
|
-
});
|
|
63
|
+
render(app, container, options);
|
|
67
64
|
} else {
|
|
68
|
-
|
|
69
|
-
hydrateRoot(container, app);
|
|
70
|
-
});
|
|
65
|
+
hydrate(app, container, options);
|
|
71
66
|
}
|
|
72
67
|
})();
|
|
73
68
|
}
|
|
74
|
-
return createRoot
|
|
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.
|
|
6
|
+
const ClientOnly = require('./shared/vite-react-ssg.0S4Yj_HC.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
|
|
|
@@ -148,14 +148,9 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
148
148
|
const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.RouterProvider, { router, future: { v7_startTransition } }) });
|
|
149
149
|
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
150
150
|
if (!isSSR && process.env.NODE_ENV === "development") {
|
|
151
|
-
|
|
152
|
-
React__default.startTransition(() => {
|
|
153
|
-
root.render(app);
|
|
154
|
-
});
|
|
151
|
+
ClientOnly.render(app, container, options);
|
|
155
152
|
} else {
|
|
156
|
-
|
|
157
|
-
client.hydrateRoot(container, app);
|
|
158
|
-
});
|
|
153
|
+
ClientOnly.hydrate(app, container, options);
|
|
159
154
|
}
|
|
160
155
|
})();
|
|
161
156
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.
|
|
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.
|
|
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 { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.
|
|
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.
|
|
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 { d as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.
|
|
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.
|
|
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.
|
|
7
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
4
|
+
import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.DQEe2Gi_.mjs';
|
|
5
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DQEe2Gi_.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 {
|
|
@@ -84,7 +84,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
84
84
|
const isClient = typeof window !== "undefined";
|
|
85
85
|
const BASE_URL = routerOptions.basename ?? "/";
|
|
86
86
|
const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {};
|
|
87
|
-
async function createRoot
|
|
87
|
+
async function createRoot(client = false, routePath) {
|
|
88
88
|
const browserRouter = client ? createBrowserRouter(
|
|
89
89
|
convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
|
|
90
90
|
{ basename: BASE_URL, future: routerFeature }
|
|
@@ -139,22 +139,17 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
139
139
|
})
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
|
-
const { router } = await createRoot
|
|
142
|
+
const { router } = await createRoot(true);
|
|
143
143
|
const app = /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router, future: { v7_startTransition } }) });
|
|
144
144
|
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
145
145
|
if (!isSSR && process.env.NODE_ENV === "development") {
|
|
146
|
-
|
|
147
|
-
React.startTransition(() => {
|
|
148
|
-
root.render(app);
|
|
149
|
-
});
|
|
146
|
+
render(app, container, options);
|
|
150
147
|
} else {
|
|
151
|
-
|
|
152
|
-
hydrateRoot(container, app);
|
|
153
|
-
});
|
|
148
|
+
hydrate(app, container, options);
|
|
154
149
|
}
|
|
155
150
|
})();
|
|
156
151
|
}
|
|
157
|
-
return createRoot
|
|
152
|
+
return createRoot;
|
|
158
153
|
function transformStaticLoaderRoute(route) {
|
|
159
154
|
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
160
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.
|
|
6
|
+
const dev = require('../shared/vite-react-ssg.CjMwYAJ_.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.
|
|
4
|
+
import { b as build, d as dev } from '../shared/vite-react-ssg.DH605nuR.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
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.
|
|
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.
|
|
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
package/dist/node.mjs
CHANGED
|
@@ -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
|
+
async function render(app, container, renderOptions = {}) {
|
|
31
|
+
const { useLegacyRender } = renderOptions;
|
|
32
|
+
if (useLegacyRender || !isReact18) {
|
|
33
|
+
reactRender(app, container);
|
|
34
|
+
} else {
|
|
35
|
+
const { createRoot } = await import('react-dom/client');
|
|
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
|
+
async function hydrate(app, container, renderOptions = {}) {
|
|
46
|
+
const { useLegacyRender } = renderOptions;
|
|
47
|
+
if (useLegacyRender || !isReact18) {
|
|
48
|
+
reactHydrate(app, container);
|
|
49
|
+
} else {
|
|
50
|
+
const { hydrateRoot } = await import('react-dom/client');
|
|
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;
|
|
@@ -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
|
|
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.2";
|
|
39
|
+
const version = "0.8.3-beta.2";
|
|
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 } =
|
|
325
|
+
const { pipe } = ReactDomServer__namespace.renderToPipeableStream(app, {
|
|
310
326
|
onError(error) {
|
|
311
327
|
writableStream.destroy(error);
|
|
312
328
|
},
|
|
@@ -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.
|
|
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.CjMwYAJ_.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);
|
|
@@ -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
|
|
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.2";
|
|
18
|
+
const version = "0.8.3-beta.2";
|
|
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
|
},
|
|
@@ -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
|
+
async function render(app, container, renderOptions = {}) {
|
|
12
|
+
const { useLegacyRender } = renderOptions;
|
|
13
|
+
if (useLegacyRender || !isReact18) {
|
|
14
|
+
reactRender(app, container);
|
|
15
|
+
} else {
|
|
16
|
+
const { createRoot } = await import('react-dom/client');
|
|
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
|
+
async function hydrate(app, container, renderOptions = {}) {
|
|
27
|
+
const { useLegacyRender } = renderOptions;
|
|
28
|
+
if (useLegacyRender || !isReact18) {
|
|
29
|
+
reactHydrate(app, container);
|
|
30
|
+
} else {
|
|
31
|
+
const { hydrateRoot } = await import('react-dom/client');
|
|
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 };
|
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.
|
|
7
|
+
const ClientOnly = require('./shared/vite-react-ssg.0S4Yj_HC.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
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
}
|
package/dist/tanstack.d.cts
CHANGED
|
@@ -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.
|
|
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.
|
|
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';
|
package/dist/tanstack.d.mts
CHANGED
|
@@ -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.
|
|
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.
|
|
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';
|
package/dist/tanstack.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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 {
|
|
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 {
|
|
7
|
-
import { d as documentReady } from './shared/vite-react-ssg.
|
|
8
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
4
|
+
import { Meta, StartClient } from '@tanstack/start';
|
|
5
|
+
import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.DQEe2Gi_.mjs';
|
|
6
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DQEe2Gi_.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
|
|
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
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
124
|
+
render(
|
|
125
|
+
/* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) }),
|
|
126
|
+
container,
|
|
127
|
+
options
|
|
128
|
+
);
|
|
130
129
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
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.2",
|
|
4
|
+
"version": "0.8.3-beta.2",
|
|
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"
|
|
@@ -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;
|