Skip to content

Commit

Permalink
fix: persistent cache use lazy compilation restart failure (#8952)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz authored Jan 7, 2025
1 parent 2cfa879 commit c1a29f4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crates/rspack_plugin_lazy_compilation/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::Path, sync::Arc};

use cow_utils::CowUtils;
use rspack_cacheable::{cacheable, cacheable_dyn};
use rspack_cacheable::{cacheable, cacheable_dyn, with::Unsupported};
use rspack_collections::Identifiable;
use rspack_core::{
impl_module_meta_info, module_namespace_promise, module_update_hash,
Expand Down Expand Up @@ -45,6 +45,8 @@ pub(crate) struct LazyCompilationProxyModule {

pub active: bool,
pub data: String,
/// The client field will be refreshed when rspack restart, so this field does not support caching
#[cacheable(with=Unsupported)]
pub client: String,
}

Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/cases/lazy-compilation/persistent-cache/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, test } from "@/fixtures";

test("should load success", async ({ page, rspack }) => {
await page.getByText("Click me").click();
let component_count = await page.getByText("Component").count();
expect(component_count).toBe(1);

const responsePromise = page.waitForResponse(
response =>
response.url().includes("lazy-compilation-using") &&
response.request().method() === "GET",
{ timeout: 5000 }
);
await rspack.reboot();
await page.reload();
await responsePromise;

await page.getByText("Click me").click();
component_count = await page.getByText("Component").count();
expect(component_count).toBe(1);
});
22 changes: 22 additions & 0 deletions tests/e2e/cases/lazy-compilation/persistent-cache/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const rspack = require("@rspack/core");

/** @type { import('@rspack/core').RspackOptions } */
module.exports = {
context: __dirname,
entry: {
main: ["./src/component.js", "./src/index.js"]
},
stats: "none",
mode: "production",
plugins: [new rspack.HtmlRspackPlugin()],
cache: true,
experiments: {
lazyCompilation: true,
cache: {
type: "persistent"
}
},
devServer: {
hot: true
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const button = document.createElement("button");
button.textContent = "Component";
document.body.appendChild(button);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const button = document.createElement("button");
button.textContent = "Click me";
document.body.appendChild(button);
48 changes: 44 additions & 4 deletions tests/e2e/fixtures/rspack.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import path from "node:path";
import type { Fixtures, PlaywrightTestArgs } from "@playwright/test";
import { type Compiler, type Configuration, rspack } from "@rspack/core";
import {
type Compiler,
type Configuration,
rspack,
type RspackOptions as RspackConfig
} from "@rspack/core";
import { RspackDevServer } from "@rspack/dev-server";
import WebpackDevServer from "webpack-dev-server";
import type { PathInfoFixtures } from "./pathInfo";

class Rspack {
private wds: boolean;
private config: RspackConfig;
projectDir: string;
compiler: Compiler;
devServer: RspackDevServer | WebpackDevServer;
Expand All @@ -15,10 +22,12 @@ class Rspack {
wds: boolean,
handleRspackConfig: (config: Configuration) => Configuration
) {
this.wds = wds;

const configPath = path.resolve(projectDir, "rspack.config.js");
const config = handleRspackConfig(require(configPath));
this.config = handleRspackConfig(require(configPath));
delete require.cache[configPath];
const compiler = rspack(config);
const compiler = rspack(this.config);

this.projectDir = projectDir;
this.compiler = compiler;
Expand All @@ -29,7 +38,7 @@ class Rspack {
item();
}
});
const DevServerConstructor = wds ? WebpackDevServer : RspackDevServer;
const DevServerConstructor = this.wds ? WebpackDevServer : RspackDevServer;
this.devServer = new DevServerConstructor(
compiler.options.devServer ?? ({} as any),
compiler
Expand All @@ -46,6 +55,37 @@ class Rspack {
this.onDone.push(resolve);
});
}

async reboot() {
await new Promise<void>((res, rej) => {
this.compiler.close(function (err) {
if (err) {
rej(err);
} else {
res();
}
});
});
await this.devServer.stop();

const compiler = rspack(this.config);
compiler.hooks.done.tap("rspack_fixture", () => {
const onDone = this.onDone;
this.onDone = [];
for (const item of onDone) {
item();
}
});
const DevServerConstructor = this.wds ? WebpackDevServer : RspackDevServer;
this.devServer = new DevServerConstructor(
compiler.options.devServer ?? ({} as any),
compiler
);
this.compiler = compiler;

await this.devServer.start();
await this.waitingForBuild();
}
}

export type RspackOptions = {
Expand Down

2 comments on commit c1a29f4

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on c1a29f4 Jan 7, 2025

Choose a reason for hiding this comment

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

📝 Ecosystem CI detail: Open

suite result
modernjs ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on c1a29f4 Jan 7, 2025

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2025-01-07 0a4e43a) Current Change
10000_big_production-mode_disable-minimize + exec 37.4 s ± 374 ms 38.5 s ± 268 ms +2.88 %
10000_development-mode + exec 1.88 s ± 30 ms 1.9 s ± 78 ms +1.35 %
10000_development-mode_hmr + exec 679 ms ± 2.4 ms 676 ms ± 4.3 ms -0.52 %
10000_production-mode + exec 2.53 s ± 44 ms 2.5 s ± 25 ms -1.14 %
arco-pro_development-mode + exec 1.73 s ± 91 ms 1.75 s ± 84 ms +1.35 %
arco-pro_development-mode_hmr + exec 377 ms ± 1.2 ms 377 ms ± 1.4 ms +0.22 %
arco-pro_production-mode + exec 3.65 s ± 83 ms 3.58 s ± 109 ms -1.79 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.66 s ± 87 ms 3.62 s ± 86 ms -1.21 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.62 s ± 92 ms 3.61 s ± 121 ms -0.33 %
threejs_development-mode_10x + exec 1.51 s ± 18 ms 1.52 s ± 14 ms +0.69 %
threejs_development-mode_10x_hmr + exec 774 ms ± 25 ms 789 ms ± 18 ms +1.88 %
threejs_production-mode_10x + exec 5.36 s ± 68 ms 5.37 s ± 53 ms +0.20 %
10000_big_production-mode_disable-minimize + rss memory 9486 MiB ± 155 MiB 9506 MiB ± 48 MiB +0.21 %
10000_development-mode + rss memory 658 MiB ± 15 MiB 666 MiB ± 19.1 MiB +1.33 %
10000_development-mode_hmr + rss memory 1353 MiB ± 356 MiB 1405 MiB ± 336 MiB +3.83 %
10000_production-mode + rss memory 622 MiB ± 31.1 MiB 651 MiB ± 22.6 MiB +4.65 %
arco-pro_development-mode + rss memory 602 MiB ± 27.6 MiB 557 MiB ± 23 MiB -7.43 %
arco-pro_development-mode_hmr + rss memory 651 MiB ± 66.9 MiB 597 MiB ± 83.9 MiB -8.36 %
arco-pro_production-mode + rss memory 754 MiB ± 70.8 MiB 719 MiB ± 42 MiB -4.58 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 748 MiB ± 38 MiB 711 MiB ± 31.9 MiB -4.94 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 757 MiB ± 81.4 MiB 731 MiB ± 57.1 MiB -3.47 %
threejs_development-mode_10x + rss memory 630 MiB ± 27.7 MiB 572 MiB ± 8.66 MiB -9.27 %
threejs_development-mode_10x_hmr + rss memory 1222 MiB ± 197 MiB 1132 MiB ± 162 MiB -7.43 %
threejs_production-mode_10x + rss memory 911 MiB ± 48.7 MiB 847 MiB ± 49.9 MiB -7.04 %
large-dyn-imports_development-mode + exec - 2.17 s ± 44 ms -
large-dyn-imports_production-mode + exec - 2.16 s ± 28 ms -
large-dyn-imports_development-mode + rss memory - 624 MiB ± 2.99 MiB -
large-dyn-imports_production-mode + rss memory - 521 MiB ± 2.39 MiB -

Please sign in to comment.