fix(bootstrap): chunk-reload can reload over a half-typed sign-up

Author: koala73Created Sep 26, 2026Updated Sep 26, 2026

installChunkReloadGuard reloads the page with no open-modal check, so it can destroy a half-typed Clerk sign-up. This is the same defect PR #8580 fixed for the stale-bundle path and #3184 fixed for the service-worker path. It is the one reload consumer that never got the guard.

src/bootstrap/chunk-reload.ts:

javascript
eventTarget.addEventListener(eventName, () => {
  if (storage.getItem(storageKey)) return;
  storage.setItem(storageKey, '1');
  reload();
});

Why this matters more than it looks

The trigger is vite:preloadError, which fires when a lazy chunk 404s. That happens when a tab holds an old bundle and requests a chunk the new deploy no longer has, so it is correlated with exactly the scenario the modal guard exists for. A user who leaves the app to fetch an emailed verification code is on an aging bundle by definition, and the code-entry modal is the surface a reload destroys.

Nobody has reported it. Worth remembering that #8580 accepted a residual risk because no reviewer could name a triggering surface, and #8593 then found one within the hour. Absence of a report is weak evidence here.

Why it was left out of the contract change

Deferring a failure-recovery reload is a different problem from deferring an upgrade reload, and it needs decisions this issue should settle:

  • If the reload is deferred, who fires it later? A second vite:preloadError may never arrive, because the failed import is not retried.
  • The one-shot sessionStorage key is already written before reload(). If the reload is deferred, the key has been burned and the retry is gone.
  • A chunk failure means some feature is broken now. Sitting in a broken state under an open modal may be worse for the user than losing the modal. That is a product call, not a mechanical one.

Current containment

scripts/enforce-overlay-reload-policy.mjs enforces that every reload() under src/bootstrap/ sits in a function consulting the reload predicate. This file is its only exemption:

javascript
export const RELOAD_GUARD_EXEMPT = new Map([
  ['src/bootstrap/chunk-reload.ts', 'failure recovery with no retry path; deferral semantics undecided'],
]);

The gate's self-test fails if that file stops having an unguarded call, so the exemption cannot outlive what it excuses. It is visible and self-expiring, not silent.

Suggested shape

Reuse the pendingReload pattern from src/bootstrap/stale-bundle-check.ts: on a blocked modal, remember the debt, do not burn the session key, and retry against the live DOM on the next focus or visibilitychange. Then delete the exemption entry, which the gate will require.

Acceptance: a test proving a vite:preloadError under a blocking overlay does not reload and does reload once the overlay closes, plus the exemption map empty.