@alignable/bifrost 0.0.39 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2DSY3VFP.js +118 -0
- package/dist/chunk-2DSY3VFP.js.map +1 -0
- package/dist/chunk-5SP2QGEH.js +76 -0
- package/dist/chunk-5SP2QGEH.js.map +1 -0
- package/dist/chunk-ABLEI4J7.js +30 -0
- package/dist/chunk-ABLEI4J7.js.map +1 -0
- package/dist/{chunk-CXNEKD7R.js → chunk-K4H777XA.js} +2 -2
- package/dist/chunk-K4H777XA.js.map +1 -0
- package/dist/chunk-OXCN6F2S.js +10 -0
- package/dist/chunk-OXCN6F2S.js.map +1 -0
- package/dist/chunk-RSVASTEA.js +63 -0
- package/dist/chunk-RSVASTEA.js.map +1 -0
- package/dist/{proxy/pages/wrapped/onRenderHtml.js → chunk-SAMMNBO4.js} +14 -16
- package/dist/chunk-SAMMNBO4.js.map +1 -0
- package/dist/chunk-X2R7ODLQ.js +14 -0
- package/dist/chunk-X2R7ODLQ.js.map +1 -0
- package/dist/{chunk-4YPY5NIX.js → chunk-X3MUHPJ3.js} +18 -18
- package/dist/chunk-X3MUHPJ3.js.map +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js.map +1 -1
- package/dist/internal-837e7a40.d.ts +128 -0
- package/dist/renderer/+config.d.ts +60 -6
- package/dist/renderer/+config.js +40 -20
- package/dist/renderer/+config.js.map +1 -1
- package/dist/renderer/bifrost/onRenderClient.d.ts +9 -0
- package/dist/renderer/bifrost/onRenderClient.js +15 -0
- package/dist/renderer/bifrost/onRenderHtml.d.ts +20 -0
- package/dist/renderer/bifrost/onRenderHtml.js +13 -0
- package/dist/renderer/bifrost/onRenderHtml.js.map +1 -0
- package/dist/renderer/configs/bifrost.d.ts +50 -0
- package/dist/renderer/configs/bifrost.js +7 -0
- package/dist/renderer/configs/bifrost.js.map +1 -0
- package/dist/renderer/configs/wrapped.d.ts +25 -0
- package/dist/renderer/configs/wrapped.js +7 -0
- package/dist/renderer/configs/wrapped.js.map +1 -0
- package/dist/renderer/onBeforeRoute.d.ts +5 -4
- package/dist/renderer/onBeforeRoute.js +1 -3
- package/dist/renderer/onBeforeRoute.js.map +1 -1
- package/dist/renderer/onRenderClient.d.ts +4 -5
- package/dist/renderer/onRenderClient.js +16 -52
- package/dist/renderer/onRenderClient.js.map +1 -1
- package/dist/renderer/onRenderHtml.d.ts +21 -5
- package/dist/renderer/onRenderHtml.js +17 -63
- package/dist/renderer/onRenderHtml.js.map +1 -1
- package/dist/renderer/usePageContext.d.ts +3 -4
- package/dist/renderer/utils/PassthruLayout.d.ts +5 -0
- package/dist/renderer/utils/PassthruLayout.js +7 -0
- package/dist/renderer/utils/PassthruLayout.js.map +1 -0
- package/dist/renderer/utils/buildHead.d.ts +3 -4
- package/dist/renderer/{getConfigOrPageContext.d.ts → utils/getConfigOrPageContext.d.ts} +3 -4
- package/dist/renderer/utils/getConfigOrPageContext.js +7 -0
- package/dist/renderer/utils/getConfigOrPageContext.js.map +1 -0
- package/dist/renderer/wrapped/onRenderClient.d.ts +9 -0
- package/dist/renderer/wrapped/onRenderClient.js +13 -0
- package/dist/renderer/wrapped/onRenderClient.js.map +1 -0
- package/dist/renderer/wrapped/onRenderHtml.d.ts +25 -0
- package/dist/renderer/wrapped/onRenderHtml.js +12 -0
- package/dist/renderer/wrapped/onRenderHtml.js.map +1 -0
- package/package.json +9 -47
- package/dist/chunk-4YPY5NIX.js.map +0 -1
- package/dist/chunk-CXNEKD7R.js.map +0 -1
- package/dist/chunk-HZZHKVWB.js +0 -15
- package/dist/chunk-HZZHKVWB.js.map +0 -1
- package/dist/controller-16e58bbd.d.ts +0 -7
- package/dist/internal-44398797.d.ts +0 -109
- package/dist/proxy/pages/Page.d.ts +0 -3
- package/dist/proxy/pages/Page.js +0 -8
- package/dist/proxy/pages/Page.js.map +0 -1
- package/dist/proxy/pages/passthru/+config.d.ts +0 -8
- package/dist/proxy/pages/passthru/+config.js +0 -12
- package/dist/proxy/pages/passthru/+config.js.map +0 -1
- package/dist/proxy/pages/passthru/onRenderHtml.d.ts +0 -12
- package/dist/proxy/pages/passthru/onRenderHtml.js +0 -10
- package/dist/proxy/pages/passthru/onRenderHtml.js.map +0 -1
- package/dist/proxy/pages/wrapped/+config.d.ts +0 -25
- package/dist/proxy/pages/wrapped/+config.js +0 -19
- package/dist/proxy/pages/wrapped/+config.js.map +0 -1
- package/dist/proxy/pages/wrapped/onBeforeRender.d.ts +0 -24
- package/dist/proxy/pages/wrapped/onBeforeRender.js +0 -30
- package/dist/proxy/pages/wrapped/onBeforeRender.js.map +0 -1
- package/dist/proxy/pages/wrapped/onRenderClient.d.ts +0 -10
- package/dist/proxy/pages/wrapped/onRenderClient.js +0 -74
- package/dist/proxy/pages/wrapped/onRenderClient.js.map +0 -1
- package/dist/proxy/pages/wrapped/onRenderHtml.d.ts +0 -20
- package/dist/proxy/pages/wrapped/onRenderHtml.js.map +0 -1
- package/dist/proxy/pages/wrapped/restorationVisit/+config.d.ts +0 -24
- package/dist/proxy/pages/wrapped/restorationVisit/+config.js +0 -18
- package/dist/proxy/pages/wrapped/restorationVisit/+config.js.map +0 -1
- package/dist/proxy/pages/wrapped/restorationVisit/onRenderClient.d.ts +0 -10
- package/dist/proxy/pages/wrapped/restorationVisit/onRenderClient.js +0 -54
- package/dist/proxy/pages/wrapped/restorationVisit/onRenderClient.js.map +0 -1
- package/dist/proxy/pages/wrapped/restorationVisit/route.d.ts +0 -3
- package/dist/proxy/pages/wrapped/restorationVisit/route.js +0 -8
- package/dist/proxy/pages/wrapped/restorationVisit/route.js.map +0 -1
- package/dist/renderer/getConfigOrPageContext.js +0 -7
- /package/dist/renderer/{getConfigOrPageContext.js.map → bifrost/onRenderClient.js.map} +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Turbolinks,
|
|
3
|
+
copyElementAttributes,
|
|
4
|
+
renderReact
|
|
5
|
+
} from "./chunk-X3MUHPJ3.js";
|
|
6
|
+
import {
|
|
7
|
+
getElementAttributes
|
|
8
|
+
} from "./chunk-RQ34EW7E.js";
|
|
9
|
+
import {
|
|
10
|
+
PageShell
|
|
11
|
+
} from "./chunk-JHLK62FM.js";
|
|
12
|
+
|
|
13
|
+
// renderer/wrapped/onRenderClient.tsx
|
|
14
|
+
import React from "react";
|
|
15
|
+
var PassThruLayout = ({
|
|
16
|
+
children
|
|
17
|
+
}) => /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
18
|
+
async function wrappedOnRenderClient(pageContext) {
|
|
19
|
+
if ("snapshot" in pageContext) {
|
|
20
|
+
return onRenderClientRestorationVisit(pageContext);
|
|
21
|
+
} else if (pageContext.isHydration) {
|
|
22
|
+
return onRenderClientHydration(pageContext);
|
|
23
|
+
} else {
|
|
24
|
+
return onRenderClientNavigation(pageContext);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function onRenderClientHydration(pageContext) {
|
|
28
|
+
const { layoutProps, layout } = pageContext;
|
|
29
|
+
await pageContext.config.onClientInit?.();
|
|
30
|
+
const bodyEl = document.getElementById("proxied-body");
|
|
31
|
+
render({
|
|
32
|
+
html: bodyEl.innerHTML,
|
|
33
|
+
layout,
|
|
34
|
+
layoutProps,
|
|
35
|
+
bodyEl,
|
|
36
|
+
pageContext
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function onRenderClientNavigation(pageContext) {
|
|
40
|
+
const resp = await fetch(pageContext.urlOriginal, {
|
|
41
|
+
headers: { ...pageContext.config.proxyHeaders, accept: "text/html" }
|
|
42
|
+
});
|
|
43
|
+
if (resp.redirected) {
|
|
44
|
+
Turbolinks.visit(resp.url);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!resp.ok) {
|
|
48
|
+
window.location.href = resp.url;
|
|
49
|
+
}
|
|
50
|
+
const html = await resp.text();
|
|
51
|
+
const { layout, layoutProps } = pageContext.config.getLayout(
|
|
52
|
+
Object.fromEntries(resp.headers.entries())
|
|
53
|
+
);
|
|
54
|
+
const parsed = document.createElement("html");
|
|
55
|
+
parsed.innerHTML = html;
|
|
56
|
+
const bodyEl = parsed.querySelector("body");
|
|
57
|
+
const headEl = parsed.querySelector("head");
|
|
58
|
+
Turbolinks._vpsOnRenderClient(headEl, true, true, () => {
|
|
59
|
+
document.body.getAttributeNames().forEach((n) => document.body.removeAttribute(n));
|
|
60
|
+
copyElementAttributes(document.body, bodyEl);
|
|
61
|
+
render({
|
|
62
|
+
html: bodyEl.innerHTML,
|
|
63
|
+
layout,
|
|
64
|
+
layoutProps,
|
|
65
|
+
bodyEl,
|
|
66
|
+
pageContext
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function onRenderClientRestorationVisit(pageContext) {
|
|
71
|
+
if (pageContext.isHydration) {
|
|
72
|
+
throw new Error("restoration visit should never happen on initial render");
|
|
73
|
+
}
|
|
74
|
+
const { layoutProps, layout } = pageContext.snapshot.pageContext;
|
|
75
|
+
const { bodyEl, headEl } = pageContext.snapshot;
|
|
76
|
+
const proxyBodyEl = bodyEl.querySelector("#proxied-body");
|
|
77
|
+
if (!proxyBodyEl) {
|
|
78
|
+
throw new Error("proxied body not found in cached snapshot");
|
|
79
|
+
}
|
|
80
|
+
Turbolinks._vpsOnRenderClient(headEl, true, true, () => {
|
|
81
|
+
document.body.getAttributeNames().forEach((n) => document.body.removeAttribute(n));
|
|
82
|
+
copyElementAttributes(document.body, bodyEl);
|
|
83
|
+
render({
|
|
84
|
+
html: proxyBodyEl.innerHTML,
|
|
85
|
+
layout,
|
|
86
|
+
layoutProps,
|
|
87
|
+
bodyEl,
|
|
88
|
+
pageContext
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function render({
|
|
93
|
+
html,
|
|
94
|
+
layout,
|
|
95
|
+
layoutProps,
|
|
96
|
+
bodyEl,
|
|
97
|
+
pageContext
|
|
98
|
+
}) {
|
|
99
|
+
const { layoutMap } = pageContext.config;
|
|
100
|
+
if (!layoutMap) {
|
|
101
|
+
throw new Error("layoutMap needs to be defined in config");
|
|
102
|
+
}
|
|
103
|
+
const Layout = layoutMap[layout] || PassThruLayout;
|
|
104
|
+
renderReact(
|
|
105
|
+
/* @__PURE__ */ React.createElement(PageShell, { key: pageContext.urlOriginal, pageContext }, /* @__PURE__ */ React.createElement(Layout, { ...layoutProps }, /* @__PURE__ */ React.createElement("div", { id: "proxied-body", dangerouslySetInnerHTML: { __html: html } }))),
|
|
106
|
+
pageContext.isHydration
|
|
107
|
+
);
|
|
108
|
+
Turbolinks._vpsCachePageContext({
|
|
109
|
+
layoutProps,
|
|
110
|
+
layout,
|
|
111
|
+
bodyAttrs: getElementAttributes(bodyEl)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
wrappedOnRenderClient
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=chunk-2DSY3VFP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/wrapped/onRenderClient.tsx"],"sourcesContent":["import React, { PropsWithChildren } from \"react\";\nimport {\n AugmentMe,\n PageContextProxyClient,\n PageContextProxyClientHydration,\n PageContextProxyClientNavigation,\n PageContextProxyClientRestorationVisit,\n} from \"../../types/internal\";\nimport { PageShell } from \"../../lib/PageShell\";\nimport { getElementAttributes } from \"../../lib/getElementAttributes\";\nimport { renderReact } from \"../../lib/renderReact\";\nimport { Turbolinks } from \"../../lib/turbolinks\";\nimport { copyElementAttributes } from \"../../lib/turbolinks/util\";\n\nconst PassThruLayout: React.ComponentType<PropsWithChildren> = ({\n children,\n}) => <>{children}</>;\n\n/* \nWe get here in 3 ways:\n1. Hydration from initial SSR\n2. Client navigation\n3. Back button restoration\n\nEach path needs to generate pageContext differently\n*/\n\nexport async function wrappedOnRenderClient(\n pageContext: PageContextProxyClient\n) {\n if (\"snapshot\" in pageContext) {\n return onRenderClientRestorationVisit(pageContext);\n } else if (pageContext.isHydration) {\n return onRenderClientHydration(pageContext);\n } else {\n return onRenderClientNavigation(pageContext);\n }\n}\n\nasync function onRenderClientHydration(\n pageContext: PageContextProxyClientHydration\n) {\n const { layoutProps, layout } = pageContext;\n\n await pageContext.config.onClientInit?.();\n const bodyEl = document.getElementById(\"proxied-body\")!;\n // During hydration of initial ssr, body is in dom, not page props (to avoid double-send)\n render({\n html: bodyEl.innerHTML,\n layout,\n layoutProps,\n bodyEl,\n pageContext,\n });\n}\n\nasync function onRenderClientNavigation(\n pageContext: PageContextProxyClientNavigation\n) {\n const resp = await fetch(pageContext.urlOriginal, {\n headers: { ...pageContext.config.proxyHeaders, accept: \"text/html\" },\n });\n\n if (resp.redirected) {\n /// Redirect /\n Turbolinks.visit(resp.url);\n return;\n }\n if (!resp.ok) {\n window.location.href = resp.url;\n }\n const html = await resp.text();\n const { layout, layoutProps } = pageContext.config.getLayout!(\n Object.fromEntries(resp.headers.entries())\n );\n\n const parsed = document.createElement(\"html\");\n parsed.innerHTML = html;\n const bodyEl = parsed.querySelector(\"body\")!;\n const headEl = parsed.querySelector(\"head\")!;\n\n Turbolinks._vpsOnRenderClient(headEl, true, true, () => {\n // merge body attributes\n document.body\n .getAttributeNames()\n .forEach((n) => document.body.removeAttribute(n));\n copyElementAttributes(document.body, bodyEl);\n // render body with react\n render({\n html: bodyEl.innerHTML,\n layout,\n layoutProps,\n bodyEl,\n pageContext,\n });\n });\n}\n\nasync function onRenderClientRestorationVisit(\n pageContext: PageContextProxyClientRestorationVisit\n) {\n if (pageContext.isHydration) {\n throw new Error(\"restoration visit should never happen on initial render\");\n }\n const { layoutProps, layout } = pageContext.snapshot.pageContext;\n const { bodyEl, headEl } = pageContext.snapshot;\n const proxyBodyEl = bodyEl.querySelector(\"#proxied-body\");\n if (!proxyBodyEl) {\n throw new Error(\"proxied body not found in cached snapshot\");\n }\n Turbolinks._vpsOnRenderClient(headEl, true, true, () => {\n // merge body attributes\n document.body\n .getAttributeNames()\n .forEach((n) => document.body.removeAttribute(n));\n copyElementAttributes(document.body, bodyEl);\n // render body with react\n render({\n html: proxyBodyEl.innerHTML,\n layout,\n layoutProps,\n bodyEl,\n pageContext,\n });\n });\n}\n\n// Helper to render proxied html into a layout. Copies over body attributes and trigger Turoblinks caching.\nfunction render({\n html,\n layout,\n layoutProps,\n bodyEl,\n pageContext,\n}: {\n html: string;\n layout: string;\n layoutProps: AugmentMe.LayoutProps;\n bodyEl: Element;\n pageContext: PageContextProxyClient;\n}) {\n const { layoutMap } = pageContext.config;\n if (!layoutMap) {\n throw new Error(\"layoutMap needs to be defined in config\");\n }\n const Layout = layoutMap[layout] || PassThruLayout;\n renderReact(\n <PageShell key={pageContext.urlOriginal} pageContext={pageContext}>\n <Layout {...layoutProps}>\n <div id=\"proxied-body\" dangerouslySetInnerHTML={{ __html: html }} />\n </Layout>\n </PageShell>,\n pageContext.isHydration\n );\n // cache page context will save it and return it to us during restoration visits\n Turbolinks._vpsCachePageContext({\n layoutProps,\n layout,\n bodyAttrs: getElementAttributes(bodyEl),\n });\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PageShell
|
|
3
|
+
} from "./chunk-JHLK62FM.js";
|
|
4
|
+
import {
|
|
5
|
+
documentPropsToReact
|
|
6
|
+
} from "./chunk-VYXAWOXV.js";
|
|
7
|
+
import {
|
|
8
|
+
getPageContextOrConfig
|
|
9
|
+
} from "./chunk-K4H777XA.js";
|
|
10
|
+
|
|
11
|
+
// renderer/bifrost/onRenderHtml.tsx
|
|
12
|
+
import React from "react";
|
|
13
|
+
import ReactDOMServer from "react-dom/server";
|
|
14
|
+
import { escapeInject, dangerouslySkipEscape } from "vike/server";
|
|
15
|
+
async function bifrostOnRenderHtml(pageContext) {
|
|
16
|
+
const { Page, pageProps, redirectTo } = pageContext;
|
|
17
|
+
if (redirectTo) {
|
|
18
|
+
return {
|
|
19
|
+
pageContext: {
|
|
20
|
+
redirectTo
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const { Layout } = pageContext.config;
|
|
25
|
+
const layoutProps = getPageContextOrConfig(pageContext, "layoutProps") || {};
|
|
26
|
+
if (!Page)
|
|
27
|
+
throw new Error("Server-side render() hook expects Page to be exported");
|
|
28
|
+
if (!Layout)
|
|
29
|
+
throw new Error("Server-side render() hook expects Layout to be exported");
|
|
30
|
+
const pageHtml = ReactDOMServer.renderToString(
|
|
31
|
+
/* @__PURE__ */ React.createElement(PageShell, { pageContext }, /* @__PURE__ */ React.createElement(Layout, { ...layoutProps }, /* @__PURE__ */ React.createElement(Page, { ...pageProps })))
|
|
32
|
+
);
|
|
33
|
+
const headHtml = ReactDOMServer.renderToString(
|
|
34
|
+
documentPropsToReact(
|
|
35
|
+
getPageContextOrConfig(pageContext, "documentProps") || {}
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
const bodyAttrs = getPageContextOrConfig(pageContext, "bodyAttrs") || [];
|
|
39
|
+
const { favicon } = pageContext.config;
|
|
40
|
+
const faviconTag = !favicon ? "" : escapeInject`<link rel="icon" href="${favicon}" />`;
|
|
41
|
+
const documentHtml = escapeInject`<!DOCTYPE html>
|
|
42
|
+
<html lang="en">
|
|
43
|
+
<head>
|
|
44
|
+
${faviconTag}
|
|
45
|
+
${dangerouslySkipEscape(headHtml)}
|
|
46
|
+
${dangerouslySkipEscape(
|
|
47
|
+
(pageContext.config.scripts || []).flatMap((s) => s).join("")
|
|
48
|
+
)}
|
|
49
|
+
${dangerouslySkipEscape(
|
|
50
|
+
(pageContext.config.dynamicScripts || []).map((s) => s(pageContext)).join("")
|
|
51
|
+
)}
|
|
52
|
+
${dangerouslySkipEscape(`<script>
|
|
53
|
+
window.Turbolinks = {controller:{restorationIdentifier: ''}};
|
|
54
|
+
addEventListener("DOMContentLoaded", () => {
|
|
55
|
+
const event = new Event("turbolinks:load", { bubbles: true, cancelable: true });
|
|
56
|
+
event.data = {url: window.location.href};
|
|
57
|
+
document.dispatchEvent(event);
|
|
58
|
+
})
|
|
59
|
+
</script>`)}
|
|
60
|
+
</head>
|
|
61
|
+
<body ${dangerouslySkipEscape(
|
|
62
|
+
bodyAttrs.map(({ name, value }) => `${name}="${value}"`).join(" ")
|
|
63
|
+
)}>
|
|
64
|
+
<div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
|
|
65
|
+
</body>
|
|
66
|
+
</html>`;
|
|
67
|
+
return {
|
|
68
|
+
documentHtml,
|
|
69
|
+
pageContext: {}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
bifrostOnRenderHtml
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=chunk-5SP2QGEH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/bifrost/onRenderHtml.tsx"],"sourcesContent":["import React from \"react\";\nimport ReactDOMServer from \"react-dom/server\";\nimport { escapeInject, dangerouslySkipEscape } from \"vike/server\";\nimport { PageShell } from \"../../lib/PageShell\";\nimport { PageContextNoProxyServer } from \"../../types/internal\";\nimport { documentPropsToReact } from \"../utils/buildHead\";\nimport { getPageContextOrConfig } from \"../utils/getConfigOrPageContext\";\n\nexport async function bifrostOnRenderHtml(\n pageContext: PageContextNoProxyServer\n) {\n const { Page, pageProps, redirectTo } = pageContext;\n if (redirectTo) {\n return {\n pageContext: {\n redirectTo,\n },\n };\n }\n const { Layout } = pageContext.config;\n const layoutProps = getPageContextOrConfig(pageContext, \"layoutProps\") || {};\n\n if (!Page)\n throw new Error(\"Server-side render() hook expects Page to be exported\");\n if (!Layout)\n throw new Error(\"Server-side render() hook expects Layout to be exported\");\n\n const pageHtml = ReactDOMServer.renderToString(\n <PageShell pageContext={pageContext}>\n <Layout {...layoutProps}>\n <Page {...pageProps} />\n </Layout>\n </PageShell>\n );\n\n const headHtml = ReactDOMServer.renderToString(\n documentPropsToReact(\n getPageContextOrConfig(pageContext, \"documentProps\") || {}\n )\n );\n\n const bodyAttrs = getPageContextOrConfig(pageContext, \"bodyAttrs\") || [];\n\n const { favicon } = pageContext.config;\n const faviconTag = !favicon\n ? \"\"\n : escapeInject`<link rel=\"icon\" href=\"${favicon}\" />`;\n\n const documentHtml = escapeInject`<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n ${faviconTag}\n ${dangerouslySkipEscape(headHtml)}\n ${dangerouslySkipEscape(\n (pageContext.config.scripts || []).flatMap((s) => s).join(\"\")\n )}\n ${dangerouslySkipEscape(\n (pageContext.config.dynamicScripts || [])\n .map((s) => s(pageContext))\n .join(\"\")\n )}\n ${dangerouslySkipEscape(`<script>\n window.Turbolinks = {controller:{restorationIdentifier: ''}};\n addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n })\n </script>`)}\n </head>\n <body ${dangerouslySkipEscape(\n bodyAttrs.map(({ name, value }) => `${name}=\"${value}\"`).join(\" \")\n )}>\n <div id=\"page-view\">${dangerouslySkipEscape(pageHtml)}</div>\n </body>\n </html>`;\n\n return {\n documentHtml,\n pageContext: {},\n };\n}\n"],"mappings":";;;;;;;;;;;AAAA,OAAO,WAAW;AAClB,OAAO,oBAAoB;AAC3B,SAAS,cAAc,6BAA6B;AAMpD,eAAsB,oBACpB,aACA;AACA,QAAM,EAAE,MAAM,WAAW,WAAW,IAAI;AACxC,MAAI,YAAY;AACd,WAAO;AAAA,MACL,aAAa;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,QAAM,EAAE,OAAO,IAAI,YAAY;AAC/B,QAAM,cAAc,uBAAuB,aAAa,aAAa,KAAK,CAAC;AAE3E,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,uDAAuD;AACzE,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,yDAAyD;AAE3E,QAAM,WAAW,eAAe;AAAA,IAC9B,oCAAC,aAAU,eACT,oCAAC,UAAQ,GAAG,eACV,oCAAC,QAAM,GAAG,WAAW,CACvB,CACF;AAAA,EACF;AAEA,QAAM,WAAW,eAAe;AAAA,IAC9B;AAAA,MACE,uBAAuB,aAAa,eAAe,KAAK,CAAC;AAAA,IAC3D;AAAA,EACF;AAEA,QAAM,YAAY,uBAAuB,aAAa,WAAW,KAAK,CAAC;AAEvE,QAAM,EAAE,QAAQ,IAAI,YAAY;AAChC,QAAM,aAAa,CAAC,UAChB,KACA,sCAAsC,OAAO;AAEjD,QAAM,eAAe;AAAA;AAAA;AAAA,QAGf,UAAU;AAAA,QACV,sBAAsB,QAAQ,CAAC;AAAA,QAC/B;AAAA,KACC,YAAY,OAAO,WAAW,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE;AAAA,EAC9D,CAAC;AAAA,QACC;AAAA,KACC,YAAY,OAAO,kBAAkB,CAAC,GACpC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,EACzB,KAAK,EAAE;AAAA,EACZ,CAAC;AAAA,QACC,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAOd,CAAC;AAAA;AAAA,cAEH;AAAA,IACN,UAAU,IAAI,CAAC,EAAE,MAAM,MAAM,MAAM,GAAG,IAAI,KAAK,KAAK,GAAG,EAAE,KAAK,GAAG;AAAA,EACnE,CAAC;AAAA,8BACuB,sBAAsB,QAAQ,CAAC;AAAA;AAAA;AAI3D,SAAO;AAAA,IACL;AAAA,IACA,aAAa,CAAC;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// renderer/configs/bifrost.ts
|
|
2
|
+
var passToClient = [
|
|
3
|
+
"layoutProps",
|
|
4
|
+
"pageProps",
|
|
5
|
+
"redirectTo",
|
|
6
|
+
"bodyAttrs",
|
|
7
|
+
"documentProps",
|
|
8
|
+
"scripts",
|
|
9
|
+
"is404"
|
|
10
|
+
];
|
|
11
|
+
var bifrostConfig = {
|
|
12
|
+
passToClient,
|
|
13
|
+
meta: {
|
|
14
|
+
Layout: { env: { server: true, client: true } },
|
|
15
|
+
layoutProps: { env: { server: true, client: true } },
|
|
16
|
+
documentProps: { env: { server: true, client: true } },
|
|
17
|
+
bodyAttrs: { env: { server: true, client: true } },
|
|
18
|
+
scripts: {
|
|
19
|
+
env: { server: true, client: true },
|
|
20
|
+
cumulative: true
|
|
21
|
+
},
|
|
22
|
+
dynamicScripts: { env: { server: true, client: false }, global: true },
|
|
23
|
+
favicon: { env: { server: true } }
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
bifrostConfig
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-ABLEI4J7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/configs/bifrost.ts"],"sourcesContent":["import { Config } from \"vike/types\";\n\nconst passToClient = [\n \"layoutProps\",\n \"pageProps\",\n \"redirectTo\",\n \"bodyAttrs\",\n \"documentProps\",\n \"scripts\",\n \"is404\",\n];\nexport const bifrostConfig = {\n passToClient,\n meta: {\n Layout: { env: { server: true, client: true } },\n layoutProps: { env: { server: true, client: true } },\n documentProps: { env: { server: true, client: true } },\n bodyAttrs: { env: { server: true, client: true } },\n scripts: {\n env: { server: true, client: true },\n cumulative: true,\n },\n dynamicScripts: { env: { server: true, client: false }, global: true },\n favicon: { env: { server: true } },\n },\n} satisfies Config;\n"],"mappings":";AAEA,IAAM,eAAe;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA,MAAM;AAAA,IACJ,QAAQ,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IAC9C,aAAa,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IACnD,eAAe,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IACrD,WAAW,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IACjD,SAAS;AAAA,MACP,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK;AAAA,MAClC,YAAY;AAAA,IACd;AAAA,IACA,gBAAgB,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,MAAM,GAAG,QAAQ,KAAK;AAAA,IACrE,SAAS,EAAE,KAAK,EAAE,QAAQ,KAAK,EAAE;AAAA,EACnC;AACF;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// renderer/getConfigOrPageContext.ts
|
|
1
|
+
// renderer/utils/getConfigOrPageContext.ts
|
|
2
2
|
function getPageContextOrConfig(pageContext, prop) {
|
|
3
3
|
return pageContext[prop] || pageContext.config[prop];
|
|
4
4
|
}
|
|
@@ -6,4 +6,4 @@ function getPageContextOrConfig(pageContext, prop) {
|
|
|
6
6
|
export {
|
|
7
7
|
getPageContextOrConfig
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=chunk-
|
|
9
|
+
//# sourceMappingURL=chunk-K4H777XA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/utils/getConfigOrPageContext.ts"],"sourcesContent":["import { PageContextNoProxy } from \"../../types/internal.js\";\n\ntype ConfigOrContext = PageContextNoProxy | PageContextNoProxy[\"config\"];\n\n/**\n * Get page configs that are definable in config and in runtime via onBeforeRoute. documentProps, for example.\n */\nexport function getPageContextOrConfig<T extends keyof ConfigOrContext>(\n pageContext: PageContextNoProxy,\n prop: T\n): ConfigOrContext[T] {\n return pageContext[prop] || pageContext.config[prop];\n}\n"],"mappings":";AAOO,SAAS,uBACd,aACA,MACoB;AACpB,SAAO,YAAY,IAAI,KAAK,YAAY,OAAO,IAAI;AACrD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/utils/PassthruLayout.tsx"],"sourcesContent":["import React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nexport const PassThruLayout: React.ComponentType<PropsWithChildren> = ({\n children,\n}) => <>{children}</>;\n"],"mappings":";AAAA,OAAO,WAAW;AAGX,IAAM,iBAAyD,CAAC;AAAA,EACrE;AACF,MAAM,0DAAG,QAAS;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Turbolinks,
|
|
3
|
+
renderReact
|
|
4
|
+
} from "./chunk-X3MUHPJ3.js";
|
|
5
|
+
import {
|
|
6
|
+
PassThruLayout
|
|
7
|
+
} from "./chunk-OXCN6F2S.js";
|
|
8
|
+
import {
|
|
9
|
+
PageShell
|
|
10
|
+
} from "./chunk-JHLK62FM.js";
|
|
11
|
+
import {
|
|
12
|
+
documentPropsToReact
|
|
13
|
+
} from "./chunk-VYXAWOXV.js";
|
|
14
|
+
import {
|
|
15
|
+
getPageContextOrConfig
|
|
16
|
+
} from "./chunk-K4H777XA.js";
|
|
17
|
+
|
|
18
|
+
// renderer/bifrost/onRenderClient.tsx
|
|
19
|
+
import React from "react";
|
|
20
|
+
import { createRoot } from "react-dom/client";
|
|
21
|
+
async function bifrostOnRenderClient(pageContext) {
|
|
22
|
+
if (pageContext.isBackwardNavigation && pageContext.is404) {
|
|
23
|
+
Turbolinks.controller.viewInvalidated();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { Page, pageProps } = pageContext;
|
|
27
|
+
const { Layout = PassThruLayout } = pageContext.config;
|
|
28
|
+
const layoutProps = getPageContextOrConfig(pageContext, "layoutProps") || {};
|
|
29
|
+
const bodyAttrs = getPageContextOrConfig(pageContext, "bodyAttrs") || [];
|
|
30
|
+
if (!Page)
|
|
31
|
+
throw new Error("Client-side render() hook expects Page to be exported");
|
|
32
|
+
const page = /* @__PURE__ */ React.createElement(PageShell, { pageContext }, /* @__PURE__ */ React.createElement(Layout, { ...layoutProps }, /* @__PURE__ */ React.createElement(Page, { ...pageProps })));
|
|
33
|
+
if (pageContext.isHydration) {
|
|
34
|
+
await pageContext.config.onClientInit?.();
|
|
35
|
+
renderReact(page, pageContext.isHydration);
|
|
36
|
+
} else {
|
|
37
|
+
const head = document.createElement("head");
|
|
38
|
+
createRoot(head).render(
|
|
39
|
+
documentPropsToReact(
|
|
40
|
+
getPageContextOrConfig(pageContext, "documentProps") || {}
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
(pageContext.config.scripts || []).forEach((sarr) => {
|
|
44
|
+
sarr.forEach((s) => {
|
|
45
|
+
head.insertAdjacentHTML("beforeend", s);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
requestAnimationFrame(() => {
|
|
49
|
+
Turbolinks._vpsOnRenderClient(head, false, false, () => {
|
|
50
|
+
document.body.getAttributeNames().forEach((n) => document.body.removeAttribute(n));
|
|
51
|
+
bodyAttrs.forEach(
|
|
52
|
+
({ name, value }) => document.body.setAttribute(name, value)
|
|
53
|
+
);
|
|
54
|
+
renderReact(page, pageContext.isHydration);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
bifrostOnRenderClient
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-RSVASTEA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/bifrost/onRenderClient.tsx"],"sourcesContent":["import React from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { PageShell } from \"../../lib/PageShell\";\nimport { renderReact } from \"../../lib/renderReact\";\nimport { Turbolinks } from \"../../lib/turbolinks\";\nimport { PageContextNoProxyClient } from \"../../types/internal\";\nimport { PassThruLayout } from \"../utils/PassthruLayout\";\nimport { documentPropsToReact } from \"../utils/buildHead\";\nimport { getPageContextOrConfig } from \"../utils/getConfigOrPageContext\";\n\nexport async function bifrostOnRenderClient(\n pageContext: PageContextNoProxyClient\n) {\n // Back button leading to 404 means we hit a page bifrost can't handle in the browser history.\n // Reload allows us to revert to passthru proxy and/or let ALB handle\n if (pageContext.isBackwardNavigation && pageContext.is404) {\n Turbolinks.controller.viewInvalidated();\n return;\n }\n\n const { Page, pageProps } = pageContext;\n const { Layout = PassThruLayout } = pageContext.config;\n const layoutProps = getPageContextOrConfig(pageContext, \"layoutProps\") || {};\n const bodyAttrs = getPageContextOrConfig(pageContext, \"bodyAttrs\") || [];\n\n if (!Page)\n throw new Error(\"Client-side render() hook expects Page to be exported\");\n\n const page = (\n <PageShell pageContext={pageContext}>\n <Layout {...layoutProps}>\n <Page {...pageProps} />\n </Layout>\n </PageShell>\n );\n if (pageContext.isHydration) {\n // During hydration of initial ssr, body is in dom, not page props (to avoid double-send)\n await pageContext.config.onClientInit?.();\n renderReact(page, pageContext.isHydration);\n } else {\n const head = document.createElement(\"head\");\n createRoot(head).render(\n documentPropsToReact(\n getPageContextOrConfig(pageContext, \"documentProps\") || {}\n )\n );\n (pageContext.config.scripts || []).forEach((sarr) => {\n sarr.forEach((s) => {\n head.insertAdjacentHTML(\"beforeend\", s);\n });\n });\n\n requestAnimationFrame(() => {\n Turbolinks._vpsOnRenderClient(head, false, false, () => {\n // clear anything on body\n document.body\n .getAttributeNames()\n .forEach((n) => document.body.removeAttribute(n));\n // add set bodyAttrs\n bodyAttrs.forEach(({ name, value }) =>\n document.body.setAttribute(name, value)\n );\n renderReact(page, pageContext.isHydration);\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAW;AAClB,SAAS,kBAAkB;AAS3B,eAAsB,sBACpB,aACA;AAGA,MAAI,YAAY,wBAAwB,YAAY,OAAO;AACzD,eAAW,WAAW,gBAAgB;AACtC;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,UAAU,IAAI;AAC5B,QAAM,EAAE,SAAS,eAAe,IAAI,YAAY;AAChD,QAAM,cAAc,uBAAuB,aAAa,aAAa,KAAK,CAAC;AAC3E,QAAM,YAAY,uBAAuB,aAAa,WAAW,KAAK,CAAC;AAEvE,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,uDAAuD;AAEzE,QAAM,OACJ,oCAAC,aAAU,eACT,oCAAC,UAAQ,GAAG,eACV,oCAAC,QAAM,GAAG,WAAW,CACvB,CACF;AAEF,MAAI,YAAY,aAAa;AAE3B,UAAM,YAAY,OAAO,eAAe;AACxC,gBAAY,MAAM,YAAY,WAAW;AAAA,EAC3C,OAAO;AACL,UAAM,OAAO,SAAS,cAAc,MAAM;AAC1C,eAAW,IAAI,EAAE;AAAA,MACf;AAAA,QACE,uBAAuB,aAAa,eAAe,KAAK,CAAC;AAAA,MAC3D;AAAA,IACF;AACA,KAAC,YAAY,OAAO,WAAW,CAAC,GAAG,QAAQ,CAAC,SAAS;AACnD,WAAK,QAAQ,CAAC,MAAM;AAClB,aAAK,mBAAmB,aAAa,CAAC;AAAA,MACxC,CAAC;AAAA,IACH,CAAC;AAED,0BAAsB,MAAM;AAC1B,iBAAW,mBAAmB,MAAM,OAAO,OAAO,MAAM;AAEtD,iBAAS,KACN,kBAAkB,EAClB,QAAQ,CAAC,MAAM,SAAS,KAAK,gBAAgB,CAAC,CAAC;AAElD,kBAAU;AAAA,UAAQ,CAAC,EAAE,MAAM,MAAM,MAC/B,SAAS,KAAK,aAAa,MAAM,KAAK;AAAA,QACxC;AACA,oBAAY,MAAM,YAAY,WAAW;AAAA,MAC3C,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getElementAttributes
|
|
3
|
-
} from "
|
|
3
|
+
} from "./chunk-RQ34EW7E.js";
|
|
4
4
|
import {
|
|
5
5
|
PageShell
|
|
6
|
-
} from "
|
|
7
|
-
import "../../../chunk-PESUYCE4.js";
|
|
8
|
-
import "../../../chunk-IYGONC4I.js";
|
|
9
|
-
import "../../../chunk-EYYCKU6F.js";
|
|
6
|
+
} from "./chunk-JHLK62FM.js";
|
|
10
7
|
|
|
11
|
-
//
|
|
8
|
+
// renderer/wrapped/onRenderHtml.tsx
|
|
12
9
|
import React from "react";
|
|
13
10
|
import ReactDOMServer from "react-dom/server";
|
|
14
11
|
import { dangerouslySkipEscape, escapeInject } from "vike/server";
|
|
15
12
|
import jsdom from "jsdom";
|
|
16
|
-
async function
|
|
17
|
-
if (pageContext.
|
|
18
|
-
const {
|
|
13
|
+
async function wrappedOnRenderHtml(pageContext) {
|
|
14
|
+
if (pageContext.wrappedServerOnly) {
|
|
15
|
+
const { html, layoutProps, layout } = pageContext.wrappedServerOnly;
|
|
19
16
|
const { layoutMap } = pageContext.config;
|
|
20
17
|
if (!layoutMap) {
|
|
21
18
|
throw new Error("layoutMap needs to be defined in config");
|
|
22
19
|
}
|
|
23
20
|
const Layout = layoutMap[layout];
|
|
24
21
|
if (!Layout) {
|
|
25
|
-
return { documentHtml:
|
|
22
|
+
return { documentHtml: html, pageContext: {} };
|
|
26
23
|
}
|
|
27
|
-
const dom = new jsdom.JSDOM(
|
|
24
|
+
const dom = new jsdom.JSDOM(html);
|
|
28
25
|
const doc = dom.window.document;
|
|
29
26
|
const bodyEl = doc.querySelector("body");
|
|
30
27
|
const head = doc.querySelector("head");
|
|
@@ -44,18 +41,18 @@ async function onRenderHtml(pageContext) {
|
|
|
44
41
|
<!DOCTYPE html>
|
|
45
42
|
<html>
|
|
46
43
|
<head>
|
|
47
|
-
${dangerouslySkipEscape(head.innerHTML)}
|
|
48
44
|
${// We need to fire turbolinks:load exactly on DCL, so it must be a blocking head script to catch DCL event.
|
|
49
45
|
// Vite loads scripts with type="module" so the rest of our code will show up too late.
|
|
50
46
|
// TODO: figure out how to bundle this better. at least read from a .js file
|
|
51
47
|
dangerouslySkipEscape(`<script>
|
|
52
|
-
window.Turbolinks = {controller:{restorationIdentifier: ''}};
|
|
48
|
+
window.Turbolinks = {controller:{restorationIdentifier: ''},supported:true};
|
|
53
49
|
addEventListener("DOMContentLoaded", () => {
|
|
54
50
|
const event = new Event("turbolinks:load", { bubbles: true, cancelable: true });
|
|
55
51
|
event.data = {url: window.location.href};
|
|
56
52
|
document.dispatchEvent(event);
|
|
57
53
|
})
|
|
58
54
|
</script>`)}
|
|
55
|
+
${dangerouslySkipEscape(head.innerHTML)}
|
|
59
56
|
</head>
|
|
60
57
|
<body ${dangerouslySkipEscape(
|
|
61
58
|
Object.entries(getElementAttributes(bodyEl)).map(([name, value]) => `${name}="${value}"`).join(" ")
|
|
@@ -65,13 +62,14 @@ async function onRenderHtml(pageContext) {
|
|
|
65
62
|
</html>`;
|
|
66
63
|
return {
|
|
67
64
|
documentHtml,
|
|
68
|
-
pageContext: {}
|
|
65
|
+
pageContext: { layout, layoutProps }
|
|
69
66
|
};
|
|
70
67
|
} else {
|
|
71
68
|
return {};
|
|
72
69
|
}
|
|
73
70
|
}
|
|
71
|
+
|
|
74
72
|
export {
|
|
75
|
-
|
|
73
|
+
wrappedOnRenderHtml
|
|
76
74
|
};
|
|
77
|
-
//# sourceMappingURL=
|
|
75
|
+
//# sourceMappingURL=chunk-SAMMNBO4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/wrapped/onRenderHtml.tsx"],"sourcesContent":["import React from \"react\";\nimport ReactDOMServer from \"react-dom/server\";\nimport { dangerouslySkipEscape, escapeInject } from \"vike/server\";\nimport { PageContextProxyServer } from \"../../types/internal.js\";\nimport { PageShell } from \"../../lib/PageShell.js\";\nimport jsdom from \"jsdom\";\nimport { getElementAttributes } from \"../../lib/getElementAttributes.js\";\n\nexport async function wrappedOnRenderHtml(pageContext: PageContextProxyServer) {\n if (pageContext.wrappedServerOnly) {\n const { html, layoutProps, layout } = pageContext.wrappedServerOnly;\n\n const { layoutMap } = pageContext.config;\n if (!layoutMap) {\n throw new Error(\"layoutMap needs to be defined in config\");\n }\n const Layout = layoutMap[layout];\n if (!Layout) {\n // passthru\n return { documentHtml: html, pageContext: {} };\n }\n\n const dom = new jsdom.JSDOM(html);\n const doc = dom.window.document;\n const bodyEl = doc.querySelector(\"body\");\n const head = doc.querySelector(\"head\");\n if (!bodyEl || !head) {\n throw new Error(\"Proxy failed\");\n }\n\n const pageHtml = ReactDOMServer.renderToString(\n <PageShell pageContext={pageContext}>\n <Layout {...layoutProps}>\n <div\n id=\"proxied-body\"\n dangerouslySetInnerHTML={{ __html: bodyEl.innerHTML }}\n />\n </Layout>\n </PageShell>\n );\n\n const documentHtml = escapeInject`\n <!DOCTYPE html>\n <html>\n <head>\n ${\n // We need to fire turbolinks:load exactly on DCL, so it must be a blocking head script to catch DCL event.\n // Vite loads scripts with type=\"module\" so the rest of our code will show up too late.\n // TODO: figure out how to bundle this better. at least read from a .js file\n dangerouslySkipEscape(`<script>\n window.Turbolinks = {controller:{restorationIdentifier: ''},supported:true};\n addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n })\n </script>`)\n }\n ${dangerouslySkipEscape(head.innerHTML)}\n </head>\n <body ${dangerouslySkipEscape(\n Object.entries(getElementAttributes(bodyEl))\n .map(([name, value]) => `${name}=\"${value}\"`)\n .join(\" \")\n )}>\n <div id=\"page-view\">${dangerouslySkipEscape(pageHtml)}</div>\n </body>\n </html>`;\n\n return {\n documentHtml,\n pageContext: { layout, layoutProps },\n };\n } else {\n // do nothing: Just exists to signal fastify server that no routes matched and we should proxy\n return {};\n }\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,WAAW;AAClB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB,oBAAoB;AAGpD,OAAO,WAAW;AAGlB,eAAsB,oBAAoB,aAAqC;AAC7E,MAAI,YAAY,mBAAmB;AACjC,UAAM,EAAE,MAAM,aAAa,OAAO,IAAI,YAAY;AAElD,UAAM,EAAE,UAAU,IAAI,YAAY;AAClC,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,SAAS,UAAU,MAAM;AAC/B,QAAI,CAAC,QAAQ;AAEX,aAAO,EAAE,cAAc,MAAM,aAAa,CAAC,EAAE;AAAA,IAC/C;AAEA,UAAM,MAAM,IAAI,MAAM,MAAM,IAAI;AAChC,UAAM,MAAM,IAAI,OAAO;AACvB,UAAM,SAAS,IAAI,cAAc,MAAM;AACvC,UAAM,OAAO,IAAI,cAAc,MAAM;AACrC,QAAI,CAAC,UAAU,CAAC,MAAM;AACpB,YAAM,IAAI,MAAM,cAAc;AAAA,IAChC;AAEA,UAAM,WAAW,eAAe;AAAA,MAC9B,oCAAC,aAAU,eACT,oCAAC,UAAQ,GAAG,eACV;AAAA,QAAC;AAAA;AAAA,UACC,IAAG;AAAA,UACH,yBAAyB,EAAE,QAAQ,OAAO,UAAU;AAAA;AAAA,MACtD,CACF,CACF;AAAA,IACF;AAEA,UAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQb,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAOd,CACV;AAAA,YACE,sBAAsB,KAAK,SAAS,CAAC;AAAA;AAAA,gBAEjC;AAAA,MACN,OAAO,QAAQ,qBAAqB,MAAM,CAAC,EACxC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,IAAI,KAAK,KAAK,GAAG,EAC3C,KAAK,GAAG;AAAA,IACb,CAAC;AAAA,gCACuB,sBAAsB,QAAQ,CAAC;AAAA;AAAA;AAI3D,WAAO;AAAA,MACL;AAAA,MACA,aAAa,EAAE,QAAQ,YAAY;AAAA,IACrC;AAAA,EACF,OAAO;AAEL,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// renderer/configs/wrapped.ts
|
|
2
|
+
var wrappedConfig = {
|
|
3
|
+
passToClient: ["layout", "layoutProps", "redirectTo"],
|
|
4
|
+
meta: {
|
|
5
|
+
layoutMap: { env: { server: true, client: true } },
|
|
6
|
+
getLayout: { env: { server: true, client: true } },
|
|
7
|
+
proxyHeaders: { env: { server: true, client: true } }
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
wrappedConfig
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-X2R7ODLQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../renderer/configs/wrapped.ts"],"sourcesContent":["import { Config } from \"vike/types\";\n\nexport const wrappedConfig = {\n passToClient: [\"layout\", \"layoutProps\", \"redirectTo\"],\n meta: {\n layoutMap: { env: { server: true, client: true } },\n getLayout: { env: { server: true, client: true } },\n proxyHeaders: { env: { server: true, client: true } },\n },\n} satisfies Config;\n"],"mappings":";AAEO,IAAM,gBAAgB;AAAA,EAC3B,cAAc,CAAC,UAAU,eAAe,YAAY;AAAA,EACpD,MAAM;AAAA,IACJ,WAAW,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IACjD,WAAW,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,IACjD,cAAc,EAAE,KAAK,EAAE,QAAQ,MAAM,QAAQ,KAAK,EAAE;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -2,21 +2,6 @@ import {
|
|
|
2
2
|
setNavigation
|
|
3
3
|
} from "./chunk-PESUYCE4.js";
|
|
4
4
|
|
|
5
|
-
// lib/renderReact.ts
|
|
6
|
-
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
7
|
-
var root;
|
|
8
|
-
function renderReact(page, isHydration) {
|
|
9
|
-
const container = document.getElementById("page-view");
|
|
10
|
-
if (isHydration) {
|
|
11
|
-
root = hydrateRoot(container, page);
|
|
12
|
-
} else {
|
|
13
|
-
if (!root) {
|
|
14
|
-
root = createRoot(container);
|
|
15
|
-
}
|
|
16
|
-
root.render(page);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
5
|
// lib/turbolinks/util.ts
|
|
21
6
|
function array(values) {
|
|
22
7
|
return Array.prototype.slice.call(values);
|
|
@@ -943,9 +928,24 @@ var Turbolinks = {
|
|
|
943
928
|
}
|
|
944
929
|
};
|
|
945
930
|
|
|
931
|
+
// lib/renderReact.ts
|
|
932
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
933
|
+
var root;
|
|
934
|
+
function renderReact(page, isHydration) {
|
|
935
|
+
const container = document.getElementById("page-view");
|
|
936
|
+
if (isHydration) {
|
|
937
|
+
root = hydrateRoot(container, page);
|
|
938
|
+
} else {
|
|
939
|
+
if (!root) {
|
|
940
|
+
root = createRoot(container);
|
|
941
|
+
}
|
|
942
|
+
root.render(page);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
946
|
export {
|
|
947
|
-
renderReact,
|
|
948
947
|
copyElementAttributes,
|
|
949
|
-
Turbolinks
|
|
948
|
+
Turbolinks,
|
|
949
|
+
renderReact
|
|
950
950
|
};
|
|
951
|
-
//# sourceMappingURL=chunk-
|
|
951
|
+
//# sourceMappingURL=chunk-X3MUHPJ3.js.map
|