Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use-sync-external-store #550

Merged
merged 66 commits into from
Apr 7, 2022
Merged

feat: use-sync-external-store #550

merged 66 commits into from
Apr 7, 2022

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Aug 31, 2021

No public API changes

The API is compatible with the latest v3 API

Major changes

Better support for context usage

  • It exports a new useStore hook.
  • It re-exports createStore from zustand/vanilla
  • zustand/context is fully rewritten with the new useStore.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 31, 2021

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.

Latest deployment of this branch, based on commit 1be05d1:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration
Next.js Configuration

@dai-shi dai-shi changed the title imaginary code that uses uSES use-sync-external-store Sep 4, 2021
@dai-shi
Copy link
Member Author

dai-shi commented Sep 4, 2021

Four tests failed:

  • re-renders with useLayoutEffect
  • can update the equality checker
  • can throw an error in selector
  • can throw an error in equality checker

I feel like we should hit v4 major with breaking changes.

@dai-shi
Copy link
Member Author

dai-shi commented Sep 4, 2021

I hacked around, but not sure if this causes a problem with cases where we used to have zombie children.

@dai-shi
Copy link
Member Author

dai-shi commented Sep 4, 2021

@@ -150,7 +150,9 @@ it('re-renders with useLayoutEffect', async () => {

const container = document.createElement('div')
ReactDOM.render(<Component />, container)
expect(container.innerHTML).toBe('true')
waitFor(() => {

Choose a reason for hiding this comment

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

I believe you need an await in front?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, nice catch. I hope it works with await.

@github-actions
Copy link

github-actions bot commented Sep 28, 2021

Size Change: -2.58 kB (-8%) ✅

Total Size: 30 kB

Filename Size Change
dist/context.js 518 B -104 B (-17%) 👏
dist/esm/context.js 448 B -73 B (-14%) 👏
dist/esm/index.js 558 B -417 B (-43%) 🎉
dist/index.js 661 B -414 B (-39%) 🎉
dist/system/context.development.js 572 B -67 B (-10%) 👏
dist/system/context.production.js 393 B -63 B (-14%) 👏
dist/system/index.development.js 666 B -432 B (-39%) 🎉
dist/system/index.production.js 430 B -236 B (-35%) 🎉
dist/umd/context.development.js 662 B -101 B (-13%) 👏
dist/umd/context.production.js 488 B -71 B (-13%) 👏
dist/umd/index.development.js 802 B -410 B (-34%) 🎉
dist/umd/index.production.js 538 B -191 B (-26%) 🎉
ℹ️ View Unchanged
Filename Size
dist/esm/middleware.js 3.41 kB
dist/esm/shallow.js 272 B
dist/esm/vanilla.js 353 B
dist/middleware.js 3.5 kB
dist/shallow.js 318 B
dist/system/middleware.development.js 3.52 kB
dist/system/middleware.production.js 2.46 kB
dist/system/shallow.development.js 338 B
dist/system/shallow.production.js 253 B
dist/system/vanilla.development.js 421 B
dist/system/vanilla.production.js 263 B
dist/umd/middleware.development.js 3.61 kB
dist/umd/middleware.production.js 2.46 kB
dist/umd/shallow.development.js 447 B
dist/umd/shallow.production.js 344 B
dist/umd/vanilla.development.js 562 B
dist/umd/vanilla.production.js 364 B
dist/vanilla.js 424 B

compressed-size-action

@dai-shi dai-shi changed the title use-sync-external-store feat: use-sync-external-store Apr 2, 2022
@dai-shi dai-shi marked this pull request as ready for review April 2, 2022 09:36
@dai-shi dai-shi merged commit a34649d into main Apr 7, 2022
@dai-shi dai-shi deleted the use-sync-external-store branch April 7, 2022 14:53
@phaistonian
Copy link

@dai-shi I noticed that you removed the Memoizing selectors section from readme.

Is not needed anymore?

@dai-shi
Copy link
Member Author

dai-shi commented May 26, 2022

@phaistonian Yes. Please see #971.

@phaistonian
Copy link

@dai-shi Awesome!

Any chance this change is the culprit for this?

@dai-shi
Copy link
Member Author

dai-shi commented May 26, 2022

Any chance this change is the culprit for this?

No, I don't think so.

dai-shi pushed a commit that referenced this pull request Mar 22, 2023
As per the discussions below, memoizing selectors does not improve performance
significantly as of v4. Thus we should avoid recommending selector memoization.
Note that the same paragraph was removed from the README in PR #550
(#550)
and this section may have been left behind as an oversight.

- #658
- #971
Mercury21th000 pushed a commit to Mercury21th000/zustand that referenced this pull request Nov 17, 2024
As per the discussions below, memoizing selectors does not improve performance
significantly as of v4. Thus we should avoid recommending selector memoization.
Note that the same paragraph was removed from the README in PR #550
(pmndrs/zustand#550)
and this section may have been left behind as an oversight.

- pmndrs/zustand#658
- pmndrs/zustand#971
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