Commit Graph

235 Commits

Author SHA1 Message Date
Brian Vaughn
b8bbb6a13d Fix edge-case Fast Refresh bug that caused Fibers with warnings/errors to be untracked prematurely (#21536)
Refactor error/warning count tracking to avoid pre-allocating an ID for Fibers that aren't yet mounted. Instead, we store a temporary reference to the Fiber itself and later check to see if it successfully mounted before merging pending error/warning counts.

This avoids a problematic edge case where a force-remounted Fiber (from Fast Refresh) caused us to untrack a Fiber that was still mounted, resulting in a DevTools error if that Fiber was inspected in the Components tab.
2021-05-20 11:24:08 -04:00
Brian Vaughn
ebcec3cc20 Add key to inspected-element error boundary (#21535)
This way changing the selected element also recreates/resets the boundary automatically.
2021-05-19 17:38:12 -04:00
Brian Vaughn
99995c1063 Improve error boundary in inspected elements panel (#21531)
Show more info about the error as well as the option to report it to GitHub.
2021-05-19 13:27:56 -04:00
Brian Vaughn
d6604ac031 Account for another DevTools + Fast Refresh edge case (#21523)
DevTools now 'untrack' Fibers (cleans up the ID-to-Fiber mapping) after a slight delay in order to support a Fast Refresh edge case:
1. Component type is updated and Fast Refresh schedules an update+remount.
2. flushPendingErrorsAndWarningsAfterDelay() runs, sees the old Fiber is no longer mounted (it's been disconnected by Fast Refresh), and calls untrackFiberID() to clear it from the Map.
3. React flushes pending passive effects before it runs the next render, which logs an error or warning, which causes a new ID to be generated for this Fiber.
4. DevTools now tries to unmount the old Component with the new ID.

The underlying problem here is the premature clearing of the Fiber ID, but DevTools has no way to detect that a given Fiber has been scheduled for Fast Refresh. (The '_debugNeedsRemount' flag won't necessarily be set.)

The best we can do is to delay untracking by a small amount, and give React time to process the Fast Refresh delay.
2021-05-18 22:44:29 -04:00
Brian Vaughn
b15bf2b2f1 DevTools bugfix for useState() with hasOwnProperty key (#21524) 2021-05-18 16:43:33 -04:00
Brian Vaughn
63927e0843 Fixed another Symbol concatenation issue with DevTools format() util (#21521) 2021-05-18 11:46:04 -04:00
Brian Vaughn
1e3383a411 DevTools: Reload all roots after Fast Refresh force remount (#21516)
Works around the corrupted Store state by detecting a broken Fast Refresh remount and forcefully dropping the root and re-mounting the entire tree. This prevents Fibers from getting duplicated in the Store (and in the Components tree). The benefit of this approach is that it doesn't rely on an update or change in behavior to Fast Refresh. (This workaround is pretty dirty, but since it's a DEV-only code path, it's probably okay.)

Note that this change doesn't fix all of the reported issues (see #21442 (comment)) but it does fix some of them.

This commit also slightly refactors the way DevTools assigns and manages unique IDs for Fibers in the backend by removing the indirection of a "primary Fiber" and instead mapping both the primary and alternate.

It also removes the previous cache-on-read behavior of getFiberID and splits the method into three separate functions for different use cases:
* getOrGenerateFiberID – Like the previous function, this method returns an ID or generates and caches a new one if the Fiber hasn't been seen before.
* getFiberIDUnsafe – This function returns an ID if one has already been generated or null if not. (It can be used to e.g. log a message about a Fiber without potentially causing it to leak.)
* getFiberIDThrows – This function returns an ID if one has already been generated or it throws. (It can be used to guarantee expected behavior rather than to silently cause a leak.)
2021-05-18 11:42:08 -04:00
Brian Vaughn
7bef382bf9 Errors thrown by Store can be dismissed in boundary (#21520) 2021-05-18 10:36:31 -04:00
Brian Vaughn
1a2d792503 Tweaked DevTools error template title to match issue form template 2021-05-14 10:19:58 -04:00
Brian Vaughn
9cf1069ffc DevTools: Fixed version range NPM syntax 2021-05-14 10:14:34 -04:00
Brian Vaughn
2bf4805e4b Update entry point exports (#21488)
The following APIs have been added to the `react` stable entry point:
* `SuspenseList`
* `startTransition`
* `unstable_createMutableSource`
* `unstable_useMutableSource`
* `useDeferredValue`
* `useTransition`

The following APIs have been added or removed from the `react-dom` stable entry point:
* `createRoot`
* `unstable_createPortal` (removed)

The following APIs have been added to the `react-is` stable entry point:
* `SuspenseList`
* `isSuspenseList`

The following feature flags have been changed from experimental to true:
* `enableLazyElements`
* `enableSelectiveHydration`
* `enableSuspenseServerRenderer`
2021-05-12 11:28:14 -04:00
Brian Vaughn
85b543c6b4 Added new GitHub issue form for React DevTools bug reports (#21450)
Added a new bug report template built with GitHub issue forms:
https://gh-community.github.io/issue-template-feedback/structured/

And updated DevTools bug report link to send information formatted for this new template.
2021-05-07 08:46:58 -04:00
Brian Vaughn
67ebdf88bf Fix DevTools bug with Suspense+LegacyHidden component (#21432) 2021-05-04 22:28:17 -04:00
Brian Vaughn
d1542de3a6 Unify React.memo and React.forwardRef display name logic (#21392)
Co-authored-by: iChenLei <2470828450@qq.com>
2021-05-04 11:40:16 -04:00
Brian Vaughn
d19257b8fa DevTools Store emits errors before throwing (#21426)
The Store should never throw an Error without also emitting an event. Otherwise Store errors will be invisible to users, but the downstream errors they cause will be reported as bugs. (For example, github.com/facebook/react/issues/21402)

Emitting an error event allows the ErrorBoundary to show the original error.

Throwing is still valuable for local development and for unit testing the Store itself.
2021-05-04 10:46:26 -04:00
Brian Vaughn
b522638b99 Add GitHub API query to bug report template (#21421)
This may help debug why sometimes the GitHub API search seems to not find a match when it should.
2021-05-04 00:09:11 -04:00
Brian Vaughn
4ca62cac45 Improve DevTools bug template text (#21413) 2021-05-03 16:57:17 -04:00
Brian Vaughn
3c21aa855a DevTools refactor Profiler commit tree reconstruction to be iterative (#21383) 2021-04-28 16:32:35 -04:00
Brian Vaughn
a0d6b155dc DevTools should iterate over siblings during mount (#21377)
Previously, DevTools recursed over both children and siblings during mount. This caused potential stack overflows when there were a lot of children (e.g. a list containing many items).

Given the following example component tree:

       A
    B  C  D
    E     F
          G

A method that recurses for every child and sibling leads to a max depth of 6:

    A
    A -> B
    A -> B -> E
    A -> B -> C
    A -> B -> C -> D
    A -> B -> C -> D -> F
    A -> B -> C -> D -> F -> G

The stack gets deeper as the tree gets either deeper or wider.

A method that recurses for every child and iterates over siblings leads to a max depth of 4:

    A
    A -> B
    A -> B -> E
    A -> C
    A -> D
    A -> D -> F
    A -> D -> F -> G

The stack gets deeper as the tree gets deeper but is resilient to wide trees (e.g. lists containing many items).
2021-04-28 10:29:22 -04:00
Brian Vaughn
5196a95fd1 Updated DevTools to replace fburl.com link with fb.me link 2021-04-27 23:49:30 -04:00
Brian Vaughn
ecb599cd87 DevTools supports multiple modal dialogs at once (#21370) 2021-04-27 20:33:11 -04:00
Brian Vaughn
8e2bb3e89c DevTools: Add Bridge protocol version backend/frontend (#21331)
Add an explicit Bridge protocol version to the frontend and backend components as well as a check during initialization to ensure that both are compatible. If not, the frontend will display either upgrade or downgrade instructions.

Note that only the `react-devtools-core` (React Native) and `react-devtools-inline` (Code Sandbox) packages implement this check. Browser extensions inject their own backend and so the check is unnecessary. (Arguably the `react-devtools-inline` check is also unlikely to be necessary _but_ has been added as an extra guard for use cases such as Replay.io.)
2021-04-27 17:26:07 -04:00
Brian Vaughn
22ab39be68 DevTools console patching should handle Symbols without erroring (#21368) 2021-04-27 16:36:20 -04:00
Brian Vaughn
fc33f12bde Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
Sebastian Silbermann
84b9162cbe Use toMatchInlineSnapshot for dehydrated values (#20618) 2021-04-26 12:30:34 -04:00
Andrew Clark
a155860018 Fix: Don't flush discrete at end of batchedUpdates (#21229)
The outermost `batchedUpdates` call flushes pending sync updates at the
end. This was intended for legacy sync mode, but it also happens to
flush discrete updates in concurrent mode.

Instead, we should only flush sync updates at the end of
`batchedUpdates` for legacy roots. Discrete sync updates can wait to
flush in the microtask.

`discreteUpdates` has the same issue, which is how I originally noticed
this, but I'll change that one in a separate commit since it requires
updating a few (no longer relevant) internal tests.
2021-04-21 09:32:09 -07:00
Ricky
a632f7de3b Flip tuple order of useTransition (#20976) 2021-04-20 12:21:44 -04:00
Brian Vaughn
83bdc565f9 Remove @octokit/rest dependency from DevTools (#21317) 2021-04-19 21:20:34 -04:00
Brian Vaughn
4def1ceee2 Update DevTools Error strings to support GitHub fuzzy search (#21314) 2021-04-19 13:05:28 -04:00
Brian Vaughn
5027eb4650 DevTools fork console patching logic (#21301)
React has its own component stack generation code that DevTools embeds a fork of, but both of them use a shared helper for disabling console logs. This shared helper is DEV only though, because it was intended for use with React DEV-only warnings and we didn't want to unnecessarily add bytes to production builds.

But DevTools itself always ships as a production build– even when it's used to debug DEV bundles of product apps (with third party DEV-only warnings). That means this helper was always a noop.

The resolveCurrentDispatcher method was changed recently to replace the thrown error with a call to console.error. This newly logged error ended up slipping through and being user visible because of the above issue.

This PR updates DevTools to also fork the console patching logic (to remove the DEV-only guard).

Note that I didn't spot this earlier because my test harness (react-devtools-shell) always runs in DEV mode. 🤡
2021-04-16 12:01:47 -04:00
Brian Vaughn
c1a53ad2b2 DevTools pre-filter GH issues by repo (#21292) 2021-04-15 19:56:41 -04:00
Brian Vaughn
f3337aa544 DevTools error boundary: Search for pre-existing GH issues (#21279) 2021-04-15 13:34:54 -04:00
Brian Vaughn
68097787f6 DevTools should use reconciler version (rather than renderer version)
when available (#21269)
2021-04-14 14:48:05 -04:00
Brian Vaughn
bdc23c3dba DevTools shows which fibers scheduled the current update (#21171) 2021-04-09 10:35:06 -04:00
Brian Vaughn
b38ac13f94 DevTools: Add post-commit hook (#21183)
I recently added UI for the Profiler's commit and post-commit durations to the DevTools, but I made two pretty silly oversights:

    1. I used the commit hook (called after mutation+layout effects) to read both the layout and passive effect durations. This is silly because passive effects may not have flushed yet git at this point.
    2. I didn't reset the values on the HostRoot node, so they accumulated with each commit.

    This commitR addresses both issues:

    1. First it adds a new DevTools hook, onPostCommitRoot*, to be called after passive effects get flushed. This gives DevTools the opportunity to read passive effect durations (if the build of React being profiled supports it).
    2. Second the work loop resets these durations (on the HostRoot) after calling the post-commit hook so address the accumulation problem.
    I've also added a unit test to guard against this regressing in the future.

    * Doing this in flushPassiveEffectsImpl seemed simplest, since there are so many places we flush passive effects. Is there any potential problem with this though?
2021-04-08 22:04:51 -04:00
Sebastian Silbermann
1214b302e1 test: Fix "couldn't locate all inline snapshots" (#21205) 2021-04-08 11:18:13 -04:00
Sebastian Markbåge
172e89b4bf Reland Remove redundant initial of isArray (#21188)
* Remove redundant initial of isArray (#21163)

* Reapply prettier

* Type the isArray function with refinement support

This ensures that an argument gets refined just like it does if isArray is
used directly.

I'm not sure how to express with just a direct reference so I added a
function wrapper and confirmed that this does get inlined properly by
closure compiler.

* A few more

* Rename unit test to internal

This is not testing a bundle.

Co-authored-by: Behnam Mohammadi <itten@live.com>
2021-04-07 07:57:43 -07:00
Brian Vaughn
a817840ea7 DevTools: useModalDismissSignal bugfix (#21173)
* DevTools: useModalDismissSignal bugfix

Make useModalDismissSignal's manually added click/keyboard events more robust to sync flushed passive effects. (Don't let the same click event that shows a modal dialog also dismiss it.)

* Replaced event.timeStamp check with setTimeout
2021-04-05 11:09:43 -04:00
Sebastian Markbage
b4f119cdf1 Revert "Remove redundant initial of isArray (#21163)"
This reverts commit b130a0f5cd.
2021-04-01 15:19:00 -04:00
Behnam Mohammadi
b130a0f5cd Remove redundant initial of isArray (#21163) 2021-04-01 10:50:48 -07:00
Andrew Clark
3ba5c87377 Remove Scheduler indirection (#21107)
* Bump version number

* Remove Scheduler indirection

I originally kept the React PriorityLevel and Scheduler PriorityLevel
types separate in case there was a versioning mismatch between the two
modules. However, it looks like we're going to keep the Scheduler module
private in the short to medium term, and longer term the public
interface will match postTask. So, I've removed the extra indirection
(the switch statements that convert between the two types).
2021-03-28 14:13:38 -07:00
Erik
a5aa9d5253 Remove redundant if statement (#21101) 2021-03-26 13:50:58 -04:00
Andrew Clark
6d3ecb70dc Remove unstable_changedBits (#20953)
We added this unstable feature a few years ago, as a way to opt out of
context updates, but it didn't prove useful in practice.

We have other proposals for how to address the same problem, like
context selectors.

Since it was prefixed with `unstable_`, we should be able to remove it
without consequence. The hook API already warned if you used it.

Even if someone is using it somewhere, it's meant to be an optimization
only, so if they are using the API properly, it should not have any
semantic impact.
2021-03-19 15:36:51 -07:00
Brian Vaughn
7d06b80af6 Fixed primitive hook badge colors for light theme (#21034) 2021-03-19 09:52:59 -04:00
Brian Vaughn
119736b1c2 [FB-only] Show which hooks (indices) changed when profiling (#20998) 2021-03-17 12:28:21 -04:00
Brian Vaughn
bf11788bf0 DevTools Profiler: Add commit and post-commit durations to UI (#20984) 2021-03-17 12:27:37 -04:00
Chris Dobson
bd245c1bab Ensure sync-xhr is allowed before reload and profile (#20879)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-03-11 10:31:57 -05:00
Brian Vaughn
ec372faefe Remove DevTools dependency on Scheduler runWithPriority (#20967) 2021-03-10 08:52:19 -05:00
Brian Vaughn
5fe091c778 Swap log with cbrt for commit bar height (#20952) 2021-03-08 14:02:09 -05:00
Brian Vaughn
e7d2a558ad DevTools flushes updated passive warning/error info after delay (#20931)
* DevTools flushes updated passive warning/error info after delay
Previously this information was not flushed until the next commit, but this provides a worse user experience if the next commit is really delayed. Instead, the backend now flushes only the warning/error counts after a delay. As a safety, if there are already any pending operations in the queue, we bail.

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
2021-03-08 11:33:14 -05:00