Skip to content

Fix useAtomSuspense registry isolation - #6672

Merged
tim-smart merged 1 commit into
Effect-TS:mainfrom
andrskr:agent/fix-atom-suspense-registry-cache
Jul 27, 2026
Merged

Fix useAtomSuspense registry isolation#6672
tim-smart merged 1 commit into
Effect-TS:mainfrom
andrskr:agent/fix-atom-suspense-registry-cache

Conversation

@andrskr

@andrskr andrskr commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • scope pending useAtomSuspense promises to the active AtomRegistry
  • preserve promise deduplication for the same atom and registry, including the separate suspendOnWaiting mode
  • add a regression test proving that two registries using the same atom resolve independently

Root cause

The Suspense promise cache was module-global and keyed only by atom. When two registries rendered the same atom concurrently, the second registry reused the first registry's promise. Its Suspense boundary therefore remained blocked even after its own atom reached a successful result.

Using registry-scoped WeakMaps keeps the existing atom-level deduplication without coupling independent registries or retaining disposed registries.

Validation

  • verified the new regression failed before the implementation change
  • pnpm test --run packages/atom/react/test/index.test.tsx
  • focused regression repeated five times
  • pnpm --filter @effect/atom-react check
  • pnpm --filter @effect/atom-react build
  • pnpm check
  • pnpm lint
  • pnpm test-types --target '>=5.9'
  • pnpm circular

Summary by CodeRabbit

  • Bug Fixes

    • Fixed useAtomSuspense so concurrent atom registries resolve independently.
    • Prevented updates in one registry from incorrectly resolving suspense boundaries in another.
  • Tests

    • Added coverage verifying isolated suspense behavior across separate atom registries.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 27, 2026
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bb46f2f

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

This PR includes changesets to release 28 packages
Name Type
@effect/atom-react Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-solid Patch
@effect/atom-vue 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/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

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4fa3a983-7b26-48cb-aa36-802a76e0d8dc

📥 Commits

Reviewing files that changed from the base of the PR and between 0a532e5 and bb46f2f.

📒 Files selected for processing (3)
  • .changeset/fix-atom-suspense-registry-cache.md
  • packages/atom/react/src/Hooks.ts
  • packages/atom/react/test/index.test.tsx

📝 Walkthrough

Walkthrough

useAtomSuspense now scopes cached promises by AtomRegistry, allowing separate registries to resolve independently. A runtime test verifies isolated Suspense boundaries, and a patch changeset documents the behavior.

Changes

Atom suspense registry isolation

Layer / File(s) Summary
Registry-scoped suspense cache
packages/atom/react/src/Hooks.ts, packages/atom/react/test/index.test.tsx, .changeset/fix-atom-suspense-registry-cache.md
atomToPromise uses nested registry- and atom-keyed WeakMaps, while the test verifies independent resolution across two registries and the changeset records the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: bug

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@andrskr
andrskr marked this pull request as ready for review July 27, 2026 20:28
@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB +0.00 KB (+0.05%)
batching.ts 9.37 KB 9.37 KB +0.00 KB (+0.01%)
brand.ts 6.26 KB 6.26 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB -0.00 KB (-0.01%)
config.ts 19.21 KB 19.22 KB -0.00 KB (-0.01%)
differ.ts 18.42 KB 18.42 KB -0.00 KB (-0.01%)
http-client.ts 20.76 KB 20.76 KB -0.00 KB (-0.00%)
logger.ts 10.28 KB 10.28 KB +0.00 KB (+0.02%)
metric.ts 8.55 KB 8.55 KB -0.00 KB (-0.04%)
optic.ts 7.41 KB 7.41 KB 0.00 KB (0.00%)
pubsub.ts 14.20 KB 14.20 KB -0.00 KB (-0.01%)
queue.ts 11.08 KB 11.09 KB -0.00 KB (-0.03%)
schedule.ts 10.28 KB 10.27 KB +0.00 KB (+0.03%)
schema-class.ts 18.16 KB 18.16 KB -0.00 KB (-0.01%)
schema-fromJsonSchemaDocument.ts 28.02 KB 28.02 KB -0.00 KB (-0.00%)
schema-representation-roundtrip.ts 24.33 KB 24.34 KB -0.00 KB (-0.01%)
schema-string-transformation.ts 12.69 KB 12.69 KB +0.00 KB (+0.02%)
schema-string.ts 10.35 KB 10.35 KB +0.00 KB (+0.02%)
schema-template-literal.ts 14.49 KB 14.49 KB -0.00 KB (-0.02%)
schema-toArbitraryLazy.ts 20.93 KB 20.93 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 23.38 KB 23.38 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.32 KB 18.32 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.00 KB 18.00 KB -0.01 KB (-0.03%)
schema-toFormatter.ts 17.88 KB 17.88 KB +0.00 KB (+0.01%)
schema-toJsonSchemaDocument.ts 21.51 KB 21.52 KB -0.00 KB (-0.01%)
schema-toRepresentation.ts 18.55 KB 18.56 KB -0.00 KB (-0.01%)
schema.ts 17.43 KB 17.43 KB +0.00 KB (+0.01%)
stm.ts 12.05 KB 12.05 KB -0.00 KB (-0.02%)
stream.ts 9.36 KB 9.37 KB -0.00 KB (-0.02%)

@tim-smart
tim-smart merged commit 83d571c into Effect-TS:main Jul 27, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants