Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smart-showers-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime': patch
---

fix: use minify regex
fix: 用最小匹配来替换
2 changes: 1 addition & 1 deletion packages/runtime/plugin-runtime/src/document/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const documentPlugin = (): CliPluginFuture<AppTools<'shared'>> => ({

html = html.replace(
new RegExp(
`${DOCUMENT_SCRIPT_PLACEHOLDER_START}${DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*)${DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${DOCUMENT_SCRIPT_PLACEHOLDER_END}`,
`${DOCUMENT_SCRIPT_PLACEHOLDER_START}${DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*?)${DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${DOCUMENT_SCRIPT_PLACEHOLDER_END}`,
'g',
),
(_scriptStr, $1, $2) =>
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/app-document/src/sub/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export default function Document(): React.ReactElement {
console.log('this is a IIFE function');
}}
/>
<Script
defer
async
id="script-has-id2"
content={() => {
console.log('this is another IIFE function');
}}
/>
</Head>
<Body {...{ dir: 'ltr' }}>
<Root {...{ class: 'root' }}>
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/app-document/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ describe('test dev and build', () => {
htmlWithDoc.includes('console.log("this is a IIFE function")'),
).toBe(true);
});

test('should not break Script origin script properties', async () => {
const htmlWithDoc = fs.readFileSync(
path.join(appDir, 'dist', 'html/sub/index.html'),
'utf-8',
);

expect(
htmlWithDoc.includes('<script defer="" async="" id="script-has-id2">'),
).toBe(true);
// IIFE should worked
expect(
htmlWithDoc.includes('console.log("this is another IIFE function")'),
).toBe(true);
});
});

describe('test dev', () => {
Expand Down