Skip to content

Cancel pending search parameter writes on history navigation - #10583

Merged
tim-smart merged 9 commits into
Effect-TS:mainfrom
brandon-julio-t:fix/search-param-history-navigation
Nov 13, 2026
Merged

tim-smart merged 9 commits into
Effect-TS:mainfrom
brandon-julio-t:fix/search-param-history-navigation

Conversation

@brandon-julio-t

@brandon-julio-t brandon-julio-t commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10582.
Closes EFF-3700.

Typing a URL filter and pressing Back during Atom.searchParam's 500ms debounce currently overwrites the restored query when the pending timer runs. The atom has already read the restored value, so the displayed filter and URL disagree, and the stale push drops the Forward entry.

Change

A popstate listener discards the pending batch. It is registered before any search-param reader's own popstate listener and stays registered while a reader is mounted or a batch is pending, so it always runs first. Window dispatches in registration order, which means stale writes are gone before atom observers run and a write an observer makes in response to the navigation is kept. Capture priority does not give this ordering on Window, so it is not used.

Readers remain individual native listeners, as on main. The browser isolates their failures, so a throwing observer cannot stop other parameters from restoring.

A write now sets up its batch (pending value, cancellation listener, timer) before publishing the value. Synchronous observers that dispose the registry, write again, throw, or navigate therefore see a complete batch.

This covers raw and schema-backed parameters together, including traversal between entries on the same pathname. The debounce and ordinary writes are unchanged. Router navigation through pushState without an event is out of scope.

This isolates one independently reproduced concern from closed, unmerged Effect-TS/effect-smol#2382, without its router-specific history state changes. Merged #8820 fixed the separate URL hash and empty-query issues.

Verification

  • pnpm test --run packages/effect/test/reactivity/Atom.test.ts: 162 tests pass. The new cases fail against main and against each rejected intermediate approach (late or capture-phase cancellation, a shared dispatcher without failure isolation, publishing before the batch is set up).
  • Native Chromium with real history.back() / history.forward(): stale raw and schema writes are cancelled with no push and Forward still works; an observer that normalizes the restored value produces exactly one push; throwing observers are each reported while every reader still restores; disposal, nested writes and exceptions during the initial write keep cancellation; no popstate listener is left on window after disposal.
  • pnpm lint and pnpm check pass.

Prepared with assistance from OpenAI Codex.

A pending debounced search-param write can overwrite the URL restored by Back and remove the Forward entry. Cancel the pending batch on popstate and remove its listener when the batch flushes normally.

Two regression cases reproduce different-path and same-path navigation. Both fail before the fix; all 157 Atom tests pass afterward. A framework-free Chromium history probe also preserves the restored query after the change. Native debounce and normal history writes retain their existing behavior.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 045818c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-cloudflare Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

After Back cancels a pending raw and schema-backed batch, another page write must preserve the restored search text. This regression verifies that cancelled values cannot reappear in a later batch. All157Atomtests, lint and type checks pass.
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.88 KB 39.88 KB 0.00 KB (0.00%)
basic.ts 7.31 KB 7.31 KB 0.00 KB (0.00%)
batching.ts 11.21 KB 11.21 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.73 KB 11.73 KB 0.00 KB (0.00%)
config.ts 23.09 KB 23.09 KB 0.00 KB (0.00%)
differ.ts 22.20 KB 22.20 KB 0.00 KB (0.00%)
http-client.ts 27.44 KB 27.44 KB 0.00 KB (0.00%)
http-router.ts 37.35 KB 37.35 KB 0.00 KB (0.00%)
logger.ts 12.19 KB 12.19 KB 0.00 KB (0.00%)
metric.ts 9.64 KB 9.64 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.21 KB 16.21 KB 0.00 KB (0.00%)
queue.ts 13.09 KB 13.09 KB 0.00 KB (0.00%)
schedule.ts 11.99 KB 11.99 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.29 KB 14.29 KB 0.00 KB (0.00%)
schema-binary.ts 42.45 KB 42.45 KB 0.00 KB (0.00%)
schema-class.ts 21.96 KB 21.96 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.56 KB 30.56 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.26 KB 28.26 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.54 KB 15.54 KB 0.00 KB (0.00%)
schema-string.ts 12.50 KB 12.50 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.43 KB 16.43 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.41 KB 39.41 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.39 KB 26.39 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.11 KB 21.11 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.28 KB 21.28 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.37 KB 21.37 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.42 KB 26.42 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
stm.ts 14.40 KB 14.40 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)

@tim-smart
tim-smart enabled auto-merge (squash) November 13, 2026 10:50
@tim-smart
tim-smart merged commit 19c76ab into Effect-TS:main Nov 13, 2026
15 of 16 checks passed
@brandon-julio-t
brandon-julio-t deleted the fix/search-param-history-navigation branch November 14, 2026 01:44

This branch is waiting to be deployed

1 waiting deployment
fork — 045818ce Waiting Nov 13, 2026 by effect-bot via approval-gate #26134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atom.searchParam applies pending writes after Back navigation

3 participants