Skip to content

Fix hydrated atom reactivity initial values#6551

Open
xianjianlf2 wants to merge 1 commit into
Effect-TS:mainfrom
xianjianlf2:fix/hydrated-atom-reactivity-6360
Open

Fix hydrated atom reactivity initial values#6551
xianjianlf2 wants to merge 1 commit into
Effect-TS:mainfrom
xianjianlf2:fix/hydrated-atom-reactivity-6360

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • route hydrated serializable atom values through the same initial-value target path used by AtomRegistry initialValues
  • keep hydrated nodes stale until first read so withReactivity can register its finalizer before mutations
  • add a regression test for hydrated serializable atoms with reactivity

Fixes #6360.

Tests

  • pnpm lint-fix
  • pnpm test packages/effect/test/reactivity/Atom.test.ts
  • pnpm check

Summary by CodeRabbit

  • Bug Fixes

    • Fixed reactivity for hydrated serializable atoms.
    • Hydrated atoms now respond correctly to subsequent updates and trigger expected rebuilds.
    • Improved initialization behavior when atoms derive their values from other atoms.
  • Tests

    • Added coverage for hydration and reactive updates of serializable atoms.

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

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 48d6b5e

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

This PR includes changesets to release 27 packages
Name Type
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-react 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/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 23, 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: 92d11bc6-a9c1-42ca-ba51-5a6a49f284cd

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0be58 and 48d6b5e.

📒 Files selected for processing (3)
  • .changeset/fix-hydrated-atom-reactivity.md
  • packages/effect/src/unstable/reactivity/AtomRegistry.ts
  • packages/effect/test/reactivity/Atom.test.ts

📝 Walkthrough

Walkthrough

Hydrated serializable atoms now resolve their initial-value target and use setInitialValue, allowing reactivity callbacks to register during the initial read. A regression test verifies updates after hydration, and the changeset declares a patch release.

Changes

Hydrated atom reactivity

Layer / File(s) Summary
Route hydrated values through initial-value targets
packages/effect/src/unstable/reactivity/AtomRegistry.ts
Centralizes initialValueTarget traversal and applies decoded hydrated values through setInitialValue on the resolved node.
Validate hydrated reactivity behavior
packages/effect/test/reactivity/Atom.test.ts, .changeset/fix-hydrated-atom-reactivity.md
Adds hydration and rebuild assertions for serializable atoms and records a patch release.

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

Sequence Diagram(s)

sequenceDiagram
  participant Hydration
  participant AtomRegistry
  participant Atom
  participant Reactivity
  Hydration->>AtomRegistry: hydrate dehydrated atom state
  AtomRegistry->>AtomRegistry: resolve initialValueTarget
  AtomRegistry->>Atom: setInitialValue(decoded value)
  Atom->>Reactivity: register invalidation callback during read
  Reactivity->>AtomRegistry: trigger rebuild after mutation
Loading

Possibly related PRs

Suggested reviewers: tim-smart, gcanti

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The hydration path now mirrors initialValues by resolving initialValueTarget and using setInitialValue, which matches #6360's requirement.
Out of Scope Changes check ✅ Passed The changes are scoped to the hydration reactivity fix, its regression test, and release metadata; no unrelated code changes appear.

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

@IMax153
IMax153 requested a review from tim-smart July 23, 2026 10:26
@IMax153 IMax153 added bug Something isn't working 4.0 labels Jul 23, 2026
@tim-smart

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tim-smart
tim-smart enabled auto-merge (squash) July 23, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

withReactivity callback never registers when atom is hydrated via Hydration.hydrate

3 participants