diff --git a/.changeset/fifty-shrimps-cheat.md b/.changeset/fifty-shrimps-cheat.md new file mode 100644 index 000000000000..cdbc374458c2 --- /dev/null +++ b/.changeset/fifty-shrimps-cheat.md @@ -0,0 +1,10 @@ +--- +'@modern-js/runtime': patch +'@modern-js/app-tools': patch +'@modern-js/prod-server': patch +'@modern-js/server': patch +--- + +fix: move chunkmap.css comment to bottom of head +fix: 将 chunkmap.css 标记移动到 head 底部 + diff --git a/packages/runtime/plugin-runtime/src/ssr/serverRender/index.ts b/packages/runtime/plugin-runtime/src/ssr/serverRender/index.ts index b64c15938ece..a415797e6164 100644 --- a/packages/runtime/plugin-runtime/src/ssr/serverRender/index.ts +++ b/packages/runtime/plugin-runtime/src/ssr/serverRender/index.ts @@ -4,8 +4,17 @@ import { isReact18 } from '../utils'; import { ServerRenderOptions } from './types'; +import { CSS_CHUNKS_PLACEHOLDER } from './utils'; export default async function serverRender(options: ServerRenderOptions) { + if (options.context.ssrContext?.template) { + options.context.ssrContext.template = + options.context.ssrContext?.template.replace( + '', + `${CSS_CHUNKS_PLACEHOLDER}`, + ); + } + if (isReact18() && options.config.mode === 'stream') { const pipe = await require('./renderToStream').render(options); return pipe; diff --git a/packages/runtime/plugin-runtime/src/ssr/serverRender/renderToStream/bulidTemplate.before.ts b/packages/runtime/plugin-runtime/src/ssr/serverRender/renderToStream/bulidTemplate.before.ts index 8a81a97d3328..15b97efbd196 100644 --- a/packages/runtime/plugin-runtime/src/ssr/serverRender/renderToStream/bulidTemplate.before.ts +++ b/packages/runtime/plugin-runtime/src/ssr/serverRender/renderToStream/bulidTemplate.before.ts @@ -2,14 +2,13 @@ import ReactHelmet, { HelmetData } from 'react-helmet'; import { matchRoutes } from 'react-router-dom'; import helmetReplace from '../helmet'; import { RuntimeContext } from '../types'; +import { CSS_CHUNKS_PLACEHOLDER } from '../utils'; import { HEAD_REG_EXP, BuildTemplateCb, buildTemplate, } from './buildTemplate.share'; -const CSS_CHUNKS_PLACEHOLDER = ''; - // build head template function getHeadTemplate(beforeEntryTemplate: string, context: RuntimeContext) { const callbacks: BuildTemplateCb[] = [ diff --git a/packages/runtime/plugin-runtime/src/ssr/serverRender/utils.ts b/packages/runtime/plugin-runtime/src/ssr/serverRender/utils.ts index 58fa36a38256..9137b18df073 100644 --- a/packages/runtime/plugin-runtime/src/ssr/serverRender/utils.ts +++ b/packages/runtime/plugin-runtime/src/ssr/serverRender/utils.ts @@ -1,5 +1,7 @@ import type { ChunkExtractor } from '@loadable/server'; +export const CSS_CHUNKS_PLACEHOLDER = ''; + export function getLoadableScripts(extractor: ChunkExtractor) { const check = (scripts: string) => (scripts || '').includes('__LOADABLE_REQUIRED_CHUNKS___ext'); diff --git a/packages/server/prod-server/tests/fixtures/completely-custom/test-dist/html/main/index.html b/packages/server/prod-server/tests/fixtures/completely-custom/test-dist/html/main/index.html index 49fb371d8f05..80b86049b548 100644 --- a/packages/server/prod-server/tests/fixtures/completely-custom/test-dist/html/main/index.html +++ b/packages/server/prod-server/tests/fixtures/completely-custom/test-dist/html/main/index.html @@ -2,7 +2,7 @@ - + @@ -13,24 +13,23 @@ - + - + -
- + - + diff --git a/packages/server/prod-server/tests/fixtures/pure/test-dist/html/main/index.html b/packages/server/prod-server/tests/fixtures/pure/test-dist/html/main/index.html index 49fb371d8f05..80b86049b548 100644 --- a/packages/server/prod-server/tests/fixtures/pure/test-dist/html/main/index.html +++ b/packages/server/prod-server/tests/fixtures/pure/test-dist/html/main/index.html @@ -2,7 +2,7 @@ - + @@ -13,24 +13,23 @@ - + - + -
- + - + diff --git a/packages/server/server/tests/fixtures/pure/test-dist/html/main/index.html b/packages/server/server/tests/fixtures/pure/test-dist/html/main/index.html index 49fb371d8f05..80b86049b548 100644 --- a/packages/server/server/tests/fixtures/pure/test-dist/html/main/index.html +++ b/packages/server/server/tests/fixtures/pure/test-dist/html/main/index.html @@ -2,7 +2,7 @@ - + @@ -13,24 +13,23 @@ - + - + -
- + - + diff --git a/packages/solutions/app-tools/src/analyze/templates.ts b/packages/solutions/app-tools/src/analyze/templates.ts index 654ce8bb13ae..20aa431bd4d9 100644 --- a/packages/solutions/app-tools/src/analyze/templates.ts +++ b/packages/solutions/app-tools/src/analyze/templates.ts @@ -110,7 +110,6 @@ export const html = (partials: { -