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

Tidy up React Scope API #19352

Merged
merged 2 commits into from Jul 16, 2020
Merged

Tidy up React Scope API #19352

merged 2 commits into from Jul 16, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Jul 14, 2020

This PR changes the React Scopes (experimental) API, so it's simpler. Previously, you used Scopes like this:

const MyScope = React.unstable_createScope()

function MyComponent() {
  return <MyScope>...</MyScope>
}

With this PR:

const Scope = React.unstable_Scope;

function MyComponent() {
  return <Scope>...</Scope>
}

So they work like Fragment or other common React exports, and can be used directly as the element type.

The reason we have unstable_createScope was because in the older design of the Scopes API, createScope used to take an argument. That specific feature was removed ages ago, so it actually makes no sense to have to do createScope each time.

@trueadm trueadm requested a review from gaearon July 14, 2020 15:06
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jul 14, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 14, 2020

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 86fd780:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Jul 14, 2020

Details of bundled changes.

Comparing: 147179a...86fd780

react-is

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-is.development.js +1.7% +4.9% 7.94 KB 8.08 KB 1.98 KB 2.08 KB UMD_DEV
react-is.production.min.js -1.8% -1.5% 2.39 KB 2.34 KB 996 B 981 B UMD_PROD
react-is.development.js +1.8% +4.8% 7.37 KB 7.5 KB 1.9 KB 1.99 KB NODE_DEV
react-is.production.min.js -1.8% -1.5% 2.39 KB 2.35 KB 961 B 947 B NODE_PROD
ReactIs-dev.js +16.6% +20.5% 7.5 KB 8.75 KB 1.91 KB 2.3 KB FB_WWW_DEV
ReactIs-prod.js 🔺+0.3% 🔺+1.6% 5.56 KB 5.58 KB 1.35 KB 1.37 KB FB_WWW_PROD

Size changes (experimental)

Generated by 🚫 dangerJS against 86fd780

@sizebot
Copy link

sizebot commented Jul 14, 2020

Details of bundled changes.

Comparing: 147179a...86fd780

react-is

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-is.development.js +1.7% +5.0% 7.93 KB 8.06 KB 1.97 KB 2.07 KB UMD_DEV
react-is.production.min.js -1.8% -1.4% 2.37 KB 2.33 KB 987 B 973 B UMD_PROD
react-is.development.js +1.8% +5.1% 7.35 KB 7.49 KB 1.89 KB 1.99 KB NODE_DEV
react-is.production.min.js -1.8% -1.5% 2.38 KB 2.34 KB 951 B 937 B NODE_PROD
ReactIs-dev.js +16.6% +20.6% 7.5 KB 8.75 KB 1.91 KB 2.31 KB FB_WWW_DEV
ReactIs-prod.js 🔺+0.3% 🔺+1.6% 5.56 KB 5.58 KB 1.35 KB 1.37 KB FB_WWW_PROD

Size changes (stable)

Generated by 🚫 dangerJS against 86fd780

@gaearon
Copy link
Collaborator

gaearon commented Jul 16, 2020

I'm not quite following. Wasn't the idea that you declare separate Scope per piece of functionality, similar to Context? How can you be sure of the type of the exposed scope's refs after this change? Presumably any traversal will now "see" unrelated Scopes, unless I'm missing something.

@trueadm
Copy link
Contributor Author

trueadm commented Jul 16, 2020

@gaearon

Wasn't the idea that you declare separate Scope per piece of functionality, similar to Context? How can you be sure of the type of the exposed scope's refs after this change? Presumably any traversal will now "see" unrelated Scopes, unless I'm missing something.

That's how scopes used to work. They changed a while ago and lost their traversal methods entirely, instead opting to use React Context to traverse up and a method to find child React Context in a sub-tree. This was one of the stems of work we had last year when Sebastian was in London, around making Scopes API "safter" and less super-powered.

packages/react-reconciler/src/ReactFiber.new.js Outdated Show resolved Hide resolved
packages/react-reconciler/src/ReactFiber.old.js Outdated Show resolved Hide resolved
@trueadm trueadm merged commit 9102719 into facebook:master Jul 16, 2020
@trueadm trueadm deleted the refine-scope branch July 16, 2020 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants