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

fix(vanilla, react): use experimental_use and some refactors #545

Merged
merged 21 commits into from
Oct 15, 2022

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Sep 10, 2022

Ref: facebook/react#25084

In addition:

  • Refactor with unified Symbol PROXY_STATE.
  • Precise SNAPSHOT type with Awaited.

@vercel
Copy link

vercel bot commented Sep 10, 2022

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

Name Status Preview Updated
valtio ✅ Ready (Inspect) Visit Preview Oct 15, 2022 at 0:49AM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 10, 2022

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 36a8f1a:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration

@github-actions
Copy link

github-actions bot commented Sep 10, 2022

Size Change: +1.42 kB (+3%)

Total Size: 51.5 kB

Filename Size Change
dist/esm/index.js 986 B +255 B (+35%) 🚨
dist/esm/vanilla.js 2.02 kB +25 B (+1%)
dist/index.js 1.13 kB +243 B (+28%) 🚨
dist/system/index.development.js 1.17 kB +278 B (+31%) 🚨
dist/system/index.production.js 526 B +14 B (+3%)
dist/system/vanilla.development.js 2.16 kB +48 B (+2%)
dist/system/vanilla.production.js 1.35 kB +50 B (+4%)
dist/umd/index.development.js 1.25 kB +242 B (+24%) 🚨
dist/umd/index.production.js 683 B +12 B (+2%)
dist/umd/vanilla.development.js 2.39 kB +91 B (+4%)
dist/umd/vanilla.production.js 1.49 kB +95 B (+7%) 🔍
dist/vanilla.js 2.27 kB +71 B (+3%)
ℹ️ View Unchanged
Filename Size
dist/esm/macro.js 617 B
dist/esm/macro/vite.js 732 B
dist/esm/utils.js 4.13 kB
dist/macro.js 910 B
dist/macro/vite.js 1.04 kB
dist/system/macro.development.js 725 B
dist/system/macro.production.js 555 B
dist/system/macro/vite.development.js 839 B
dist/system/macro/vite.production.js 660 B
dist/system/utils.development.js 4.35 kB
dist/system/utils.production.js 2.91 kB
dist/umd/macro.development.js 1.06 kB
dist/umd/macro.production.js 766 B
dist/umd/macro/vite.development.js 1.21 kB
dist/umd/macro/vite.production.js 893 B
dist/umd/utils.development.js 4.86 kB
dist/umd/utils.production.js 3.09 kB
dist/utils.js 4.71 kB

compressed-size-action

@dai-shi dai-shi marked this pull request as ready for review September 10, 2022 13:33
@dai-shi dai-shi marked this pull request as draft September 10, 2022 13:39
src/react.ts Outdated
Comment on lines 2 to 4
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
experimental_use,
Copy link

@SukkaW SukkaW Sep 24, 2022

Choose a reason for hiding this comment

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

DefinitelyTyped/DefinitelyTyped#62189

It seems that the typing of experimental_use is now added to the @types/react, and ts-ignore could be removed.

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, yeah, I updated there and there, but forgot here. Thanks.

@dai-shi
Copy link
Member Author

dai-shi commented Oct 15, 2022

According to reactjs/rfcs#229, the use of use here is violating the rule/convention of React.
From our perspective, this PR is not breaking.
When React finalizes the spec and release a stable version, we will consider following their pattern, and in that case, our library comes with breaking changes. i.e. snapshot will not resolve promises.
Meanwhile, let's merge this and release a patch version.

@dai-shi dai-shi changed the title feat: use experimental_use fix(vanilla, react): use experimental_use and some refactors Oct 15, 2022
@@ -14,6 +24,38 @@ import type { INTERNAL_Snapshot as Snapshot } from './vanilla'

const { useSyncExternalStore } = useSyncExternalStoreExports

// customized version of affectedToPathList
// we need to avoid invoking getters
Copy link
Contributor

Choose a reason for hiding this comment

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

@dai-shi ahhh, okay, this change (skipping getters in the output of affectedToPathList) is why I've been confused.

I've been watching the output of useAffectedDebugValue (maybe a little too religiously in retrospect) and was very confused by the lack of getters.

This made me think "valtio is not working" / "doesn't know my getters were invoked", when obviously I could tell it did, b/c the re-renders still worked correctly.

I finally reproduced the behavior in proxy-compare and "get it"--getters (and method invocations) are always in the affected map, and are always handled correctly by isChanged, it is merely affectedToPathList that is leaving them off.

What was the rationale here? I'm sure it makes sense, just curious b/c it tripped me up. Wondering if I can work the rationale/behavior in a doc/"gotchas" update.

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Without it, it loops infinitely and hangs, AFAIR.

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