Skip to content

Commit 6f96397

Browse files
committed
fix: prevent duplicate bundles
- on startup we had two requests each time due to the svelte version changes in #1319, and the file was always marked as changed. Fixed by not notifying when the version info comes from the bundle worker - migrate had two bundle requests, one from the direct `rebundle()` call, the second one because `update_file` invoked `on_update` that also invoked `rebundle()` -> remove the direct invocation - `reset` always did two request, because `this.set` already calls `#onreset` -> deduplicate
1 parent befc0a4 commit 6f96397

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

packages/repl/src/lib/Input/ComponentSelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
<input
183183
value={workspace.svelte_version}
184184
placeholder="latest"
185-
onchange={(ev) => (workspace.svelte_version = ev.currentTarget.value || 'latest')}
185+
onchange={(ev) => workspace.set_svelte_version(ev.currentTarget.value || 'latest', true)}
186186
/>
187187
</label>
188188

packages/repl/src/lib/Repl.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@
127127
...workspace.current!,
128128
contents: migration!.code
129129
});
130-
131-
rebundle();
132130
}
133131
134132
let width = $state(0);
@@ -142,7 +140,7 @@
142140
? new Bundler({
143141
svelte_version: svelteVersion,
144142
onversion: (version) => {
145-
workspace.svelte_version = version;
143+
workspace.set_svelte_version(version);
146144
onversion?.(version);
147145
},
148146
onstatus: (message) => {

packages/repl/src/lib/Workspace.svelte.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,13 @@ export class Workspace {
407407
selected?: string
408408
) {
409409
this.states.clear();
410-
this.set(new_files, selected);
410+
const bundle = this.set(new_files, selected);
411411

412412
this.mark_saved();
413413

414414
this.#tailwind = options.tailwind;
415415
this.#aliases = options.aliases;
416416

417-
const bundle = this.#onreset(new_files);
418417
const diagnostics = this.#reset_diagnostics();
419418

420419
return Promise.all([bundle, diagnostics])
@@ -458,7 +457,7 @@ export class Workspace {
458457
}
459458
}
460459

461-
this.#onreset?.(this.files);
460+
return this.#onreset?.(this.files);
462461
}
463462

464463
unlink(view: EditorView) {
@@ -507,10 +506,12 @@ export class Workspace {
507506
return this.#svelte_version;
508507
}
509508

510-
set svelte_version(value) {
509+
set_svelte_version(value, notify = false) {
511510
this.#svelte_version = value;
512-
this.#update_file(this.#current);
513-
this.#reset_diagnostics();
511+
if (notify) {
512+
this.#update_file(this.#current);
513+
this.#reset_diagnostics();
514+
}
514515
}
515516

516517
get vim() {

0 commit comments

Comments
 (0)