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

[Fresh] Make all errors recoverable #17438

Merged
merged 5 commits into from
Nov 25, 2019
Merged

[Fresh] Make all errors recoverable #17438

merged 5 commits into from
Nov 25, 2019

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Nov 23, 2019

The logic for recovering from errors was a bit shaky because we tried to guess what was last scheduled from the commit event. That was insufficient because:

  1. Failure before the initial mount doesn't make commits at all
  2. We can't easily distinguish a user-initiated unmount from a commit that happened for some other reason

The first is a current limitation of Fast Refresh which is annoying. The second leads to some edge cases where it can't reliably recover even on updates.

I'm changing the strategy to introduce a first-class DevTools hook that fires when a root gets scheduled an element. We track these in Fresh runtime in a WeakMap (if not available, retrying is off completely). This lets us recover from both initial and update errors, and also tell reliably what was the last scheduled element.

Because this DevTools hook is new, I had to add some checks. I also cleaned up an old instrumentation file that existed for a similar purpose but is unused. Also added a re-entrancy check to the Fresh runtime. Should be unnecessary but I'm starting to rely on it not being re-entrant.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 23, 2019

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 67b6791:

Sandbox Source
modest-https-p95s0 Configuration

@sizebot
Copy link

sizebot commented Nov 23, 2019

Details of bundled changes.

Comparing: 54f6673...67b6791

react-refresh

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-refresh-babel.development.js 0.0% -0.0% 24.07 KB 24.07 KB 5.5 KB 5.5 KB NODE_DEV
react-refresh-babel.production.min.js 0.0% -0.0% 7.2 KB 7.2 KB 2.58 KB 2.58 KB NODE_PROD
ReactFreshRuntime-dev.js +2.2% -0.2% 17.61 KB 18 KB 5.38 KB 5.37 KB FB_WWW_DEV
react-refresh-runtime.development.js +2.1% -0.3% 17.59 KB 17.96 KB 5.41 KB 5.39 KB NODE_DEV

Size changes (experimental)

Generated by 🚫 dangerJS against 67b6791

@sizebot
Copy link

sizebot commented Nov 23, 2019

Details of bundled changes.

Comparing: 54f6673...67b6791

react-refresh

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-refresh-babel.production.min.js 0.0% -0.0% 7.19 KB 7.19 KB 2.58 KB 2.57 KB NODE_PROD
react-refresh-runtime.development.js +2.1% -0.3% 17.58 KB 17.95 KB 5.4 KB 5.38 KB NODE_DEV
react-refresh-runtime.production.min.js 0.0% -0.4% 368 B 368 B 266 B 265 B NODE_PROD
react-refresh-babel.development.js 0.0% -0.0% 24.06 KB 24.06 KB 5.5 KB 5.5 KB NODE_DEV

Size changes (stable)

Generated by 🚫 dangerJS against 67b6791

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

source

@gaearon gaearon merged commit 6470e0f into facebook:master Nov 25, 2019
hasLoggedError = true;
warningWithoutStack(
false,
'React DevTools encountered an error: %s',
Copy link
Contributor

@bvaughn bvaughn Nov 26, 2019

Choose a reason for hiding this comment

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

This warning is a bit misleading, and might result in people filing bugs against DevTools that should mention Fresh instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It’s just copy paste from other “DevTools hooks”. We can change the message in all of them? I don’t think this one is particularly special other than the fact that it happens to be used by Fresh today.

Technically there’s nothing preventing DevTools from using this one too — in fact I think it might help us remove some fragile logic in the renderer. (For new versions at least.) In that case we’d need to remove the DEV-only flag check though.

In either case the issue would be filed in the same repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In other words, we could apply the same argument to the “commit root” hook which has the same message but is used by both DevTools and Fresh.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it was copy pasted from the previous one, but in this particular case it's always incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand so much pushback against a wording suggestion 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it matters but I'm happy to stamp a PR that changes it :-) I don't mean to "push back", I was only explaining my reasoning for why I left it as is. I'm sorry if that explanation isn't useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's cool. Thanks for the follow up PR.

trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* [Fresh] Detect root updates more reliably

* [Fresh] Use WeakMap for root elements

* [Fresh] Make initial failures recoverable too

* Fix DevTools check

* Fix wrong flow type
trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* [Fresh] Detect root updates more reliably

* [Fresh] Use WeakMap for root elements

* [Fresh] Make initial failures recoverable too

* Fix DevTools check

* Fix wrong flow type
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jul 5, 2024
Summary:
The `hasUnrecoverableErrors` function has been [hardcoded](https://github.com/facebook/react/blob/f38c22b244086f62ae5ed851b6ed17029ec44be5/packages/react-refresh/src/ReactFreshRuntime.js#L602) to always return false for the past 5 years, since React Refresh [can recover from all errors](facebook/react#17438). This hardcoding was introduced in react-refresh v0.7.1, and RN currently uses v0.14.2.

## Changelog:

[INTERNAL] [REMOVED] - Remove unreachable if-condition in refresh logic

Pull Request resolved: #45296

Test Plan: Fast Refresh should still work as expected.

Reviewed By: NickGerleman

Differential Revision: D59405648

Pulled By: arushikesarwani94

fbshipit-source-id: 6fefedb484eeab032028d738b48ac936a9044cb0
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