From bf3250afd5ddc63903c74090d9a326319e0a9e38 Mon Sep 17 00:00:00 2001 From: clchenliang Date: Fri, 25 Aug 2023 16:55:05 +0800 Subject: [PATCH 1/5] fix: not set partials html receive extra placeholder --- .../plugin-runtime/src/document/cli/index.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/runtime/plugin-runtime/src/document/cli/index.ts b/packages/runtime/plugin-runtime/src/document/cli/index.ts index b19b788af947..94946c197bb1 100644 --- a/packages/runtime/plugin-runtime/src/document/cli/index.ts +++ b/packages/runtime/plugin-runtime/src/document/cli/index.ts @@ -189,16 +189,25 @@ export const documentPlugin = (): CliPlugin => ({ htmlWebpackPlugin.tags.bodyTags.toString(), ].join(''); // support partials html + const partialsContent = { + partialsTop: '', + partialsHead: '', + partialsBody: '', + }; if (partialsByEntrypoint?.[entryName]) { - const partialsTop = partialsByEntrypoint[entryName].top.join('\n'); - const partialsHead = partialsByEntrypoint[entryName].head.join('\n'); - const partialsBody = partialsByEntrypoint[entryName].body.join('\n'); - html = html - .replace(TOP_PARTICALS_SEPARATOR, partialsTop) - .replace(HEAD_PARTICALS_SEPARATOR, partialsHead) - .replace(BODY_PARTICALS_SEPARATOR, partialsBody); + partialsContent.partialsTop = + partialsByEntrypoint[entryName].top.join('\n'); + partialsContent.partialsHead = + partialsByEntrypoint[entryName].head.join('\n'); + partialsContent.partialsBody = + partialsByEntrypoint[entryName].body.join('\n'); } + html = html + .replace(TOP_PARTICALS_SEPARATOR, partialsContent.partialsTop) + .replace(HEAD_PARTICALS_SEPARATOR, partialsContent.partialsHead) + .replace(BODY_PARTICALS_SEPARATOR, partialsContent.partialsBody); + const links = [ htmlWebpackPlugin.tags.headTags .filter((item: any) => item.tagName === 'link') From 47c161ecf97eaf17d5efb19efd8424dcfc4fc2e7 Mon Sep 17 00:00:00 2001 From: clchenliang Date: Fri, 25 Aug 2023 17:01:40 +0800 Subject: [PATCH 2/5] docs: add changeset --- .changeset/chilled-walls-sort.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/chilled-walls-sort.md diff --git a/.changeset/chilled-walls-sort.md b/.changeset/chilled-walls-sort.md new file mode 100644 index 000000000000..9c886a3135ae --- /dev/null +++ b/.changeset/chilled-walls-sort.md @@ -0,0 +1,6 @@ +--- +'@modern-js/runtime': patch +--- + +fix: html has placeholder when not set partials +fix: html 在没有设置 partials 的时候,会多出占位符 From 58989e30a3a41406507406f650829c72d9ded68a Mon Sep 17 00:00:00 2001 From: clchenliang Date: Fri, 25 Aug 2023 17:51:11 +0800 Subject: [PATCH 3/5] test: add integration test --- .../integration/app-document/modern.config.ts | 24 ++----------------- .../src/differentProperities/pages/index.tsx | 10 ++++++++ .../app-document/tests/index.test.ts | 9 +++++++ 3 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 tests/integration/app-document/src/differentProperities/pages/index.tsx diff --git a/tests/integration/app-document/modern.config.ts b/tests/integration/app-document/modern.config.ts index 3d9a765995e9..149f3a0fd36b 100644 --- a/tests/integration/app-document/modern.config.ts +++ b/tests/integration/app-document/modern.config.ts @@ -1,26 +1,6 @@ -import { - AppTools, - appTools, - CliPlugin, - defineConfig, -} from '@modern-js/app-tools'; +import { appTools, defineConfig } from '@modern-js/app-tools'; import { routerPlugin } from '@modern-js/plugin-router-v5'; -const tmpTest = (): CliPlugin => ({ - name: 'tmpTest', - setup: () => { - return { - htmlPartials({ entrypoint, partials }) { - partials.top.push(''); - partials.head.push(''); - partials.body.push(''); - - return { partials, entrypoint }; - }, - }; - }, -}); - export default defineConfig({ runtime: { router: { @@ -43,5 +23,5 @@ export default defineConfig({ favicon: './static/a.icon', }, output: {}, - plugins: [appTools(), routerPlugin(), tmpTest()], + plugins: [appTools(), routerPlugin()], }); diff --git a/tests/integration/app-document/src/differentProperities/pages/index.tsx b/tests/integration/app-document/src/differentProperities/pages/index.tsx new file mode 100644 index 000000000000..edcd04d7d5b1 --- /dev/null +++ b/tests/integration/app-document/src/differentProperities/pages/index.tsx @@ -0,0 +1,10 @@ +import { Link } from '@modern-js/runtime/router-v5'; + +const App = () => ( + <> + 去 A + 去 B + +); + +export default App; diff --git a/tests/integration/app-document/tests/index.test.ts b/tests/integration/app-document/tests/index.test.ts index 73c8d657091e..53214e1b4760 100644 --- a/tests/integration/app-document/tests/index.test.ts +++ b/tests/integration/app-document/tests/index.test.ts @@ -170,6 +170,15 @@ describe('test build', () => { expect(htmlWithDoc.includes(`head class="head"`)).toBe(true); }); + test('when not set partial html should normal', async () => { + const normalHtml = fs.readFileSync( + path.join(appDir, 'dist', 'html/differentProperities/index.html'), + 'utf-8', + ); + const partialPlaceholder = encodeURIComponent(''); + expect(new RegExp(partialPlaceholder).test(normalHtml)).toBe(false); + }); + test('should injected partial html content to html', async () => { const htmlWithDoc = fs.readFileSync( path.join(appDir, 'dist', 'html/sub/index.html'), From 7b81ade821d90cbc686d6f006554e2357a182ce1 Mon Sep 17 00:00:00 2001 From: clchenliang Date: Sun, 27 Aug 2023 21:53:48 +0800 Subject: [PATCH 4/5] fix: test leave both setting --- .../integration/app-document/modern.config.ts | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/integration/app-document/modern.config.ts b/tests/integration/app-document/modern.config.ts index 149f3a0fd36b..dcaf054c5c19 100644 --- a/tests/integration/app-document/modern.config.ts +++ b/tests/integration/app-document/modern.config.ts @@ -1,6 +1,29 @@ -import { appTools, defineConfig } from '@modern-js/app-tools'; +import { + AppTools, + appTools, + CliPlugin, + defineConfig, +} from '@modern-js/app-tools'; import { routerPlugin } from '@modern-js/plugin-router-v5'; +export const tmpTest = (): CliPlugin => ({ + name: 'tmpTest', + setup: () => { + return { + htmlPartials({ entrypoint, partials }) { + console.log('===> e.name: ', entrypoint.entryName); + if (entrypoint.entryName === 'sub') { + partials.top.push(''); + partials.head.push(''); + partials.body.push(''); + } + + return { partials, entrypoint }; + }, + }; + }, +}); + export default defineConfig({ runtime: { router: { @@ -23,5 +46,5 @@ export default defineConfig({ favicon: './static/a.icon', }, output: {}, - plugins: [appTools(), routerPlugin()], + plugins: [appTools(), routerPlugin(), tmpTest()], }); From 7f2a221f46f23db1e93f6d3e09d84e45fdf120b1 Mon Sep 17 00:00:00 2001 From: clchenliang Date: Sun, 27 Aug 2023 21:56:12 +0800 Subject: [PATCH 5/5] docs: remove comments --- tests/integration/app-document/modern.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/app-document/modern.config.ts b/tests/integration/app-document/modern.config.ts index dcaf054c5c19..f6d46f2a394e 100644 --- a/tests/integration/app-document/modern.config.ts +++ b/tests/integration/app-document/modern.config.ts @@ -11,7 +11,6 @@ export const tmpTest = (): CliPlugin => ({ setup: () => { return { htmlPartials({ entrypoint, partials }) { - console.log('===> e.name: ', entrypoint.entryName); if (entrypoint.entryName === 'sub') { partials.top.push(''); partials.head.push('');