Skip to content

v8.2.3 — Defer LocationChangeBridge dispatch to escape React commit (#43)

Choose a tag to compare

@CaspianTools CaspianTools released this 27 Apr 04:27
· 142 commits to main since this release

Defer LocationChangeBridge dispatch to escape React's commit phase (#43 / mod1183)

v8.2.2 introduced <LocationChangeBridge /> which patches history.pushState / replaceState to dispatch a caspian:locationchange event after the URL updates. The event was dispatched synchronously from inside the patched function. That broke under Next.js App Router 14+: Next.js calls history.pushState from inside a useInsertionEffect during React's commit phase, the synchronous event triggered <SearchResultsPage>'s listener, and React threw useInsertionEffect must not schedule updates on every search submission.

This release defers the dispatch to a microtask via queueMicrotask. Microtasks run after the commit phase completes, so listeners' state updates land outside the insertion-effect window and React processes them as normal post-commit updates. This does not reintroduce the v8.1.4 race (where a microtask fired before the URL was updated), because here the microtask is queued from inside the patched pushState after the original pushState has already updated the URL — by the time the microtask runs, window.location.search is guaranteed to reflect the new query.

No consumer action required

Drop-in patch. Reinstalling the new tag silences the React error and restores the expected behaviour: typing a new search term while on /search updates results without a reload, with no console warnings.

Install

npm install github:Caspian-Explorer/script-caspian-store#v8.2.3

After upgrading, restart your Next.js dev server and hard-reload the browser so the new client bundle loads.