fix: inject script for ssr mode (#3339)
* fix: inject script for ssr mode * chore: changeset
This commit is contained in:
parent
71f852cad9
commit
3dc68e148e
4 changed files with 20 additions and 3 deletions
5
.changeset/heavy-adults-obey.md
Normal file
5
.changeset/heavy-adults-obey.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fixes injectscript in ssr mode
|
|
@ -78,7 +78,19 @@ export class App {
|
||||||
const renderers = manifest.renderers;
|
const renderers = manifest.renderers;
|
||||||
const info = this.#routeDataToRouteInfo.get(routeData!)!;
|
const info = this.#routeDataToRouteInfo.get(routeData!)!;
|
||||||
const links = createLinkStylesheetElementSet(info.links, manifest.site);
|
const links = createLinkStylesheetElementSet(info.links, manifest.site);
|
||||||
const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);
|
|
||||||
|
const filteredScripts = info.scripts.filter(script => typeof script !== 'string' && script?.stage !== 'head-inline') as string[];
|
||||||
|
const scripts = createModuleScriptElementWithSrcSet(filteredScripts, manifest.site);
|
||||||
|
|
||||||
|
// Add all injected scripts to the page.
|
||||||
|
for (const script of info.scripts) {
|
||||||
|
if (typeof script !== 'string' && script.stage === 'head-inline') {
|
||||||
|
scripts.add({
|
||||||
|
props: {},
|
||||||
|
children: script.children,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const result = await render({
|
const result = await render({
|
||||||
links,
|
links,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export interface RouteInfo {
|
||||||
routeData: RouteData;
|
routeData: RouteData;
|
||||||
file: string;
|
file: string;
|
||||||
links: string[];
|
links: string[];
|
||||||
scripts: string[];
|
scripts: Array<string | {children: string, stage: string}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
|
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
|
||||||
|
|
|
@ -109,7 +109,7 @@ function buildManifest(
|
||||||
routes.push({
|
routes.push({
|
||||||
file: '',
|
file: '',
|
||||||
links: Array.from(pageData.css),
|
links: Array.from(pageData.css),
|
||||||
scripts,
|
scripts: [...scripts, ...astroConfig._ctx.scripts.filter(script => script.stage === 'head-inline').map(({stage, content}) => ({stage, children: content}))],
|
||||||
routeData: serializeRouteData(pageData.route),
|
routeData: serializeRouteData(pageData.route),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue