Skip to content

Conversation

@dmaskasky
Copy link
Member

Summary

If a previous createStore has already overridden createStore, we should try our best to compose with it.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 22, 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.

Comment on lines 165 to 180
const prevStore = prevCreateStore?.();
const buildingBlocks = (
prevStore ? INTERNAL_getBuildingBlocksRev1(prevStore) : []
) as BuildingBlocks;
buildingBlocks[0] ??= new WeakMap();
buildingBlocks[1] ??= new WeakMap();
buildingBlocks[6] ??= {};
const storeHooks = INTERNAL_initializeStoreHooks(buildingBlocks[6]);
const atomWrite = buildingBlocks[8];
buildingBlocks[8] = (atom, get, set, ...args) => {
if (inRestoreAtom) {
return set(atom, ...args);
}
return atomWrite
? atomWrite(atom, get, set, ...args)
: atom.write(get, set, ...args);
};
const store = INTERNAL_buildStore(...buildingBlocks);
const [atomStateMap, mountedAtoms] = buildingBlocks;
Copy link
Member Author

Choose a reason for hiding this comment

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

@dai-shi
I think we need more thought around how to derive a store from a previous store. Currently, overriding certain building blocks won't work as expected.

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.

Again, thanks for working on this.

@dmaskasky dmaskasky force-pushed the dmaskasky-compose-with-prevstore branch 2 times, most recently from 26b1d10 to 5c27901 Compare July 23, 2025 08:23
@dmaskasky dmaskasky force-pushed the dmaskasky-compose-with-prevstore branch from 5c27901 to 2c586d0 Compare July 23, 2025 09:07
@dmaskasky dmaskasky requested a review from dai-shi July 23, 2025 09:10
const prevStore = prevCreateStore?.() ?? INTERNAL_buildStore();
const buildingBlocks = [
...INTERNAL_getBuildingBlocksRev1(prevStore),
] as BuildingBlocks;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it already mutable without the type annotation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think buildingBlocks should be frozen.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should be frozen. I'm only talking about the typing. Doesn't this work?

  const buildingBlocks = [
    ...INTERNAL_getBuildingBlocksRev1(prevStore),
  ];

@sebinsua
Copy link

Since updating jotai-devtools and jotai in my project, the devtools shows no atoms at all.

Do you know if this fixes that issue? It might somehow relate to my project using a custom store or it could be something else. I've not been able to work out what's happening yet.

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