Skip to content

Commit 2d20aba

Browse files
authored
fix: prevent from accessing outdated compilation (#8591)
1 parent 9335a8b commit 2d20aba

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

packages/rspack/src/Compilation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
11351135
}
11361136
}
11371137
);
1138-
},
1139-
10
1138+
}
11401139
))(this);
11411140

11421141
rebuildModule(m: Module, f: (err: Error, m: Module) => void) {
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
type CallFn<D> = (args: D[]) => void;
22

33
export default class MergeCaller<D> {
4-
private timer: any = null;
54
private callArgs: D[] = [];
65

7-
// add in constructor
8-
private debounceTime: number;
96
private callFn: CallFn<D>;
10-
constructor(fn: CallFn<D>, debounceTime: number) {
11-
this.debounceTime = debounceTime;
7+
constructor(fn: CallFn<D>) {
128
this.callFn = fn;
139
}
1410

1511
private finalCall = () => {
16-
this.timer = null;
1712
const args = this.callArgs;
1813
this.callArgs = [];
1914
this.callFn(args);
2015
};
2116

2217
push(...data: D[]) {
23-
if (this.timer) {
24-
clearTimeout(this.timer);
18+
if (this.callArgs.length === 0) {
19+
queueMicrotask(this.finalCall);
2520
}
26-
2721
this.callArgs.push(...data);
28-
29-
this.timer = setTimeout(this.finalCall, this.debounceTime);
3022
}
3123
}

packages/rspack/src/util/fake.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function createFakeCompilationDependencies(
66
getDeps: () => string[],
77
addDeps: (deps: string[]) => void
88
) {
9-
const addDepsCaller = new MergeCaller(addDeps, 10);
9+
const addDepsCaller = new MergeCaller(addDeps);
1010
return {
1111
*[Symbol.iterator]() {
1212
const deps = getDeps();

0 commit comments

Comments
 (0)