diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 3847a4589..36fb01ff2 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -16,7 +16,6 @@ import { render } from '../render/core.js'; import { RouteCache } from '../render/route-cache.js'; import { createLinkStylesheetElementSet, - createModuleScriptElementWithSrcSet, createModuleScriptElement, } from '../render/ssr-element.js'; import { matchRoute } from '../routing/match.js'; @@ -83,8 +82,8 @@ export class App { let scripts = new Set(); for (const script of info.scripts) { - if (('stage' in script)) { - if(script.stage === 'head-inline') { + if ('stage' in script) { + if (script.stage === 'head-inline') { scripts.add({ props: {}, children: script.children, diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 1bbfe3511..cf34364ec 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -12,13 +12,11 @@ export interface RouteInfo { routeData: RouteData; file: string; links: string[]; - scripts: - ( - // Integration injected - { children: string; stage: string } | - // Hoisted - { type: 'inline' | 'external'; value: string; } - )[]; + scripts: // Integration injected + (| { children: string; stage: string } + // Hoisted + | { type: 'inline' | 'external'; value: string } + )[]; } export type SerializedRouteInfo = Omit & { diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 8bac241d6..05d1bcc55 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -16,10 +16,7 @@ import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import { call as callEndpoint } from '../endpoint/index.js'; import { debug, info } from '../logger/core.js'; import { render } from '../render/core.js'; -import { - createLinkStylesheetElementSet, - createModuleScriptsSet, -} from '../render/ssr-element.js'; +import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js'; import { createRequest } from '../request.js'; import { getOutputFilename, isBuildingToSSR } from '../util.js'; import { getOutFile, getOutFolder } from './common.js'; @@ -167,7 +164,7 @@ interface GeneratePathOptions { pageData: PageBuildData; internals: BuildInternals; linkIds: string[]; - scripts: { type: 'inline' | 'external', value: string } | null; + scripts: { type: 'inline' | 'external'; value: string } | null; mod: ComponentInstance; renderers: SSRLoadedRenderer[]; } diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index 4342da32e..4b734fb9e 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -19,7 +19,7 @@ export interface PageBuildData { route: RouteData; moduleSpecifier: string; css: Set; - hoistedScript: { type: 'inline' | 'external', value: string } | undefined; + hoistedScript: { type: 'inline' | 'external'; value: string } | undefined; } export type AllPagesData = Record; diff --git a/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts b/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts index ae3525250..9ab7ece45 100644 --- a/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts +++ b/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts @@ -50,7 +50,9 @@ export function vitePluginHoistedScripts( output.facadeModuleId && virtualHoistedEntry(output.facadeModuleId) ) { - const canBeInlined = output.imports.length === 0 && output.dynamicImports.length === 0 && + const canBeInlined = + output.imports.length === 0 && + output.dynamicImports.length === 0 && Buffer.byteLength(output.code) <= assetInlineLimit; let removeFromBundle = false; const facadeId = output.facadeModuleId!; @@ -59,23 +61,23 @@ export function vitePluginHoistedScripts( const vid = viteID(new URL('.' + pathname, astroConfig.root)); const pageInfo = getPageDataByViteID(internals, vid); if (pageInfo) { - if(canBeInlined) { + if (canBeInlined) { pageInfo.hoistedScript = { type: 'inline', - value: output.code + value: output.code, }; removeFromBundle = true; } else { pageInfo.hoistedScript = { type: 'external', - value: id + value: id, }; } } } // Remove the bundle if it was inlined - if(removeFromBundle) { + if (removeFromBundle) { delete bundle[id]; } } diff --git a/packages/astro/src/core/render/ssr-element.ts b/packages/astro/src/core/render/ssr-element.ts index 2788fdace..4828583ee 100644 --- a/packages/astro/src/core/render/ssr-element.ts +++ b/packages/astro/src/core/render/ssr-element.ts @@ -25,8 +25,11 @@ export function createLinkStylesheetElementSet(hrefs: string[], site?: string) { return new Set(hrefs.map((href) => createLinkStylesheetElement(href, site))); } -export function createModuleScriptElement(script: { type: 'inline' | 'external'; value: string; }, site?: string): SSRElement { - if(script.type === 'external') { +export function createModuleScriptElement( + script: { type: 'inline' | 'external'; value: string }, + site?: string +): SSRElement { + if (script.type === 'external') { return createModuleScriptElementWithSrc(script.value, site); } else { return { @@ -56,8 +59,8 @@ export function createModuleScriptElementWithSrcSet( } export function createModuleScriptsSet( - scripts: { type: 'inline' | 'external'; value: string; }[], + scripts: { type: 'inline' | 'external'; value: string }[], site?: string ): Set { - return new Set(scripts.map(script => createModuleScriptElement(script, site))); + return new Set(scripts.map((script) => createModuleScriptElement(script, site))); } diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js index 79fff798e..dac6a18c7 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.test.js @@ -58,7 +58,7 @@ describe('Scripts (hoisted and not)', () => { ); }); - it('Inline scripts that are shared by multiple pages create chunks, and aren\'t inlined into the HTML', async () => { + it("Inline scripts that are shared by multiple pages create chunks, and aren't inlined into the HTML", async () => { let html = await fixture.readFile('/inline-shared-one/index.html'); let $ = cheerio.load(html);