vike 0.4.267-commit-83049a4 → 0.4.268-commit-45c1759
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/RenderErrorPage.js +2 -2
- package/abort.js +2 -2
- package/dist/client/__internal/index.d.ts +2 -0
- package/dist/client/__internal/index.js +3 -0
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +1 -1
- package/dist/client/runtime-client-routing/renderPageClient.js +105 -29
- package/dist/client/shared/loadPageConfigsLazyClientSide.js +0 -4
- package/dist/node/api/serverEntryDev.js +12 -0
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.d.ts +1 -1
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +2 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.js +2 -2
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginWrapServerFile.d.ts +4 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginWrapServerFile.js +29 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy.js +2 -2
- package/dist/server/__internal/fetch-deprecated.d.ts +2 -0
- package/dist/server/__internal/fetch-deprecated.js +6 -0
- package/dist/server/__internal/fetch.js +5 -0
- package/dist/server/__internal/index.d.ts +3 -0
- package/dist/server/__internal/index.js +6 -0
- package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.js +4 -4
- package/dist/server/runtime/renderPageServer.js +3 -1
- package/dist/types/Config.d.ts +1 -1
- package/dist/types/Server.d.ts +1 -1
- package/dist/types/VikeNamespace.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/fetch.js +2 -2
- package/modifyUrl.js +2 -2
- package/package.json +23 -8
- package/routing.js +2 -2
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.d.ts +0 -4
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.js +0 -22
- package/dist/server/runtime/fetch.js +0 -5
- /package/dist/server/{runtime → __internal}/fetch.d.ts +0 -0
package/RenderErrorPage.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Some tools still need this as of January 2025
|
|
2
|
-
export * from './dist/shared/RenderErrorPage.js'
|
|
3
|
-
export { default } from './dist/shared/RenderErrorPage.js'
|
|
2
|
+
export * from './dist/shared-server-client/RenderErrorPage.js'
|
|
3
|
+
export { default } from './dist/shared-server-client/RenderErrorPage.js'
|
package/abort.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Some tools still need this as of January 2025
|
|
2
|
-
export * from './dist/shared/abort.js'
|
|
3
|
-
export { default } from './dist/shared/abort.js'
|
|
2
|
+
export * from './dist/shared-server-client/abort.js'
|
|
3
|
+
export { default } from './dist/shared-server-client/abort.js'
|
|
@@ -790,7 +790,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
790
790
|
declare global {
|
|
791
791
|
var _vike: VikeGlobalInternal;
|
|
792
792
|
}
|
|
793
|
-
declare function disableClientRouting(err: unknown,
|
|
793
|
+
declare function disableClientRouting(err: unknown, logError: boolean): void;
|
|
794
794
|
declare function getRenderCount(): number;
|
|
795
795
|
/**
|
|
796
796
|
* Get the `pageContext` object on the client-side.
|
|
@@ -526,21 +526,12 @@ function stampFinished(urlOriginal) {
|
|
|
526
526
|
window._vike ?? (window._vike = {});
|
|
527
527
|
window._vike.fullyRenderedUrl = urlOriginal;
|
|
528
528
|
}
|
|
529
|
-
function disableClientRouting(err,
|
|
529
|
+
function disableClientRouting(err, logError) {
|
|
530
530
|
globalObject.clientRoutingIsDisabled = true;
|
|
531
531
|
assert(isErrorFetchingStaticAssets(err));
|
|
532
|
-
if (
|
|
533
|
-
// We purposely don't use console.error() to avoid flooding error trackers such as Sentry
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
assertInfo(false, [
|
|
537
|
-
'Failed to fetch static asset.',
|
|
538
|
-
import.meta.env.PROD ? 'This usually happens when a new frontend is deployed.' : null,
|
|
539
|
-
'Falling back to Server Routing.',
|
|
540
|
-
'(The next page navigation will use Server Routing instead of Client Routing.)',
|
|
541
|
-
]
|
|
542
|
-
.filter(Boolean)
|
|
543
|
-
.join(' '), { onlyOnce: true });
|
|
532
|
+
if (logError)
|
|
533
|
+
console.log(err); // We purposely don't use console.error() to avoid flooding error trackers such as Sentry
|
|
534
|
+
assertInfo(false, 'Failed to fetch static asset (due to a connection issue, or a new deployment) — falling back to Server Routing', { onlyOnce: true });
|
|
544
535
|
}
|
|
545
536
|
function getIsRenderOutdated() {
|
|
546
537
|
const renderNumber = ++globalObject.renderCounter;
|
|
@@ -627,17 +618,14 @@ async function loadPageConfigsLazyClientSideAndExecHook(pageContext, isFirstRend
|
|
|
627
618
|
catch (err_) {
|
|
628
619
|
err = err_;
|
|
629
620
|
hasErr = true;
|
|
630
|
-
if (handleErrorFetchingStaticAssets(err, pageContext, isFirstRender)) {
|
|
631
|
-
return { skip: true };
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
// Syntax error in user file
|
|
635
|
-
}
|
|
636
621
|
}
|
|
637
622
|
if (isRenderOutdated())
|
|
638
623
|
return { skip: true };
|
|
639
|
-
if (hasErr)
|
|
624
|
+
if (hasErr) {
|
|
625
|
+
if (await handleErrorFetchingStaticAssets(err, pageContext, isFirstRender))
|
|
626
|
+
return { skip: true };
|
|
640
627
|
return { err };
|
|
628
|
+
}
|
|
641
629
|
objectAssign(pageContext, pageContextAddendum);
|
|
642
630
|
try {
|
|
643
631
|
await execHook('onCreatePageContext', pageContext, getPageContextPublicClient);
|
|
@@ -652,21 +640,109 @@ async function loadPageConfigsLazyClientSideAndExecHook(pageContext, isFirstRend
|
|
|
652
640
|
return { err };
|
|
653
641
|
return { pageContext };
|
|
654
642
|
}
|
|
655
|
-
function handleErrorFetchingStaticAssets(err, pageContext, isFirstRender) {
|
|
656
|
-
if (
|
|
643
|
+
async function handleErrorFetchingStaticAssets(err, pageContext, isFirstRender) {
|
|
644
|
+
if (import.meta.env.DEV)
|
|
657
645
|
return false;
|
|
658
|
-
|
|
659
|
-
|
|
646
|
+
if (!isErrorFetchingStaticAssets(err))
|
|
647
|
+
return false; // Syntax error in user file
|
|
648
|
+
// *******************************************
|
|
649
|
+
// ******* The three possible actions ********
|
|
650
|
+
// *******************************************
|
|
651
|
+
/** Show Vike's error page */
|
|
652
|
+
const showErrorPage = () => {
|
|
660
653
|
disableClientRouting(err, false);
|
|
661
|
-
//
|
|
662
|
-
|
|
654
|
+
// Vike handles the error like any other error: Vike logs it with `console.error()` and renders Vike's error page
|
|
655
|
+
return false;
|
|
656
|
+
};
|
|
657
|
+
/** Show the rendered HTML (with broken hydration) */
|
|
658
|
+
const showCurrentBrokenPage = () => {
|
|
659
|
+
disableClientRouting(err, false);
|
|
660
|
+
// Abort rendering (and don't show error page), not gracefully: the error throws (i.e. the error is handled by the browser and shown in the browser's developer console)
|
|
663
661
|
throw err;
|
|
662
|
+
};
|
|
663
|
+
/** Do a full (re-)load of the page */
|
|
664
|
+
const hardReload = (url) => {
|
|
665
|
+
disableClientRouting(err, true);
|
|
666
|
+
if (url) {
|
|
667
|
+
redirectHard(url);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
// We use `location.reload()` instead of redirectHard(): navigating with `location.href = url` creates a `type: 'navigate'` entry, which would lead to an infinite reload loop — see isPageReload()
|
|
671
|
+
window.location.reload();
|
|
672
|
+
}
|
|
673
|
+
// Abort rendering (and don't show error page), gracefully (i.e. without throwing nor logging any error)
|
|
674
|
+
return true;
|
|
675
|
+
};
|
|
676
|
+
// **************************
|
|
677
|
+
// ******* The logic ********
|
|
678
|
+
// **************************
|
|
679
|
+
// Possible causes that lead to this point:
|
|
680
|
+
// - New deployment
|
|
681
|
+
// - Connection problem
|
|
682
|
+
// === Client-side navigation ===
|
|
683
|
+
// We hard load the next page:
|
|
684
|
+
// - New deployment => fully reloading the website is exactly what we want
|
|
685
|
+
// - Connection problem => next page isn't shown => only useful action is to try again with a hard reload
|
|
686
|
+
// - It's usually better to show the browser's offline page than to leave the user stuck on the old page. (This way, the user knows there's a connection problem instead of wondering whether the website is broken.)
|
|
687
|
+
if (!isFirstRender) {
|
|
688
|
+
return hardReload(pageContext.urlOriginal);
|
|
689
|
+
}
|
|
690
|
+
// === First render ===
|
|
691
|
+
// Avoid infinite reload loop: we don't reload a page that was itself loaded by a reload
|
|
692
|
+
if (isPageReload()) {
|
|
693
|
+
if (isBlankPage()) {
|
|
694
|
+
return showErrorPage();
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
return showCurrentBrokenPage();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (isBlankPage()) {
|
|
701
|
+
return hardReload();
|
|
664
702
|
}
|
|
665
703
|
else {
|
|
666
|
-
|
|
704
|
+
globalObject.clientRoutingIsDisabled = true; // Eagerly disable before connection check
|
|
705
|
+
if (!(await isConnectionDown())) {
|
|
706
|
+
// Most likely a new deployment (or the connection is back): either way, reloading fixes the page
|
|
707
|
+
return hardReload();
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
// - Reloading is counterproductive since it would likely get another connection error, resulting in either: the browser's offline page, or repeating this asset loading failure.
|
|
711
|
+
// - Handling flaky connections is the browser's job (e.g. the user reloads the page)
|
|
712
|
+
// - Showing the rendered HTML is usually more useful to the user (even when unhydrated thus broken) than showing Vike's error page
|
|
713
|
+
return showCurrentBrokenPage();
|
|
714
|
+
}
|
|
667
715
|
}
|
|
668
|
-
|
|
669
|
-
|
|
716
|
+
}
|
|
717
|
+
// Whether fetching static assets fails because of the connection. (The error thrown by `import()` doesn't tell: it's the same whether a new frontend was deployed, i.e. the static assets don't exist anymore, or the connection is down.)
|
|
718
|
+
async function isConnectionDown() {
|
|
719
|
+
try {
|
|
720
|
+
await fetch(window.location.href, {
|
|
721
|
+
method: 'HEAD',
|
|
722
|
+
cache: 'no-store',
|
|
723
|
+
// On a flaky connection, the request may hang and succeed much later: we don't want to reload the page long after it was shown (e.g. while the user is filling a form)
|
|
724
|
+
signal: AbortSignal.timeout(4000),
|
|
725
|
+
});
|
|
726
|
+
// The server responds
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
catch {
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
// The page shows nothing (e.g. SPA)
|
|
734
|
+
function isBlankPage() {
|
|
735
|
+
return !document.body.innerText.trim();
|
|
736
|
+
}
|
|
737
|
+
// Whether the current page was loaded by a page reload
|
|
738
|
+
function isPageReload() {
|
|
739
|
+
// The browser records how the current document was loaded (Navigation Timing API)
|
|
740
|
+
const navigation = performance.getEntriesByType('navigation')[0];
|
|
741
|
+
return (
|
|
742
|
+
// Cannot be determined (e.g. older browsers)
|
|
743
|
+
!navigation ||
|
|
744
|
+
// A document loaded by `location.reload()` has `type: 'reload'`
|
|
745
|
+
navigation.type === 'reload');
|
|
670
746
|
}
|
|
671
747
|
// [HMR] If error page is shown => re-render whole page
|
|
672
748
|
if (import.meta.env.DEV && import.meta.hot)
|
|
@@ -53,10 +53,6 @@ function isFetchError(err) {
|
|
|
53
53
|
'error loading dynamically imported module',
|
|
54
54
|
// safari
|
|
55
55
|
'Importing a module script failed',
|
|
56
|
-
// ??
|
|
57
|
-
'error resolving module specifier',
|
|
58
|
-
// ??
|
|
59
|
-
'failed to resolve module',
|
|
60
56
|
];
|
|
61
57
|
return FAILED_TO_FETCH_MESSAGES.some((s) => err.message.toLowerCase().includes(s.toLowerCase()));
|
|
62
58
|
}
|
|
@@ -61,6 +61,7 @@ async function startServerEntry_child(viteServer, serverEntryFilePath) {
|
|
|
61
61
|
restartOnFileChange(viteServer, (filePath) => isImportedBy(ssr.moduleGraph.getModulesByFile(filePath), serverEntryFilePath));
|
|
62
62
|
// The user's server uses the current Vite development server (e.g. `app.use(devMiddleware)`) => we restart the process instead of letting Vite restart itself (e.g. upon vite.config.js changes)
|
|
63
63
|
viteServer.restart = async () => restart('Vite needs to restart');
|
|
64
|
+
closeOnSignal(viteServer);
|
|
64
65
|
try {
|
|
65
66
|
// Same module runner as the one Vike uses to load pages (`ssrLoadModule()`) => a module imported by both +serverEntry.js and a page is instantiated only once (like in production)
|
|
66
67
|
await viteServer.ssrLoadModule(serverEntryFilePath);
|
|
@@ -80,6 +81,17 @@ function restartOnFileChange(viteServer, isRestartNeeded) {
|
|
|
80
81
|
viteServer.watcher.on('change', onFileChange);
|
|
81
82
|
viteServer.watcher.on('unlink', onFileChange);
|
|
82
83
|
}
|
|
84
|
+
// The user's server may handle SIGINT/SIGTERM without exiting the process (e.g. graceful shutdown: close the server and let the process exit once it's idle) => close Vite's development server, otherwise it keeps the process alive
|
|
85
|
+
function closeOnSignal(viteServer) {
|
|
86
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
87
|
+
process.once(signal, () => {
|
|
88
|
+
void viteServer.close();
|
|
89
|
+
// Listening to a signal disables Node.js's default behavior of terminating the process => if the user's server doesn't listen to it, then we terminate the process ourselves
|
|
90
|
+
if (process.listenerCount(signal) === 0)
|
|
91
|
+
process.kill(process.pid, signal);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
83
95
|
function restart(reason) {
|
|
84
96
|
assertInfo(false, `${reason}, restarting server...`, { onlyOnce: false });
|
|
85
97
|
process.exit(EXIT_CODE_RESTART);
|
|
@@ -4,7 +4,7 @@ import type { ResolvedConfig } from 'vite';
|
|
|
4
4
|
import '../../assertEnvVite.js';
|
|
5
5
|
declare const optimizeDeps: {
|
|
6
6
|
readonly optimizeDeps: {
|
|
7
|
-
readonly exclude: ["vike/client", "vike/client/router"];
|
|
7
|
+
readonly exclude: ["vike/client", "vike/client/router", "vike/__internal/client"];
|
|
8
8
|
readonly include: ["vike > @brillout/json-serializer/parse", "vike > @brillout/json-serializer/stringify", "vike > @brillout/picocolors"];
|
|
9
9
|
};
|
|
10
10
|
readonly ssr: {
|
|
@@ -43,6 +43,8 @@ const optimizeDeps = {
|
|
|
43
43
|
// We must exclude Vike's client runtime so it can import virtual modules
|
|
44
44
|
'vike/client',
|
|
45
45
|
'vike/client/router',
|
|
46
|
+
// Also all entries of Vike's client runtime, otherwise pre-bundling an entry would load a second copy of Vike's client code (also problematic as it duplicates module-level variables that don't use `getGlobalObject()`)
|
|
47
|
+
'vike/__internal/client',
|
|
46
48
|
],
|
|
47
49
|
include: [
|
|
48
50
|
// Avoid:
|
|
@@ -30,14 +30,14 @@ function getServerConfig(vikeConfig) {
|
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
32
|
serverEntryId = catchAllEntry;
|
|
33
|
-
serverEntryVike = 'vike/fetch';
|
|
33
|
+
serverEntryVike = 'vike/__internal/fetch';
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
// Used to filter which module ID to transform.
|
|
37
37
|
// It points to a fully resolved server entry or the virtual universal-deploy catchAll entry.
|
|
38
38
|
serverEntryId,
|
|
39
39
|
// This entry will be pushed to universal-deploy via `addEntry`.
|
|
40
|
-
// It either points to the default fetchable endpoint (vike/fetch), or one defined by the user through +server.
|
|
40
|
+
// It either points to the default fetchable endpoint (vike/__internal/fetch), or one defined by the user through +server.
|
|
41
41
|
serverEntryVike,
|
|
42
42
|
serverFilePath,
|
|
43
43
|
// +serverEntry.js => it's the production server entry dist/server/index.mjs (instead of @universal-deploy/node's)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { pluginWrapServerFile };
|
|
2
|
+
import { wrapper } from 'vite-plugin-wrapper';
|
|
3
|
+
import { escapeRegex } from '../../../../utils/escapeRegex.js';
|
|
4
|
+
import '../../assertEnvVite.js';
|
|
5
|
+
function pluginWrapServerFile(serverFilePath) {
|
|
6
|
+
return wrapper({
|
|
7
|
+
resolveId: {
|
|
8
|
+
filter: {
|
|
9
|
+
id: new RegExp(`${escapeRegex(serverFilePath)}$`),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
load(id) {
|
|
13
|
+
return [
|
|
14
|
+
// === Side exports
|
|
15
|
+
`export * from ${JSON.stringify(id)};`,
|
|
16
|
+
'',
|
|
17
|
+
// === Default export
|
|
18
|
+
// `vikeFetch` acts as fallback if the user's +server.js doesn't export `fetch`
|
|
19
|
+
// - Example: https://vike.dev/cloudflare#durable-objects
|
|
20
|
+
// - Bloat (when `vikeFetch` isn't used) is negligible
|
|
21
|
+
"import vikeFetch from 'vike/__internal/fetch';",
|
|
22
|
+
`import * as mod from ${JSON.stringify(id)};`,
|
|
23
|
+
// Destructured because mod.default makes Rolldown warn when +server.js has no default export
|
|
24
|
+
'const { default: server } = mod;',
|
|
25
|
+
'export default { ...server, ...server?.prod, fetch: server?.fetch ?? vikeFetch.fetch };',
|
|
26
|
+
].join('\n');
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -8,7 +8,7 @@ import { pluginCommon } from './pluginUniversalDeploy/common.js';
|
|
|
8
8
|
import { hasVikeServerOrVikePhoton } from './pluginUniversalDeploy/detectDeprecated.js';
|
|
9
9
|
import { getServerConfig, getServerEntryFilePath_ifDev } from './pluginUniversalDeploy/getServerConfig.js';
|
|
10
10
|
import { pluginServerEntryAlias } from './pluginUniversalDeploy/pluginServerEntryAlias.js';
|
|
11
|
-
import {
|
|
11
|
+
import { pluginWrapServerFile } from './pluginUniversalDeploy/pluginWrapServerFile.js';
|
|
12
12
|
import { getViteCliCommand } from '../shared/isViteCli.js';
|
|
13
13
|
import { unique } from '../../../utils/unique.js';
|
|
14
14
|
import { assertUsage } from '../../../utils/assert.js';
|
|
@@ -79,6 +79,6 @@ function pluginUniversalDeploy(vikeConfig) {
|
|
|
79
79
|
},
|
|
80
80
|
pluginServerEntryInject(serverFilePath ?? serverEntryId),
|
|
81
81
|
pluginServerEntryAlias(serverFilePath),
|
|
82
|
-
!serverFilePath ? null :
|
|
82
|
+
!serverFilePath ? null : pluginWrapServerFile(serverFilePath),
|
|
83
83
|
].filter((p) => p !== null);
|
|
84
84
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default } from './fetch.js';
|
|
2
|
+
// TO-DO/next-major-release: remove this export (the entire file)
|
|
3
|
+
import { assertWarning } from '../../utils/assert.js';
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
import '../assertEnvServer.js';
|
|
6
|
+
assertWarning(false, `${pc.cyan("import vike from 'vike/fetch'")} is deprecated, see ${pc.underline('https://vike.dev/migration/vike-fetch')}`, { onlyOnce: true });
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { setGlobalContext_prodBuildEntry } from '../runtime/globalContext.js';
|
|
2
2
|
export { getMiddlewaresPipe_nonHandlers, getMiddlewaresPipe_handlers, } from '../runtime/universal-middleware/getMiddlewaresPipe.js';
|
|
3
|
+
export { getPageContextJson };
|
|
3
4
|
export { route, getPagesAndRoutes };
|
|
4
5
|
export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
|
|
5
6
|
import { route as routeInternal, type PageRoutes } from '../../shared-server-client/route/index.js';
|
|
6
7
|
import type { PageFile } from '../../shared-server-client/getPageFiles/getPageFileObject.js';
|
|
7
8
|
import { PageConfigRuntime } from '../../types/PageConfig.js';
|
|
9
|
+
import type { PageContextServer } from '../../types/PageContext.js';
|
|
8
10
|
import '../assertEnvServer.js';
|
|
9
11
|
/**
|
|
10
12
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
@@ -20,3 +22,4 @@ declare function getPagesAndRoutes(): Promise<{
|
|
|
20
22
|
declare function route(pageContext: Parameters<typeof routeInternal>[0]): Promise<{
|
|
21
23
|
pageContextAddendum: import("../../shared-server-client/route/index.js").PageContextAfterRoute;
|
|
22
24
|
}>;
|
|
25
|
+
declare function getPageContextJson(pageContext: PageContextServer): string | ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
export { setGlobalContext_prodBuildEntry } from '../runtime/globalContext.js';
|
|
3
3
|
// Used by the vike(app) of the @vikejs/* server adapters
|
|
4
4
|
export { getMiddlewaresPipe_nonHandlers, getMiddlewaresPipe_handlers, } from '../runtime/universal-middleware/getMiddlewaresPipe.js';
|
|
5
|
+
// Used by vike-react-rsc
|
|
6
|
+
export { getPageContextJson };
|
|
5
7
|
// Used by vite-plugin-vercel
|
|
6
8
|
export { route, getPagesAndRoutes };
|
|
7
9
|
import { route as routeInternal } from '../../shared-server-client/route/index.js';
|
|
8
10
|
import { getGlobalContextServerInternal, initGlobalContext_getPagesAndRoutes } from '../runtime/globalContext.js';
|
|
9
11
|
import { setNodeEnvProductionIfUndefined } from '../../utils/assertSetup.js';
|
|
12
|
+
import { getPageContextJson as getPageContextJsonInternal } from '../runtime/renderPageServer/getPageContextJson.js';
|
|
10
13
|
import '../assertEnvServer.js';
|
|
11
14
|
/**
|
|
12
15
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
@@ -32,3 +35,6 @@ async function route(pageContext) {
|
|
|
32
35
|
// Old interface
|
|
33
36
|
return { pageContextAddendum: pageContextFromRoute };
|
|
34
37
|
}
|
|
38
|
+
function getPageContextJson(pageContext) {
|
|
39
|
+
return getPageContextJsonInternal(pageContext);
|
|
40
|
+
}
|
|
@@ -79,10 +79,6 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
79
79
|
let pageContextPromise = null;
|
|
80
80
|
let pageContextProvidedByRenderHook = null;
|
|
81
81
|
let injectFilter = null;
|
|
82
|
-
if (isDocumentHtml(hookReturnValue)) {
|
|
83
|
-
documentHtml = hookReturnValue;
|
|
84
|
-
return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
|
|
85
|
-
}
|
|
86
82
|
const errPrefix = `The ${renderHook.hookName}() hook defined at ${renderHook.hookFilePath}`;
|
|
87
83
|
const errSuffix = `a string generated with ${pc.cyan('escapeInject`<html>...</html>`')} or the value returned by ${pc.cyan('dangerouslySkipEscape()')}, see https://vike.dev/escapeInject`;
|
|
88
84
|
if (typeof hookReturnValue === 'string') {
|
|
@@ -93,6 +89,10 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
93
89
|
].join(' '), { onlyOnce: true });
|
|
94
90
|
hookReturnValue = dangerouslySkipEscape(hookReturnValue);
|
|
95
91
|
}
|
|
92
|
+
if (isDocumentHtml(hookReturnValue)) {
|
|
93
|
+
documentHtml = hookReturnValue;
|
|
94
|
+
return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
|
|
95
|
+
}
|
|
96
96
|
const wrongReturnValue = `should return the value ${pc.cyan('documentHtml')} or an object ${pc.cyan('{ documentHtml }')} where ${pc.cyan('documentHtml')} is ${errSuffix}`;
|
|
97
97
|
assertUsage(isObject(hookReturnValue), `${errPrefix} ${wrongReturnValue}`);
|
|
98
98
|
assertHookReturnedObject(hookReturnValue, ['documentHtml', 'pageContext', 'injectFilter'], errPrefix);
|
|
@@ -422,7 +422,7 @@ async function getPermanentRedirect(pageContextBegin, globalContext) {
|
|
|
422
422
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
423
423
|
return null;
|
|
424
424
|
if (!originChanged)
|
|
425
|
-
urlTarget =
|
|
425
|
+
urlTarget = modifyUrlPathname(urlTarget, (urlPathname) => prependBase(urlPathname, globalContext.baseServer));
|
|
426
426
|
assert(urlTarget !== pageContext.urlOriginal);
|
|
427
427
|
}
|
|
428
428
|
logRuntimeInfo?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, pageContext, 'info');
|
|
@@ -454,6 +454,8 @@ pageContextNominalPageBegin, requestId, pageContextErrorPageInit, globalContext)
|
|
|
454
454
|
assertUsage(errorPageId, `You called ${pc.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
455
455
|
objectAssign(pageContext, { pageId: errorPageId });
|
|
456
456
|
objectAssign(pageContext, pageContextErrorPageInit, true);
|
|
457
|
+
// Overrides `is404: false` of pageContextErrorPageInit, e.g. `throw render(404)` => `is404: true`
|
|
458
|
+
objectAssign(pageContext, pageContextAbort);
|
|
457
459
|
updateType(pageContext, await loadPageConfigsLazyServerSide(pageContext));
|
|
458
460
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
459
461
|
pageContextJson = getPageContextJson(pageContext);
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -542,7 +542,7 @@ type ConfigBuiltIn = {
|
|
|
542
542
|
*
|
|
543
543
|
* https://vike.dev/middleware
|
|
544
544
|
*/
|
|
545
|
-
middleware?: EnhancedMiddleware | EnhancedMiddleware[];
|
|
545
|
+
middleware?: EnhancedMiddleware | EnhancedMiddleware[] | ImportStringList;
|
|
546
546
|
/**
|
|
547
547
|
* Set to `false` to disable Vike's automatic server integration mechanism (e.g. for integrating a JavaScript server manually via `renderPage()`).
|
|
548
548
|
*
|
package/dist/types/Server.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Fetchable, ServerOptions } from '@universal-deploy/store';
|
|
|
5
5
|
*
|
|
6
6
|
* https://vike.dev/server
|
|
7
7
|
*/
|
|
8
|
-
interface Server extends Fetchable {
|
|
8
|
+
interface Server extends Partial<Fetchable> {
|
|
9
9
|
prod?: Omit<ServerOptions, 'fetch'> & {
|
|
10
10
|
static?: boolean | string;
|
|
11
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: '0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: '0.4.268-commit-45c1759';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.268-commit-45c1759';
|
package/fetch.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Some tools still need this as of January 2025
|
|
2
|
-
export * from './dist/server/
|
|
3
|
-
export { default } from './dist/server/
|
|
2
|
+
export * from './dist/server/__internal/fetch-deprecated.js'
|
|
3
|
+
export { default } from './dist/server/__internal/fetch-deprecated.js'
|
package/modifyUrl.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Some tools still need this as of January 2025
|
|
2
|
-
export * from './dist/shared/modifyUrl.js'
|
|
3
|
-
export { default } from './dist/shared/modifyUrl.js'
|
|
2
|
+
export * from './dist/shared-server-client/modifyUrl.js'
|
|
3
|
+
export { default } from './dist/shared-server-client/modifyUrl.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.268-commit-45c1759",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -95,18 +95,27 @@
|
|
|
95
95
|
"default": "./dist/server/runtime/universal-middleware/deprecated-export.js"
|
|
96
96
|
},
|
|
97
97
|
"./fetch": {
|
|
98
|
-
"types": "./dist/server/
|
|
99
|
-
"worker": "./dist/server/
|
|
100
|
-
"workerd": "./dist/server/
|
|
101
|
-
"node": "./dist/server/
|
|
98
|
+
"types": "./dist/server/__internal/fetch-deprecated.d.ts",
|
|
99
|
+
"worker": "./dist/server/__internal/fetch-deprecated.js",
|
|
100
|
+
"workerd": "./dist/server/__internal/fetch-deprecated.js",
|
|
101
|
+
"node": "./dist/server/__internal/fetch-deprecated.js",
|
|
102
102
|
"browser": "./dist/client/node.js",
|
|
103
|
-
"default": "./dist/server/
|
|
103
|
+
"default": "./dist/server/__internal/fetch-deprecated.js"
|
|
104
104
|
},
|
|
105
105
|
"./__internal": {
|
|
106
106
|
"types": "./dist/server/__internal/index.d.ts",
|
|
107
107
|
"node": "./dist/server/__internal/index.js",
|
|
108
108
|
"default": "./dist/server/__internal/index.js"
|
|
109
109
|
},
|
|
110
|
+
"./__internal/client": {
|
|
111
|
+
"types": "./dist/client/__internal/index.d.ts",
|
|
112
|
+
"default": "./dist/client/__internal/index.js"
|
|
113
|
+
},
|
|
114
|
+
"./__internal/fetch": {
|
|
115
|
+
"types": "./dist/server/__internal/fetch.d.ts",
|
|
116
|
+
"node": "./dist/server/__internal/fetch.js",
|
|
117
|
+
"default": "./dist/server/__internal/fetch.js"
|
|
118
|
+
},
|
|
110
119
|
"./__internal/setup": {
|
|
111
120
|
"types": "./dist/server/runtime/page-files/setup.d.ts",
|
|
112
121
|
"node": "./dist/server/runtime/page-files/setup.js",
|
|
@@ -130,7 +139,7 @@
|
|
|
130
139
|
"@brillout/vite-plugin-server-entry": "^0.7.23",
|
|
131
140
|
"@universal-deploy/store": "^0.3.0",
|
|
132
141
|
"@universal-deploy/vite": "^0.2.2",
|
|
133
|
-
"@universal-middleware/core": "^0.7.
|
|
142
|
+
"@universal-middleware/core": "^0.7.1",
|
|
134
143
|
"@universal-middleware/node": "^0.2.9",
|
|
135
144
|
"cac": "^6.0.0",
|
|
136
145
|
"convert-route": "^2.0.0",
|
|
@@ -219,11 +228,17 @@
|
|
|
219
228
|
"./dist/server/runtime/universal-middleware/deprecated-export.d.ts"
|
|
220
229
|
],
|
|
221
230
|
"fetch": [
|
|
222
|
-
"./dist/server/
|
|
231
|
+
"./dist/server/__internal/fetch-deprecated.d.ts"
|
|
223
232
|
],
|
|
224
233
|
"__internal": [
|
|
225
234
|
"./dist/server/__internal/index.d.ts"
|
|
226
235
|
],
|
|
236
|
+
"__internal/client": [
|
|
237
|
+
"./dist/client/__internal/index.d.ts"
|
|
238
|
+
],
|
|
239
|
+
"__internal/fetch": [
|
|
240
|
+
"./dist/server/__internal/fetch.d.ts"
|
|
241
|
+
],
|
|
227
242
|
"__internal/setup": [
|
|
228
243
|
"./dist/server/runtime/page-files/setup.d.ts"
|
|
229
244
|
]
|
package/routing.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Some tools still need this as of January 2025
|
|
2
|
-
export * from './dist/shared/route/routing.js'
|
|
3
|
-
export { default } from './dist/shared/route/routing.js'
|
|
2
|
+
export * from './dist/shared-server-client/route/routing.js'
|
|
3
|
+
export { default } from './dist/shared-server-client/route/routing.js'
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export { pluginUnwrapProdOptions };
|
|
2
|
-
import { wrapper } from 'vite-plugin-wrapper';
|
|
3
|
-
import { escapeRegex } from '../../../../utils/escapeRegex.js';
|
|
4
|
-
import '../../assertEnvVite.js';
|
|
5
|
-
function pluginUnwrapProdOptions(serverFilePath) {
|
|
6
|
-
return wrapper({
|
|
7
|
-
resolveId: {
|
|
8
|
-
filter: {
|
|
9
|
-
id: new RegExp(escapeRegex(serverFilePath)),
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
// Unwrap all prod.* options
|
|
13
|
-
load(id) {
|
|
14
|
-
return `
|
|
15
|
-
import mod from ${JSON.stringify(id)};
|
|
16
|
-
|
|
17
|
-
export * from ${JSON.stringify(id)};
|
|
18
|
-
export default { ...mod, ...mod?.prod };
|
|
19
|
-
`;
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
}
|
|
File without changes
|