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

[ReactDebugTools] add custom error type for future new hooks #24168

Merged
merged 3 commits into from
Mar 30, 2022

Conversation

mondaychen
Copy link
Contributor

@mondaychen mondaychen commented Mar 25, 2022

Summary

  • In ReactDebugTools, we maintain a list of react's built-in hooks in Dispatcher. If react adds more built-in hooks in future releases, and user hasn't upgraded the tool (e.g. devtool extension), this function will throw and might be confusing to users.
  • This PR adds a custom error UnsupportedFeatureError in ReactDebugTools. It also exports the name of the error as a string so devtool can show a more friendly message to let users know the issue can be resolved by upgrading.

Next

This is to unblock mondaychen#1 and mondaychen#2 so that we can resolve #24096

How did you test this change?

I tested it by temporarily removing useEffect hook and test in an application that calls it
Screen Shot 2022-03-25 at 12 34 06 PM

After adding a custom view we can explicitly ask user to upgrade: mondaychen#2

@sizebot
Copy link

sizebot commented Mar 25, 2022

Comparing: e7d0053...ed70bfa

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 131.32 kB 131.32 kB = 41.96 kB 41.96 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 136.38 kB 136.38 kB = 43.42 kB 43.42 kB
facebook-www/ReactDOM-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB
facebook-www/ReactDOM-prod.modern.js = 417.73 kB 417.73 kB = 77.21 kB 77.22 kB
facebook-www/ReactDOMForked-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.development.js +2.89% 20.99 kB 21.60 kB +4.31% 5.46 kB 5.69 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.production.min.js +2.48% 6.38 kB 6.54 kB +3.82% 2.33 kB 2.42 kB

Generated by 🚫 dangerJS against ed70bfa

@mondaychen mondaychen force-pushed the custom_error_debug_tools_1 branch from 626cf89 to a11680b Compare March 28, 2022 15:57
@mondaychen mondaychen force-pushed the custom_error_debug_tools_1 branch from a11680b to 60cb32b Compare March 28, 2022 16:10
@mondaychen mondaychen changed the title [WIP][ReactDebugTools] add custom error type for future new hooks [ReactDebugTools] add custom error type for future new hooks Mar 29, 2022
@mondaychen mondaychen requested a review from lunaruan March 29, 2022 15:18
@mondaychen mondaychen marked this pull request as ready for review March 29, 2022 15:20
@mondaychen mondaychen requested a review from bvaughn March 29, 2022 15:49
Copy link
Contributor

@lunaruan lunaruan left a comment

Choose a reason for hiding this comment

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

Looks good with a small nit!

packages/react-debug-tools/src/ReactDebugHooks.js Outdated Show resolved Hide resolved
@mondaychen mondaychen merged commit 0415b18 into facebook:main Mar 30, 2022
const error = new Error('Missing method in Dispatcher: ' + prop);
// Note: This error name needs to stay in sync with react-devtools-shared
// TODO: refactor this if we ever combine the devtools and debug tools packages
error.name = 'UnsupportedFeatureError';
Copy link
Contributor

@lunaruan lunaruan Mar 30, 2022

Choose a reason for hiding this comment

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

Sorry, I missed this! Could you make this error name something more package specific (ex. 'ReactDebugTools') to minimize name clashes?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about ReactDebugToolsError (for more consistency with built in error names)

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 12, 2022
Summary:
This sync includes the following changes:
- **[e8f4a6653](facebook/react@e8f4a6653 )**: Fix import in example //<dan>//
- **[bb49abea2](facebook/react@bb49abea2 )**: Update some READMEs ([#24290](facebook/react#24290)) //<dan>//
- **[4bc465a16](facebook/react@4bc465a16 )**: Rename Controls to PipeableStream ([#24286](facebook/react#24286)) //<Sebastian Markbåge>//
- **[ece5295e5](facebook/react@ece5295e5 )**: Remove unnecessary flag check ([#24284](facebook/react#24284)) //<zhoulixiang>//
- **[9ededef94](facebook/react@9ededef94 )**: Don't mute hydration errors forcing client render ([#24276](facebook/react#24276)) //<dan>//
- **[985272e26](facebook/react@985272e26 )**: Fix name mismatch in react-reconciler custom build. ([#24272](facebook/react#24272)) //<Hikari Hayashi>//
- **[b8cfda15e](facebook/react@b8cfda15e )**: changed Transitions type to Array<Transition> ([#24249](facebook/react#24249)) //<Luna Ruan>//
- **[c89a15c71](facebook/react@c89a15c71 )**: [ReactDebugTools] wrap uncaught error from rendering user's component ([#24216](facebook/react#24216)) //<Mengdi "Monday" Chen>//
- **[ebd7ff65b](facebook/react@ebd7ff65b )**: Don't recreate the same fallback on the client if hydrating suspends ([#24236](facebook/react#24236)) //<dan>//
- **[aa05e7315](facebook/react@aa05e7315 )**: Add 4.4.0 release to eslint rules CHANGELOG ([#24234](facebook/react#24234)) //<Brian Vaughn>//
- **[7e3121e1c](facebook/react@7e3121e1c )**: Remove unstable_createMutableSource from experimental build ([#24209](facebook/react#24209)) //<Sebastian Silbermann>//
- **[0415b18a1](facebook/react@0415b18a1 )**: [ReactDebugTools] add custom error type for future new hooks ([#24168](facebook/react#24168)) //<Mengdi "Monday" Chen>//

Changelog:
[General][Changed] - React Native sync for revisions 34aa5cf...e8f4a66

jest_e2e[run_all_tests]

Reviewed By: kacieb

Differential Revision: D35581059

fbshipit-source-id: ee031dfc49b1ef663b601f33f3f3f6c5a804971e
rickhanlonii pushed a commit that referenced this pull request Apr 13, 2022
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
rickhanlonii pushed a commit that referenced this pull request Apr 14, 2022
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
rickhanlonii pushed a commit that referenced this pull request Apr 14, 2022
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
rickhanlonii pushed a commit that referenced this pull request Apr 14, 2022
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
rickhanlonii pushed a commit that referenced this pull request Apr 14, 2022
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
…k#24168)

* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2023
Summary:
This sync includes the following changes:
- **[e8f4a6653](facebook/react@e8f4a6653 )**: Fix import in example //<dan>//
- **[bb49abea2](facebook/react@bb49abea2 )**: Update some READMEs ([facebook#24290](facebook/react#24290)) //<dan>//
- **[4bc465a16](facebook/react@4bc465a16 )**: Rename Controls to PipeableStream ([facebook#24286](facebook/react#24286)) //<Sebastian Markbåge>//
- **[ece5295e5](facebook/react@ece5295e5 )**: Remove unnecessary flag check ([facebook#24284](facebook/react#24284)) //<zhoulixiang>//
- **[9ededef94](facebook/react@9ededef94 )**: Don't mute hydration errors forcing client render ([facebook#24276](facebook/react#24276)) //<dan>//
- **[985272e26](facebook/react@985272e26 )**: Fix name mismatch in react-reconciler custom build. ([facebook#24272](facebook/react#24272)) //<Hikari Hayashi>//
- **[b8cfda15e](facebook/react@b8cfda15e )**: changed Transitions type to Array<Transition> ([facebook#24249](facebook/react#24249)) //<Luna Ruan>//
- **[c89a15c71](facebook/react@c89a15c71 )**: [ReactDebugTools] wrap uncaught error from rendering user's component ([facebook#24216](facebook/react#24216)) //<Mengdi "Monday" Chen>//
- **[ebd7ff65b](facebook/react@ebd7ff65b )**: Don't recreate the same fallback on the client if hydrating suspends ([facebook#24236](facebook/react#24236)) //<dan>//
- **[aa05e7315](facebook/react@aa05e7315 )**: Add 4.4.0 release to eslint rules CHANGELOG ([facebook#24234](facebook/react#24234)) //<Brian Vaughn>//
- **[7e3121e1c](facebook/react@7e3121e1c )**: Remove unstable_createMutableSource from experimental build ([facebook#24209](facebook/react#24209)) //<Sebastian Silbermann>//
- **[0415b18a1](facebook/react@0415b18a1 )**: [ReactDebugTools] add custom error type for future new hooks ([facebook#24168](facebook/react#24168)) //<Mengdi "Monday" Chen>//

Changelog:
[General][Changed] - React Native sync for revisions 34aa5cf...e8f4a66

jest_e2e[run_all_tests]

Reviewed By: kacieb

Differential Revision: D35581059

fbshipit-source-id: ee031dfc49b1ef663b601f33f3f3f6c5a804971e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants