Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions e2e/cases/nonce/dynamic-chunk/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { build, dev } from '@e2e/helper';
import { expect, test } from '@playwright/test';

declare global {
interface Window {
dynamicChunkNonce?: string;
}
}

test('should apply nonce to dynamic chunks in dev build', async ({ page }) => {
const rsbuild = await dev({
cwd: __dirname,
page,
});

await page.waitForFunction(
() => window.dynamicChunkNonce !== undefined,
undefined,
{
timeout: 2000,
},
);

expect(await page.evaluate('window.dynamicChunkNonce')).toEqual(
'CSP_NONCE_PLACEHOLDER',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down Expand Up @@ -482,6 +486,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down
16 changes: 2 additions & 14 deletions packages/core/src/client/hmr.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why you changed the HMR runtime code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Web socket connect too slow, so serve side will do first `lazyCompilation` completely quickly. But at this time, web socket is not connected. So we need do a hmr action when web socket connect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, great chart! This is very clear

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function formatURL(fallback?: boolean) {
}

// Remember some state related to hot module replacement.
let isFirstCompilation = true;
let lastCompilationHash: string | undefined;
let hasCompileErrors = false;

Expand All @@ -55,22 +54,15 @@ export const registerOverlay = (
function handleSuccess() {
clearOutdatedErrors();

const isHotUpdate = !isFirstCompilation;
isFirstCompilation = false;
hasCompileErrors = false;

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
tryApplyUpdates();
}
tryApplyUpdates();
}

// Compilation with warnings (e.g. ESLint).
function handleWarnings({ text }: { text: string[] }) {
clearOutdatedErrors();

const isHotUpdate = !isFirstCompilation;
isFirstCompilation = false;
hasCompileErrors = false;

for (let i = 0; i < text.length; i++) {
Expand All @@ -83,17 +75,13 @@ function handleWarnings({ text }: { text: string[] }) {
console.warn(text[i]);
}

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
tryApplyUpdates();
}
tryApplyUpdates();
}

// Compilation with errors (e.g. syntax error or missing modules).
function handleErrors({ text, html }: { text: string[]; html: string }) {
clearOutdatedErrors();

isFirstCompilation = false;
hasCompileErrors = true;

// Also log them to the console.
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ export const withDefaultConfig = async (
}
}

if (merged.dev?.lazyCompilation === undefined) {
merged.dev ||= {};
merged.dev.lazyCompilation = {
imports: true,
entries: false,
};
}

if (!merged.source.tsconfigPath) {
const tsconfigPath = join(rootPath, TS_CONFIG_FILE);

Expand Down
4 changes: 4 additions & 0 deletions packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ exports[`should use Rspack as the default bundler > apply Rspack correctly 1`] =
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"rspackFuture": {
"bundlerInfo": {
"force": false,
Expand Down
12 changes: 12 additions & 0 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"rspackFuture": {
"bundlerInfo": {
"force": false,
Expand Down Expand Up @@ -517,6 +521,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"rspackFuture": {
"bundlerInfo": {
"force": false,
Expand Down Expand Up @@ -1480,6 +1488,10 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"rspackFuture": {
"bundlerInfo": {
"force": false,
Expand Down
32 changes: 32 additions & 0 deletions packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ exports[`environment config > should print environment config when inspect confi
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -448,6 +452,10 @@ exports[`environment config > should print environment config when inspect confi
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -610,6 +618,10 @@ exports[`environment config > should support modify environment config by api.mo
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -752,6 +764,10 @@ exports[`environment config > should support modify environment config by api.mo
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -895,6 +911,10 @@ exports[`environment config > should support modify environment config by api.mo
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -1041,6 +1061,10 @@ exports[`environment config > should support modify single environment config by
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -1183,6 +1207,10 @@ exports[`environment config > should support modify single environment config by
"reconnect": 100,
},
"hmr": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"liveReload": true,
"watchFiles": [],
"writeToDisk": false,
Expand Down Expand Up @@ -1324,6 +1352,10 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
"devtool": "eval-source-map",
"experiments": {
"asyncWebAssembly": true,
"lazyCompilation": {
"entries": false,
"imports": true,
},
"rspackFuture": {
"bundlerInfo": {
"force": false,
Expand Down
Loading