Skip to content

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Jul 23, 2025

To expand our idea.

Copy link

vercel bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 3:39am

Copy link

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@3104

commit: 7c5bbc8

Copy link

Size Change: +1.35 kB (+1.37%)

Total Size: 99.6 kB

Filename Size Change
./dist/esm/vanilla.mjs 1.51 kB +319 B (+26.74%) 🚨
./dist/esm/vanilla/internals.mjs 3.57 kB -163 B (-4.36%)
./dist/system/vanilla.development.js 1.61 kB +326 B (+25.45%) 🚨
./dist/system/vanilla.production.js 555 B +205 B (+58.57%) 🆘
./dist/system/vanilla/internals.development.js 3.71 kB -172 B (-4.44%)
./dist/system/vanilla/internals.production.js 2.26 kB -103 B (-4.36%)
./dist/umd/vanilla.development.js 2.25 kB +343 B (+18.01%) ⚠️
./dist/umd/vanilla.production.js 678 B +275 B (+68.24%) 🆘
./dist/umd/vanilla/internals.development.js 5.18 kB +12 B (+0.23%)
./dist/umd/vanilla/internals.production.js 3.09 kB -109 B (-3.41%)
./dist/vanilla.js 2.21 kB +403 B (+22.3%) 🚨
./dist/vanilla/internals.js 5.04 kB +13 B (+0.26%)
ℹ️ View Unchanged
Filename Size
./dist/babel/plugin-debug-label.js 932 B
./dist/babel/plugin-react-refresh.js 1.14 kB
./dist/babel/preset.js 1.41 kB
./dist/esm/babel/plugin-debug-label.mjs 1 kB
./dist/esm/babel/plugin-react-refresh.mjs 1.19 kB
./dist/esm/babel/preset.mjs 1.49 kB
./dist/esm/index.mjs 62 B
./dist/esm/react.mjs 1.46 kB
./dist/esm/react/utils.mjs 746 B
./dist/esm/utils.mjs 67 B
./dist/esm/vanilla/utils.mjs 5.09 kB
./dist/index.js 242 B
./dist/react.js 1.51 kB
./dist/react/utils.js 1.4 kB
./dist/system/babel/plugin-debug-label.development.js 1.1 kB
./dist/system/babel/plugin-debug-label.production.js 775 B
./dist/system/babel/plugin-react-refresh.development.js 1.29 kB
./dist/system/babel/plugin-react-refresh.production.js 928 B
./dist/system/babel/preset.development.js 1.59 kB
./dist/system/babel/preset.production.js 1.14 kB
./dist/system/index.development.js 252 B
./dist/system/index.production.js 183 B
./dist/system/react.development.js 1.64 kB
./dist/system/react.production.js 960 B
./dist/system/react/utils.development.js 860 B
./dist/system/react/utils.production.js 462 B
./dist/system/utils.development.js 257 B
./dist/system/utils.production.js 187 B
./dist/system/vanilla/utils.development.js 5.29 kB
./dist/system/vanilla/utils.production.js 3.15 kB
./dist/umd/babel/plugin-debug-label.development.js 1.08 kB
./dist/umd/babel/plugin-debug-label.production.js 852 B
./dist/umd/babel/plugin-react-refresh.development.js 1.27 kB
./dist/umd/babel/plugin-react-refresh.production.js 1 kB
./dist/umd/babel/preset.development.js 1.54 kB
./dist/umd/babel/preset.production.js 1.22 kB
./dist/umd/index.development.js 383 B
./dist/umd/index.production.js 328 B
./dist/umd/react.development.js 1.65 kB
./dist/umd/react.production.js 1.05 kB
./dist/umd/react/utils.development.js 1.54 kB
./dist/umd/react/utils.production.js 1.01 kB
./dist/umd/utils.development.js 399 B
./dist/umd/utils.production.js 342 B
./dist/umd/vanilla/utils.development.js 6.28 kB
./dist/umd/vanilla/utils.production.js 3.8 kB
./dist/utils.js 247 B
./dist/vanilla/utils.js 6.15 kB

compressed-size-action

Copy link

LiveCodes Preview in LiveCodes

Latest commit: 7c5bbc8
Last updated: Jul 23, 2025 3:38am (UTC)

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

See documentations for usage instructions.

@dai-shi
Copy link
Member Author

dai-shi commented Jul 23, 2025

image

Hmm, I'm not super happy with it.

if (import.meta.env?.MODE !== 'production' && !atom) {
throw new Error('Atom is undefined or null')
}
let atomState = atomStateMap.get(atom)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be the same issue. ensureAtomState closes over the storeState destructure which causes it to reuse those captured values. If we want swappable pieces, my guess is that we would have to destructure within ensureAtomState and other building block functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a good test would be to do,

const asm0 = { get: vi.fn(() => ({ d: new Set() })), has: () => true }
const buildingBlocks0 = asm0
const store0 = INTERNAL_buildStore(...buildingBlocks0)
const [...buildingBlocks1] = INTERNAL_getBuildingBlocks(store0)
const asm1 = { get: vi.fn(() => ({ d: new Set() })), has: () => true }
buildingBlocks1[0] = asm1
const store1 = INTERNAL_buildStore(...buildingBlocks1)
const a = atom(0)
store1.get(a)
expect(asm1.get).toBeCalled()
expect(asm0.get).not.toBeCalled()

Copy link
Member Author

Choose a reason for hiding this comment

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

With this rev2, my expectation is to call createBuildingBlocks again for the second store. You could argue that building blocks of the first store has changed, but we can't assure they don't use closure state anyways. We need some assumptions.

@dai-shi
Copy link
Member Author

dai-shi commented Aug 28, 2025

Closing in favor of #3105.

@dai-shi dai-shi closed this Aug 28, 2025
@dai-shi dai-shi deleted the internal/store-state-idea branch August 28, 2025 12:03
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.

2 participants