vite-react-ssg 0.8.4 → 0.8.5-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.
- package/README.md +5 -8
- package/dist/client/single-page.d.mts +4 -4
- package/dist/client/single-page.d.ts +4 -4
- package/dist/client/single-page.mjs +7 -6
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.mjs +10 -8
- package/dist/node/cli.mjs +9 -9
- package/dist/node.d.mts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.mjs +7 -7
- package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.ts → vite-react-ssg.-NlgsPvg.d.mts} +8 -8
- package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.mts → vite-react-ssg.-NlgsPvg.d.ts} +8 -8
- package/dist/shared/{vite-react-ssg.CKcl-j8g.mjs → vite-react-ssg.2P3UhU88.mjs} +212 -211
- package/dist/shared/{vite-react-ssg.C0y5wbxl.mjs → vite-react-ssg.C_MPXL9p.mjs} +1 -1
- package/dist/shared/{vite-react-ssg.CfJcpdWF.mjs → vite-react-ssg.Dx4ca9OM.mjs} +18 -4
- package/dist/tanstack.d.mts +5 -4
- package/dist/tanstack.d.ts +5 -4
- package/dist/tanstack.mjs +9 -7
- package/package.json +32 -33
- package/dist/chunks/jsdomGlobal.cjs +0 -36
- package/dist/client/single-page.cjs +0 -75
- package/dist/client/single-page.d.cts +0 -11
- package/dist/index.cjs +0 -196
- package/dist/index.d.cts +0 -26
- package/dist/node/cli.cjs +0 -89
- package/dist/node/cli.d.cts +0 -2
- package/dist/node.cjs +0 -24
- package/dist/node.d.cts +0 -11
- package/dist/shared/vite-react-ssg.B4jDfvXh.cjs +0 -106
- package/dist/shared/vite-react-ssg.C2GpVZF1.cjs +0 -38
- package/dist/shared/vite-react-ssg.CFQGqC60.cjs +0 -36
- package/dist/shared/vite-react-ssg.CjsEygxB.cjs +0 -37
- package/dist/shared/vite-react-ssg.Cm9gBlfg.d.cts +0 -15
- package/dist/shared/vite-react-ssg.DWHmkjdM.cjs +0 -35
- package/dist/shared/vite-react-ssg.Di0pROyF.d.ts +0 -214
- package/dist/shared/vite-react-ssg.Dus0yLsZ.cjs +0 -1082
- package/dist/style-collectors/styled-components.cjs +0 -20
- package/dist/style-collectors/styled-components.d.cts +0 -9
- package/dist/tanstack.cjs +0 -144
- package/dist/tanstack.d.cts +0 -30
- package/dist/shared/{vite-react-ssg.Di0pROyF.d.cts → vite-react-ssg.BrImbdZU.d.mts} +1 -1
- package/dist/shared/{vite-react-ssg.Di0pROyF.d.mts → vite-react-ssg.BrImbdZU.d.ts} +1 -1
|
@@ -1,89 +1,81 @@
|
|
|
1
|
-
import { join, isAbsolute, parse, dirname } from 'node:path';
|
|
2
1
|
import { createRequire } from 'node:module';
|
|
2
|
+
import { join, isAbsolute, parse, dirname } from 'node:path';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import { JSDOM } from 'jsdom';
|
|
3
5
|
import { gray, yellow, blue, dim, cyan, red, green, reset, bold, bgLightCyan } from 'kolorist';
|
|
4
6
|
import PQueue from 'p-queue';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
7
|
import { resolveConfig, createLogger, build as build$1, mergeConfig, version as version$1, send, createServer } from 'vite';
|
|
7
|
-
import { JSDOM } from 'jsdom';
|
|
8
|
-
import { s as serializeState } from './vite-react-ssg.C6pK7rvr.mjs';
|
|
9
8
|
import { a as withTrailingSlash, r as removeLeadingSlash, w as withLeadingSlash, s as stripBase, j as joinUrlSegments } from './vite-react-ssg.CjIppNIS.mjs';
|
|
9
|
+
import { s as serializeState } from './vite-react-ssg.C6pK7rvr.mjs';
|
|
10
10
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
11
11
|
import { HelmetProvider } from 'react-helmet-async';
|
|
12
|
-
import { Writable, Readable } from 'node:stream';
|
|
13
|
-
import * as ReactDomServer from 'react-dom/server';
|
|
14
12
|
import { once } from 'node:events';
|
|
15
|
-
import {
|
|
13
|
+
import { Readable, Writable } from 'node:stream';
|
|
14
|
+
import { c as convertRoutesToDataRoutes } from './vite-react-ssg.C_MPXL9p.mjs';
|
|
15
|
+
import * as ReactDomServer from 'react-dom/server';
|
|
16
16
|
import { M as META_CONTAINER_ID } from './vite-react-ssg.B-j07kW6.mjs';
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const lazyData = await route.lazy();
|
|
36
|
-
if (lazyData) {
|
|
37
|
-
route = {
|
|
38
|
-
...route,
|
|
39
|
-
...lazyData
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let path = route.path;
|
|
44
|
-
path = handlePath(path, prefix);
|
|
45
|
-
if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
|
|
46
|
-
const staticPaths = await route.getStaticPaths();
|
|
47
|
-
for (let staticPath of staticPaths) {
|
|
48
|
-
staticPath = handlePath(staticPath, prefix);
|
|
49
|
-
if (Array.isArray(route.children))
|
|
50
|
-
await getPaths(route.children, staticPath);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (route.index && !path) {
|
|
54
|
-
paths.add("/");
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(route.children))
|
|
57
|
-
await getPaths(route.children, path);
|
|
18
|
+
const DYNAMIC_IMPORT_REGEX = /import\("([^)]+)"\)/g;
|
|
19
|
+
async function collectAssets({
|
|
20
|
+
routes,
|
|
21
|
+
locationArg,
|
|
22
|
+
base,
|
|
23
|
+
serverManifest,
|
|
24
|
+
manifest,
|
|
25
|
+
ssrManifest
|
|
26
|
+
}) {
|
|
27
|
+
const { matchRoutes } = await import('react-router-dom');
|
|
28
|
+
const matches = matchRoutes([...routes], locationArg, base);
|
|
29
|
+
const routeEntries = matches?.map((item) => item.route.entry).filter(Boolean) ?? [];
|
|
30
|
+
const dynamicImports = /* @__PURE__ */ new Set();
|
|
31
|
+
matches?.forEach((item) => {
|
|
32
|
+
let lazyStr = "";
|
|
33
|
+
if (item.route.lazy) {
|
|
34
|
+
lazyStr += item.route.lazy.toString();
|
|
58
35
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return { paths: Array.from(paths) };
|
|
62
|
-
function handlePath(path, prefix) {
|
|
63
|
-
if (path != null) {
|
|
64
|
-
path = prefix && !path.startsWith("/") ? `${prefix}${path ? `/${path}` : ""}` : path;
|
|
65
|
-
paths.add(path);
|
|
36
|
+
if (item.route.Component?._payload?._result) {
|
|
37
|
+
lazyStr += item.route.Component._payload._result.toString();
|
|
66
38
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
39
|
+
const match = lazyStr.matchAll(DYNAMIC_IMPORT_REGEX);
|
|
40
|
+
for (const m of match) {
|
|
41
|
+
dynamicImports.add(m[1].split("/").at(-1) ?? "");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const entries = /* @__PURE__ */ new Set();
|
|
45
|
+
routeEntries.forEach((e) => entries.add(e));
|
|
46
|
+
const manifestEntries = [...Object.entries(serverManifest)];
|
|
47
|
+
dynamicImports.forEach((name) => {
|
|
48
|
+
const result = manifestEntries.find(([_, value]) => value.file.endsWith(name));
|
|
49
|
+
if (result) {
|
|
50
|
+
entries.add(result[0]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const modules = collectModulesForEntries(manifest, entries);
|
|
54
|
+
const assets = /* @__PURE__ */ new Set();
|
|
55
|
+
Array.from(modules).forEach((id) => {
|
|
56
|
+
const files = ssrManifest[id] || [];
|
|
57
|
+
files.forEach((file) => {
|
|
58
|
+
assets.add(file);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return assets;
|
|
74
62
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
function collectModulesForEntries(manifest, entries) {
|
|
64
|
+
const mods = /* @__PURE__ */ new Set();
|
|
65
|
+
if (!entries)
|
|
66
|
+
return mods;
|
|
67
|
+
for (const entry of entries)
|
|
68
|
+
collectModules(manifest, entry, mods);
|
|
69
|
+
return mods;
|
|
81
70
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
|
|
72
|
+
if (!entry)
|
|
73
|
+
return mods;
|
|
74
|
+
mods.add(entry);
|
|
75
|
+
manifest[entry]?.dynamicImports?.forEach((item) => {
|
|
76
|
+
collectModules(manifest, item, mods);
|
|
77
|
+
});
|
|
78
|
+
return mods;
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
async function getBeastiesOrCritters(outDir, options = {}) {
|
|
@@ -111,7 +103,7 @@ async function getBeastiesOrCritters(outDir, options = {}) {
|
|
|
111
103
|
...options
|
|
112
104
|
});
|
|
113
105
|
} catch (e) {
|
|
114
|
-
return
|
|
106
|
+
return undefined;
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
|
|
@@ -233,138 +225,6 @@ function appendLink(document, attrs) {
|
|
|
233
225
|
document.head.appendChild(link);
|
|
234
226
|
}
|
|
235
227
|
|
|
236
|
-
const DYNAMIC_IMPORT_REGEX = /import\("([^)]+)"\)/g;
|
|
237
|
-
async function collectAssets({
|
|
238
|
-
routes,
|
|
239
|
-
locationArg,
|
|
240
|
-
base,
|
|
241
|
-
serverManifest,
|
|
242
|
-
manifest,
|
|
243
|
-
ssrManifest
|
|
244
|
-
}) {
|
|
245
|
-
const { matchRoutes } = await import('react-router-dom');
|
|
246
|
-
const matches = matchRoutes([...routes], locationArg, base);
|
|
247
|
-
const routeEntries = matches?.map((item) => item.route.entry).filter(Boolean) ?? [];
|
|
248
|
-
const dynamicImports = /* @__PURE__ */ new Set();
|
|
249
|
-
matches?.forEach((item) => {
|
|
250
|
-
let lazyStr = "";
|
|
251
|
-
if (item.route.lazy) {
|
|
252
|
-
lazyStr += item.route.lazy.toString();
|
|
253
|
-
}
|
|
254
|
-
if (item.route.Component?._payload?._result) {
|
|
255
|
-
lazyStr += item.route.Component._payload._result.toString();
|
|
256
|
-
}
|
|
257
|
-
const match = lazyStr.matchAll(DYNAMIC_IMPORT_REGEX);
|
|
258
|
-
for (const m of match) {
|
|
259
|
-
dynamicImports.add(m[1].split("/").at(-1) ?? "");
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
const entries = /* @__PURE__ */ new Set();
|
|
263
|
-
routeEntries.forEach((e) => entries.add(e));
|
|
264
|
-
const manifestEntries = [...Object.entries(serverManifest)];
|
|
265
|
-
dynamicImports.forEach((name) => {
|
|
266
|
-
const result = manifestEntries.find(([_, value]) => value.file.endsWith(name));
|
|
267
|
-
if (result) {
|
|
268
|
-
entries.add(result[0]);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
const modules = collectModulesForEntries(manifest, entries);
|
|
272
|
-
const assets = /* @__PURE__ */ new Set();
|
|
273
|
-
Array.from(modules).forEach((id) => {
|
|
274
|
-
const files = ssrManifest[id] || [];
|
|
275
|
-
files.forEach((file) => {
|
|
276
|
-
assets.add(file);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
return assets;
|
|
280
|
-
}
|
|
281
|
-
function collectModulesForEntries(manifest, entries) {
|
|
282
|
-
const mods = /* @__PURE__ */ new Set();
|
|
283
|
-
if (!entries)
|
|
284
|
-
return mods;
|
|
285
|
-
for (const entry of entries)
|
|
286
|
-
collectModules(manifest, entry, mods);
|
|
287
|
-
return mods;
|
|
288
|
-
}
|
|
289
|
-
function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
|
|
290
|
-
if (!entry)
|
|
291
|
-
return mods;
|
|
292
|
-
mods.add(entry);
|
|
293
|
-
manifest[entry]?.dynamicImports?.forEach((item) => {
|
|
294
|
-
collectModules(manifest, item, mods);
|
|
295
|
-
});
|
|
296
|
-
return mods;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async function renderStaticApp(app) {
|
|
300
|
-
if (!ReactDomServer.renderToPipeableStream) {
|
|
301
|
-
return ReactDomServer.renderToString(/* @__PURE__ */ jsx(Fragment, { children: app }));
|
|
302
|
-
}
|
|
303
|
-
const writableStream = new WritableAsPromise();
|
|
304
|
-
const { pipe } = ReactDomServer.renderToPipeableStream(app, {
|
|
305
|
-
onError(error) {
|
|
306
|
-
writableStream.destroy(error);
|
|
307
|
-
},
|
|
308
|
-
onAllReady() {
|
|
309
|
-
pipe(writableStream);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
return writableStream.getPromise();
|
|
313
|
-
}
|
|
314
|
-
class WritableAsPromise extends Writable {
|
|
315
|
-
_output;
|
|
316
|
-
_deferred;
|
|
317
|
-
constructor() {
|
|
318
|
-
super();
|
|
319
|
-
this._output = "";
|
|
320
|
-
this._deferred = {
|
|
321
|
-
promise: null,
|
|
322
|
-
resolve: () => null,
|
|
323
|
-
reject: () => null
|
|
324
|
-
};
|
|
325
|
-
this._deferred.promise = new Promise((resolve, reject) => {
|
|
326
|
-
this._deferred.resolve = resolve;
|
|
327
|
-
this._deferred.reject = reject;
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
_write(chunk, _enc, next) {
|
|
331
|
-
this._output += chunk.toString();
|
|
332
|
-
next();
|
|
333
|
-
}
|
|
334
|
-
_destroy(error, next) {
|
|
335
|
-
if (error instanceof Error)
|
|
336
|
-
this._deferred.reject(error);
|
|
337
|
-
else
|
|
338
|
-
next();
|
|
339
|
-
}
|
|
340
|
-
end() {
|
|
341
|
-
this._deferred.resolve(this._output);
|
|
342
|
-
return this.destroy();
|
|
343
|
-
}
|
|
344
|
-
getPromise() {
|
|
345
|
-
return this._deferred.promise;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function extractHelmet(context, styleCollector) {
|
|
350
|
-
const { helmet } = context;
|
|
351
|
-
const htmlAttributes = helmet.htmlAttributes.toString();
|
|
352
|
-
const bodyAttributes = helmet.bodyAttributes.toString();
|
|
353
|
-
let titleString = helmet.title.toString();
|
|
354
|
-
if (titleString.split(">")[1] === "</title") {
|
|
355
|
-
titleString = "";
|
|
356
|
-
}
|
|
357
|
-
const metaStrings = [
|
|
358
|
-
titleString,
|
|
359
|
-
helmet.meta.toString(),
|
|
360
|
-
helmet.link.toString(),
|
|
361
|
-
helmet.script.toString()
|
|
362
|
-
];
|
|
363
|
-
const styleTag = styleCollector?.toString?.("") ?? "";
|
|
364
|
-
const metaAttributes = metaStrings.filter(Boolean);
|
|
365
|
-
return { htmlAttributes, bodyAttributes, metaAttributes, styleTag };
|
|
366
|
-
}
|
|
367
|
-
|
|
368
228
|
function invariant(value, message) {
|
|
369
229
|
if (value === false || value === null || typeof value === "undefined") {
|
|
370
230
|
console.error(
|
|
@@ -417,7 +277,7 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
417
277
|
}
|
|
418
278
|
}
|
|
419
279
|
function json(data, init) {
|
|
420
|
-
if (init ===
|
|
280
|
+
if (init === undefined) {
|
|
421
281
|
init = {};
|
|
422
282
|
}
|
|
423
283
|
const responseInit = typeof init === "number" ? {
|
|
@@ -447,6 +307,146 @@ function stripDataParam(request) {
|
|
|
447
307
|
return new Request(url.href, init);
|
|
448
308
|
}
|
|
449
309
|
|
|
310
|
+
async function renderStaticApp(app) {
|
|
311
|
+
if (!ReactDomServer.renderToPipeableStream) {
|
|
312
|
+
return ReactDomServer.renderToString(/* @__PURE__ */ jsx(Fragment, { children: app }));
|
|
313
|
+
}
|
|
314
|
+
const writableStream = new WritableAsPromise();
|
|
315
|
+
const { pipe } = ReactDomServer.renderToPipeableStream(app, {
|
|
316
|
+
onError(error) {
|
|
317
|
+
writableStream.destroy(error);
|
|
318
|
+
},
|
|
319
|
+
onAllReady() {
|
|
320
|
+
pipe(writableStream);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return writableStream.getPromise();
|
|
324
|
+
}
|
|
325
|
+
class WritableAsPromise extends Writable {
|
|
326
|
+
_output;
|
|
327
|
+
_deferred;
|
|
328
|
+
constructor() {
|
|
329
|
+
super();
|
|
330
|
+
this._output = "";
|
|
331
|
+
this._deferred = {
|
|
332
|
+
promise: null,
|
|
333
|
+
resolve: () => null,
|
|
334
|
+
reject: () => null
|
|
335
|
+
};
|
|
336
|
+
this._deferred.promise = new Promise((resolve, reject) => {
|
|
337
|
+
this._deferred.resolve = resolve;
|
|
338
|
+
this._deferred.reject = reject;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
_write(chunk, _enc, next) {
|
|
342
|
+
this._output += chunk.toString();
|
|
343
|
+
next();
|
|
344
|
+
}
|
|
345
|
+
_destroy(error, next) {
|
|
346
|
+
if (error instanceof Error)
|
|
347
|
+
this._deferred.reject(error);
|
|
348
|
+
else
|
|
349
|
+
next();
|
|
350
|
+
}
|
|
351
|
+
end() {
|
|
352
|
+
this._deferred.resolve(this._output);
|
|
353
|
+
return this.destroy();
|
|
354
|
+
}
|
|
355
|
+
getPromise() {
|
|
356
|
+
return this._deferred.promise;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const version = "0.8.5-beta.1";
|
|
361
|
+
|
|
362
|
+
function buildLog(text, count) {
|
|
363
|
+
console.log(`
|
|
364
|
+
${gray("[vite-react-ssg]")} ${yellow(text)}${count ? blue(` (${count})`) : ""}`);
|
|
365
|
+
}
|
|
366
|
+
function getSize(str) {
|
|
367
|
+
return `${(str.length / 1024).toFixed(2)} KiB`;
|
|
368
|
+
}
|
|
369
|
+
async function routesToPaths(routes) {
|
|
370
|
+
if (!routes || routes.length === 0)
|
|
371
|
+
return { paths: ["/"] };
|
|
372
|
+
const paths = /* @__PURE__ */ new Set();
|
|
373
|
+
const getPaths = async (routes2, prefix = "") => {
|
|
374
|
+
prefix = prefix.replace(/\/$/g, "");
|
|
375
|
+
for (let route of routes2) {
|
|
376
|
+
if (route.lazy) {
|
|
377
|
+
const lazyData = await route.lazy();
|
|
378
|
+
if (lazyData) {
|
|
379
|
+
route = {
|
|
380
|
+
...route,
|
|
381
|
+
...lazyData
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
let path = route.path;
|
|
386
|
+
path = handlePath(path, prefix);
|
|
387
|
+
if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
|
|
388
|
+
const staticPaths = await route.getStaticPaths();
|
|
389
|
+
for (let staticPath of staticPaths) {
|
|
390
|
+
staticPath = handlePath(staticPath, prefix);
|
|
391
|
+
if (Array.isArray(route.children))
|
|
392
|
+
await getPaths(route.children, staticPath);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (route.index && !path) {
|
|
396
|
+
paths.add("/");
|
|
397
|
+
}
|
|
398
|
+
if (Array.isArray(route.children))
|
|
399
|
+
await getPaths(route.children, path);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
await getPaths(routes);
|
|
403
|
+
return { paths: Array.from(paths) };
|
|
404
|
+
function handlePath(path, prefix) {
|
|
405
|
+
if (path != null) {
|
|
406
|
+
path = prefix && !path.startsWith("/") ? `${prefix}${path ? `/${path}` : ""}` : path;
|
|
407
|
+
paths.add(path);
|
|
408
|
+
}
|
|
409
|
+
return path;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function resolveAlias(config, entry) {
|
|
413
|
+
const resolver = config.createResolver();
|
|
414
|
+
const result = await resolver(entry, config.root);
|
|
415
|
+
return result || join(config.root, entry);
|
|
416
|
+
}
|
|
417
|
+
function createRequest(path) {
|
|
418
|
+
const url = new URL(path, "http://vite-react-ssg.com");
|
|
419
|
+
url.search = "";
|
|
420
|
+
url.hash = "";
|
|
421
|
+
url.pathname = path;
|
|
422
|
+
return new Request(url.href);
|
|
423
|
+
}
|
|
424
|
+
const dynamicRE = /[:*?]/;
|
|
425
|
+
function isDynamicSegmentsRoute(route) {
|
|
426
|
+
if (!route)
|
|
427
|
+
return false;
|
|
428
|
+
return dynamicRE.test(route);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function extractHelmet(context, styleCollector) {
|
|
432
|
+
const { helmet } = context;
|
|
433
|
+
const htmlAttributes = helmet.htmlAttributes.toString();
|
|
434
|
+
const bodyAttributes = helmet.bodyAttributes.toString();
|
|
435
|
+
let titleString = helmet.title.toString();
|
|
436
|
+
if (titleString.split(">")[1] === "</title") {
|
|
437
|
+
titleString = "";
|
|
438
|
+
}
|
|
439
|
+
const metaStrings = [
|
|
440
|
+
titleString,
|
|
441
|
+
helmet.meta.toString(),
|
|
442
|
+
helmet.link.toString(),
|
|
443
|
+
helmet.script.toString()
|
|
444
|
+
];
|
|
445
|
+
const styleTag = styleCollector?.toString?.("") ?? "";
|
|
446
|
+
const metaAttributes = metaStrings.filter(Boolean);
|
|
447
|
+
return { htmlAttributes, bodyAttributes, metaAttributes, styleTag };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
450
|
class RemixAdapter {
|
|
451
451
|
context;
|
|
452
452
|
constructor(context) {
|
|
@@ -528,7 +528,7 @@ async function callRouteLoader({
|
|
|
528
528
|
request: stripDataParam(stripIndexParam(request)),
|
|
529
529
|
params
|
|
530
530
|
});
|
|
531
|
-
if (result ===
|
|
531
|
+
if (result === undefined) {
|
|
532
532
|
throw new Error(
|
|
533
533
|
`You defined a loader for route "${routeId}" but didn't return anything from your \`loader\` function. Please return a value or \`null\`.`
|
|
534
534
|
);
|
|
@@ -788,7 +788,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
788
788
|
}));
|
|
789
789
|
const prefix = format === "esm" && process.platform === "win32" ? "file://" : "";
|
|
790
790
|
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
791
|
-
const serverEntry = join(
|
|
791
|
+
const serverEntry = prefix + join(ssgOut, parse(ssrEntry).name + ext).replace(/\\/g, "/");
|
|
792
792
|
const serverManifest = JSON.parse(await fs.readFile(join(ssgOut, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
793
793
|
const _require = createRequire(import.meta.url);
|
|
794
794
|
const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
|
|
@@ -799,7 +799,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
799
799
|
routesPaths = DefaultIncludedRoutes(routesPaths);
|
|
800
800
|
routesPaths = Array.from(new Set(routesPaths));
|
|
801
801
|
buildLog("Rendering Pages...", routesPaths.length);
|
|
802
|
-
const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) :
|
|
802
|
+
const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) : undefined;
|
|
803
803
|
if (beasties)
|
|
804
804
|
console.log(`${gray("[vite-react-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
|
|
805
805
|
const ssrManifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
|
|
@@ -916,13 +916,14 @@ function ssrServerPlugin({
|
|
|
916
916
|
const appCtx = await createRoot(false, url);
|
|
917
917
|
const adapter = getAdapter(appCtx);
|
|
918
918
|
const { app, base } = appCtx;
|
|
919
|
-
const
|
|
919
|
+
const [pathname, search] = url.split("?");
|
|
920
|
+
const searchParams = new URLSearchParams(search);
|
|
920
921
|
if (!app && searchParams.has("_data")) {
|
|
921
922
|
return adapter.handleLoader(req, res);
|
|
922
923
|
}
|
|
923
924
|
const indexHTML = await server.transformIndexHtml(url, template);
|
|
924
925
|
const transformedIndexHTML = await onBeforePageRender?.(url, indexHTML, appCtx) || indexHTML;
|
|
925
|
-
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await adapter.render(stripBase(
|
|
926
|
+
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await adapter.render(stripBase(pathname, base));
|
|
926
927
|
metaAttributes.push(styleTag);
|
|
927
928
|
const mods = await Promise.all(
|
|
928
929
|
[ssrEntry, entry].map(async (entry2) => await server.moduleGraph.getModuleByUrl(entry2))
|
|
@@ -15,7 +15,7 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [])
|
|
|
15
15
|
...route,
|
|
16
16
|
...mapRouteProperties(route),
|
|
17
17
|
id,
|
|
18
|
-
children:
|
|
18
|
+
children: undefined
|
|
19
19
|
};
|
|
20
20
|
if (route.children) {
|
|
21
21
|
pathOrLayoutRoute.children = convertRoutesToDataRoutes(
|
|
@@ -8,10 +8,18 @@ const CopyReactDOM = {
|
|
|
8
8
|
};
|
|
9
9
|
const { version, render: reactRender, hydrate: reactHydrate } = CopyReactDOM;
|
|
10
10
|
const isReact18 = Number((version || "").split(".")[0]) > 17;
|
|
11
|
+
const isReact19 = Number((version || "").split(".")[0]) > 18;
|
|
11
12
|
function render(app, container, renderOptions = {}) {
|
|
12
13
|
const { useLegacyRender } = renderOptions;
|
|
13
14
|
if (useLegacyRender || !isReact18) {
|
|
14
15
|
reactRender(app, container);
|
|
16
|
+
} else if (isReact19) {
|
|
17
|
+
import('react-dom/client').then(({ createRoot }) => {
|
|
18
|
+
const root = createRoot(container);
|
|
19
|
+
React.startTransition(() => {
|
|
20
|
+
root.render(app);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
15
23
|
} else {
|
|
16
24
|
CopyReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = true;
|
|
17
25
|
const { createRoot } = CopyReactDOM;
|
|
@@ -29,6 +37,12 @@ function hydrate(app, container, renderOptions = {}) {
|
|
|
29
37
|
const { useLegacyRender } = renderOptions;
|
|
30
38
|
if (useLegacyRender || !isReact18) {
|
|
31
39
|
reactHydrate(app, container);
|
|
40
|
+
} else if (isReact19) {
|
|
41
|
+
import('react-dom/client').then(({ hydrateRoot }) => {
|
|
42
|
+
React.startTransition(() => {
|
|
43
|
+
hydrateRoot(container, app);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
32
46
|
} else {
|
|
33
47
|
CopyReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = true;
|
|
34
48
|
const { hydrateRoot } = CopyReactDOM;
|
|
@@ -51,10 +65,6 @@ function documentReady(_passThrough) {
|
|
|
51
65
|
return Promise.resolve(_passThrough);
|
|
52
66
|
}
|
|
53
67
|
|
|
54
|
-
function Head(props) {
|
|
55
|
-
return /* @__PURE__ */ jsx(Helmet, { ...props });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
68
|
function useIsClient() {
|
|
59
69
|
const [isBrowser, setIsBrowser] = useState(false);
|
|
60
70
|
useEffect(() => {
|
|
@@ -80,4 +90,8 @@ Current type: ${isValidElement(children) ? "React element" : typeof children}`
|
|
|
80
90
|
return fallback ?? null;
|
|
81
91
|
}
|
|
82
92
|
|
|
93
|
+
function Head(props) {
|
|
94
|
+
return /* @__PURE__ */ jsx(Helmet, { ...props });
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
export { ClientOnly as C, Head as H, documentReady as d, hydrate as h, render as r };
|
package/dist/tanstack.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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.
|
|
4
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.BrImbdZU.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.BrImbdZU.mjs';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.mjs';
|
|
5
|
+
import 'beasties';
|
|
5
6
|
import 'react';
|
|
6
7
|
import 'react-router-dom';
|
|
7
|
-
import 'beasties';
|
|
8
8
|
import 'react-helmet-async';
|
|
9
9
|
|
|
10
10
|
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
@@ -24,6 +24,7 @@ declare global {
|
|
|
24
24
|
interface Window {
|
|
25
25
|
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
26
26
|
__VITE_REACT_SSG_HASH__: string;
|
|
27
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
package/dist/tanstack.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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.
|
|
4
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.BrImbdZU.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.BrImbdZU.js';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.js';
|
|
5
|
+
import 'beasties';
|
|
5
6
|
import 'react';
|
|
6
7
|
import 'react-router-dom';
|
|
7
|
-
import 'beasties';
|
|
8
8
|
import 'react-helmet-async';
|
|
9
9
|
|
|
10
10
|
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
@@ -24,6 +24,7 @@ declare global {
|
|
|
24
24
|
interface Window {
|
|
25
25
|
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
26
26
|
__VITE_REACT_SSG_HASH__: string;
|
|
27
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
package/dist/tanstack.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { HelmetProvider } from 'react-helmet-async';
|
|
3
2
|
import { RouterProvider } from '@tanstack/react-router';
|
|
4
3
|
import { Meta, StartClient } from '@tanstack/start';
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
5
|
+
import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.Dx4ca9OM.mjs';
|
|
6
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Dx4ca9OM.mjs';
|
|
7
|
+
import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
|
|
7
8
|
import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
|
|
8
9
|
import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.B-j07kW6.mjs';
|
|
9
10
|
export { r as registerPaths } from './shared/vite-react-ssg.B-j07kW6.mjs';
|
|
10
|
-
import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
|
|
11
11
|
import 'react';
|
|
12
12
|
import 'react-dom';
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
19
19
|
ssrWhenDev,
|
|
20
20
|
getStyleCollector = null
|
|
21
21
|
} = options;
|
|
22
|
-
if (process.env.NODE_ENV === "development" && ssrWhenDev !==
|
|
22
|
+
if (process.env.NODE_ENV === "development" && ssrWhenDev !== undefined)
|
|
23
23
|
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`.");
|
|
24
24
|
const isClient = typeof window !== "undefined";
|
|
25
25
|
const BASE_URL = routerOptions.basename ?? "/";
|
|
@@ -71,7 +71,7 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
71
71
|
const routeData = staticLoadData?.[pathname]?.find((item) => item.id === node.id);
|
|
72
72
|
return routeData?.loaderData ?? null;
|
|
73
73
|
};
|
|
74
|
-
} :
|
|
74
|
+
} : undefined
|
|
75
75
|
);
|
|
76
76
|
const router = routerOptions.router;
|
|
77
77
|
router.options.isServer = !client;
|
|
@@ -118,7 +118,9 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
118
118
|
console.warn("[vite-react-ssg] Root container not found.");
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const context = await createRoot(true);
|
|
122
|
+
window.__VITE_REACT_SSG_CONTEXT__ = context;
|
|
123
|
+
const { router } = context;
|
|
122
124
|
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
123
125
|
if (!isSSR && process.env.NODE_ENV === "development") {
|
|
124
126
|
render(
|