Skip to content

breaking(internals): avoid getInternalBuildingBlock function#3293

Merged
dai-shi merged 27 commits intomainfrom
breaking/building-blocks-in-params
May 5, 2026
Merged

breaking(internals): avoid getInternalBuildingBlock function#3293
dai-shi merged 27 commits intomainfrom
breaking/building-blocks-in-params

Conversation

@dai-shi
Copy link
Copy Markdown
Member

@dai-shi dai-shi commented Apr 1, 2026

alternative to #3280. Though, it became pretty similar.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 1, 2026

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

Project Deployment Actions Updated (UTC)
jotai Ready Ready Preview, Comment Apr 21, 2026 8:51am

Request Review

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Apr 1, 2026

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 1, 2026

More templates

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

commit: ac38969

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

Size Change: -92 B (-0.09%)

Total Size: 104 kB

Filename Size Change
./dist/esm/react.mjs 1.85 kB +5 B (+0.27%)
./dist/esm/vanilla.mjs 667 B +1 B (+0.15%)
./dist/esm/vanilla/internals.mjs 4.63 kB +28 B (+0.61%)
./dist/react.js 1.81 kB +7 B (+0.39%)
./dist/system/react.development.js 2.04 kB +6 B (+0.29%)
./dist/system/react.production.js 1.25 kB +6 B (+0.48%)
./dist/system/vanilla.development.js 737 B +1 B (+0.14%)
./dist/system/vanilla/internals.development.js 4.74 kB +35 B (+0.74%)
./dist/system/vanilla/internals.production.js 2.85 kB -47 B (-1.62%)
./dist/umd/react.development.js 1.95 kB +6 B (+0.31%)
./dist/umd/react.production.js 1.34 kB +3 B (+0.22%)
./dist/umd/vanilla.development.js 794 B +1 B (+0.13%)
./dist/umd/vanilla.production.js 403 B +1 B (+0.25%)
./dist/umd/vanilla/internals.development.js 6.01 kB -37 B (-0.61%)
./dist/umd/vanilla/internals.production.js 3.69 kB -74 B (-1.97%)
./dist/vanilla/internals.js 5.85 kB -34 B (-0.58%)
ℹ️ View Unchanged
Filename Size
./dist/babel/plugin-debug-label.js 1.06 kB
./dist/babel/plugin-react-refresh.js 1.26 kB
./dist/babel/preset.js 1.55 kB
./dist/esm/babel/plugin-debug-label.mjs 1.12 kB
./dist/esm/babel/plugin-react-refresh.mjs 1.31 kB
./dist/esm/babel/preset.mjs 1.62 kB
./dist/esm/index.mjs 62 B
./dist/esm/react/utils.mjs 746 B
./dist/esm/utils.mjs 67 B
./dist/esm/vanilla/utils.mjs 5.18 kB
./dist/index.js 242 B
./dist/react/utils.js 1.4 kB
./dist/system/babel/plugin-debug-label.development.js 1.22 kB
./dist/system/babel/plugin-debug-label.production.js 900 B
./dist/system/babel/plugin-react-refresh.development.js 1.41 kB
./dist/system/babel/plugin-react-refresh.production.js 1.05 kB
./dist/system/babel/preset.development.js 1.72 kB
./dist/system/babel/preset.production.js 1.29 kB
./dist/system/index.development.js 252 B
./dist/system/index.production.js 185 B
./dist/system/react/utils.development.js 859 B
./dist/system/react/utils.production.js 465 B
./dist/system/utils.development.js 257 B
./dist/system/utils.production.js 190 B
./dist/system/vanilla.production.js 349 B
./dist/system/vanilla/utils.development.js 5.38 kB
./dist/system/vanilla/utils.production.js 3.11 kB
./dist/umd/babel/plugin-debug-label.development.js 1.2 kB
./dist/umd/babel/plugin-debug-label.production.js 973 B
./dist/umd/babel/plugin-react-refresh.development.js 1.4 kB
./dist/umd/babel/plugin-react-refresh.production.js 1.12 kB
./dist/umd/babel/preset.development.js 1.69 kB
./dist/umd/babel/preset.production.js 1.36 kB
./dist/umd/index.development.js 383 B
./dist/umd/index.production.js 327 B
./dist/umd/react/utils.development.js 1.54 kB
./dist/umd/react/utils.production.js 1.02 kB
./dist/umd/utils.development.js 395 B
./dist/umd/utils.production.js 340 B
./dist/umd/vanilla/utils.development.js 6.42 kB
./dist/umd/vanilla/utils.production.js 3.75 kB
./dist/utils.js 243 B
./dist/vanilla.js 685 B
./dist/vanilla/utils.js 6.3 kB

compressed-size-action

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

LiveCodes Preview in LiveCodes

Latest commit: ac38969
Last updated: Apr 23, 2026 12:37am (UTC)

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

See documentations for usage instructions.

@dmaskasky
Copy link
Copy Markdown
Collaborator

dmaskasky commented Apr 1, 2026

My initial thought is that rest/spread adds overhead to these internal functions.
Many of the functions only require passing store since atomOnInit needs it. But this pollutes the api quite a bit. I'm inclined to shove store into buildingBlocks. Semantically, buildingBlocks are not buildingBlocks for the store, they are the buildingBlocks used by the store internals.
The BB prefix is nice. I find code width a bigger problem now that I also have a chat side panel open. We can also use bb instead of buildingBlocks for the identifier.

@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented Apr 2, 2026

This gets closer to #3280. One of meaningful changes is that I dislike putting store in buildingBlocks.

Comment thread src/vanilla/internals.ts
Comment thread src/vanilla/internals.ts Outdated
// store api
store,
] satisfies BuildingBlocks
).map((fn, i) => buildArgs[i] || fn) as BuildingBlocks
Copy link
Copy Markdown
Collaborator

@dmaskasky dmaskasky Apr 3, 2026

Choose a reason for hiding this comment

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

Passing store in buildArgs is technically possible, but should not affect anything.

This is a common pattern. The intent is not to overwrite the store (since that is what we are building).

const buildingBlocks = getBuildingBlocks(store)
buildingBlocks[0] = new AtomState()
const store2 = buildStore(...buildingBlocks)

I recommend putting buildingBlocks[29] = store after this line to overwrite buildArgs[29].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't like it then. If we specialize store like that, I wouldn't put it into the building blocks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Then let's void it from the buildArgs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I mean I don't like adding store in buildingBlocks.

Comment thread src/vanilla/internals.ts Outdated
}
try {
return atomWrite(store, atom, getter, setter, ...args)
return atomWrite(buildingBlocks, atom, getter, setter, ...args)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or should we also make atomWrite non-variadic?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't see any use cases, but feels consistent for all atom interceptors.

@dai-shi dai-shi added this to the v2.20.0 milestone Apr 21, 2026
@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented Apr 21, 2026

@arjunvegda @dmaskasky
For v2.20.0, I would like to introduce this breaking change. Please prepare for the change. Ideally, I would like to merge this after all "PASS".

Comment thread src/vanilla/internals.ts
Comment thread src/vanilla/internals.ts
) => Readonly<BuildingBlocks>
type AbortHandlersMap = WeakMapLike<PromiseLike<unknown>, Set<() => void>>
type RegisterAbortHandler = <T>(
store: Store,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we should still pass the store as the second param.

Comment thread src/vanilla/internals.ts
@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented Apr 21, 2026

I'll work on them.

@dmaskasky
Copy link
Copy Markdown
Collaborator

@arjunvegda @dmaskasky

For v2.20.0, I would like to introduce this breaking change. Please prepare for the change. Ideally, I would like to merge this after all "PASS".

Ok, and we should remember to set the minimum version of Jotai peer dep to this version.

@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented Apr 22, 2026

@dmaskasky reported this breaking change makes jotai-scope unmaintainable. Let's start over when we get time.

@arjunvegda sorry about the confusion. sorry about the double confusion. I'll wait for your reply.

@dai-shi dai-shi closed this Apr 22, 2026
@dai-shi dai-shi removed this from the v2.20.0 milestone Apr 22, 2026
@dai-shi dai-shi deleted the breaking/building-blocks-in-params branch April 22, 2026 23:56
@dmaskasky
Copy link
Copy Markdown
Collaborator

@dmaskasky reported this breaking change makes jotai-scope unmaintainable. Let's start over when we get time.

@arjunvegda sorry about the confusion.

I was able to reach a solution for jotai-scope and jotai-effect.

@dai-shi dai-shi restored the breaking/building-blocks-in-params branch April 23, 2026 00:36
@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented Apr 23, 2026

wow, that's great to hear.

@dai-shi
Copy link
Copy Markdown
Member Author

dai-shi commented May 5, 2026

/ecosystem-ci run

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Ecosystem CI Output

---- Jotai Ecosystem CI Results ----
{
  "bunshi": "PASS",
  "jotai-devtools": "PASS",
  "jotai-effect": "PASS",
  "jotai-family": "PASS",
  "jotai-scope": "PASS",
  "waku-jotai": "PASS"
}

https://github.com/pmndrs/jotai/actions/runs/25407046676

@dai-shi dai-shi merged commit 4b63111 into main May 5, 2026
52 checks passed
@dai-shi dai-shi deleted the breaking/building-blocks-in-params branch May 5, 2026 23:09
@dai-shi dai-shi restored the breaking/building-blocks-in-params branch May 5, 2026 23:10
@dai-shi dai-shi deleted the breaking/building-blocks-in-params branch May 5, 2026 23:13
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