Skip to content

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jul 23, 2025

Summary

The current building‑blocks implementation behaves unexpectedly when you try to derive one store from another. Each building‑block function closes over the arguments and default values supplied to the original buildStore call, so a derived store reuses those captured values instead of its own, causing unintended behavior.

This PR refactors store internals to eliminate parent scope references.

API Changes

Changed

  • store prop added to all atom interceptors and building block functions
  • atomOnInit(atom, store) -> atomOnInit(store, atom)
  • INTERNAL_buildStore added args
    • setAtomStateValueOrPromise
    • storeGet
    • storeSet
    • storeSub
  • buildingBlocks added items
    • setAtomStateValueOrPromise
    • storeGet
    • storeSet
    • storeSub
  • type BuildingBlocks now mutable
  • INTERNAL_getBuildingBlocksRev2 returns type Readonly<BuildingBlocks>
  • store[BUILDING_BLOCKS] is frozen

Added

  • type INTERNAL_BuildingBlocks
  • type INTERNAL_StoreHooks

Removed

  • INTERNAL_SetAtomStateValueOrPromise

Check List

  • pnpm run fix for formatting and linting code and docs

Copy link

vercel bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
jotai Ready Ready Preview Comment Sep 7, 2025 11:53pm

Copy link

codesandbox-ci bot commented Jul 23, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

pkg-pr-new bot commented Jul 23, 2025

More templates

npm i https://pkg.pr.new/jotai@3105

commit: cc50fe1

Copy link

github-actions bot commented Jul 23, 2025

LiveCodes Preview in LiveCodes

Latest commit: cc50fe1
Last updated: Sep 7, 2025 11:53pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/FLUDNYK4A

See documentations for usage instructions.

@dmaskasky dmaskasky requested a review from dai-shi July 23, 2025 06:04
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to see some diffs, but I assume the logic is preserved.
Other than that, it's super clean and I like it. Splendid work!

@dai-shi
Copy link
Member

dai-shi commented Aug 28, 2025

@arjunvegda Please be aware that this is going to be a breaking change for you.

@dai-shi dai-shi merged commit 543f064 into pmndrs:main Sep 8, 2025
45 checks passed
@alex-kinokon
Copy link

This breaks jotai-effect due to the removal of INTERNAL_buildStoreRev1‎ (link).

cc @dmaskasky

@dmaskasky
Copy link
Collaborator Author

Yes, I have to update jotai-effect, and jotai-scope. I'll release this today.

@dmaskasky
Copy link
Collaborator Author

I just released [email protected], which now supports [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants