Commit Graph
241 Commits
Author SHA1 Message Date
Ikko AshimineandGitHub 107f68d7aa Fix typo in bridge.js (#21621) 2021-06-04 11:42:09 -04:00
b2844b7d9a Devtools: add feature to trigger an error boundary (#21583)
Co-authored-by: Brian Vaughn <[email protected]>
2021-06-03 11:21:44 -04:00
Brian VaughnandGitHub 4324b0479f DevTools: Format error message (#21580)
To support GitHub API fuzzy issue search
2021-05-27 15:44:14 -04:00
Brian VaughnandGitHub 206a7facc6 Enabled Profiling feature flags for OSS release (#21565)
* Enabled Profiling feature flags for OSS release

`enableProfilerCommitHooks` and `enableProfilerNestedUpdatePhase`
2021-05-25 17:32:14 -04:00
Brian VaughnandGitHub bdae1b3f4a DevTools: Support an element mounting before its owner (#21562) 2021-05-25 14:49:05 -04:00
Brian VaughnandGitHub ae049a0dc5 DevTools: Revert force deep re-mount when Fast Refresh detected (#21539)
This reverts the most expensive part of 68db562f6 (which seems to no longer be necessary after subsequent changes).
2021-05-20 15:28:59 -04:00
Brian VaughnandGitHub 2ad45b36ad 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 VaughnandGitHub 27d29a696a 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 VaughnandGitHub dfb8ebf078 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 VaughnandGitHub fc7ed12d54 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 VaughnandGitHub 266a011709 DevTools bugfix for useState() with hasOwnProperty key (#21524) 2021-05-18 16:43:33 -04:00
Brian VaughnandGitHub 14e0db6322 Fixed another Symbol concatenation issue with DevTools format() util (#21521) 2021-05-18 11:46:04 -04:00
Brian VaughnandGitHub 68db562f66 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 VaughnandGitHub 71dadb6ecb Errors thrown by Store can be dismissed in boundary (#21520) 2021-05-18 10:36:31 -04:00
Brian Vaughn c7c3ac5f15 Tweaked DevTools error template title to match issue form template 2021-05-14 10:19:58 -04:00
Brian Vaughn cedb3adb75 DevTools: Fixed version range NPM syntax 2021-05-14 10:14:34 -04:00
Brian VaughnandGitHub b86ad519ba 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 VaughnandGitHub 2ff1c3964e 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 VaughnandGitHub 997683098b Fix DevTools bug with Suspense+LegacyHidden component (#21432) 2021-05-04 22:28:17 -04:00
527633288c Unify React.memo and React.forwardRef display name logic (#21392)
Co-authored-by: iChenLei <[email protected]>
2021-05-04 11:40:16 -04:00
Brian VaughnandGitHub cef8b51dd5 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 VaughnandGitHub cc7abe23e7 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 VaughnandGitHub 6c1407704b Improve DevTools bug template text (#21413) 2021-05-03 16:57:17 -04:00
Brian VaughnandGitHub 705da32b3f DevTools refactor Profiler commit tree reconstruction to be iterative (#21383) 2021-04-28 16:32:35 -04:00
Brian VaughnandGitHub 10976b6a03 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 ebfe0ae788 Updated DevTools to replace fburl.com link with fb.me link 2021-04-27 23:49:30 -04:00
Brian VaughnandGitHub ef6d74b778 DevTools supports multiple modal dialogs at once (#21370) 2021-04-27 20:33:11 -04:00
Brian VaughnandGitHub 5f6c7586ed 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 VaughnandGitHub 53531d2764 DevTools console patching should handle Symbols without erroring (#21368) 2021-04-27 16:36:20 -04:00
Brian VaughnandGitHub 60228a0f7e Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
Sebastian SilbermannandGitHub b4efc06886 Use toMatchInlineSnapshot for dehydrated values (#20618) 2021-04-26 12:30:34 -04:00
Andrew ClarkandGitHub e2777c2523 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
RickyandGitHub e305b111a5 Flip tuple order of useTransition (#20976) 2021-04-20 12:21:44 -04:00
Brian VaughnandGitHub bbd112e0da Remove @octokit/rest dependency from DevTools (#21317) 2021-04-19 21:20:34 -04:00
Brian VaughnandGitHub 15fed0570a Update DevTools Error strings to support GitHub fuzzy search (#21314) 2021-04-19 13:05:28 -04:00
Brian VaughnandGitHub 85217a9c5b 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 VaughnandGitHub 7889613b74 DevTools pre-filter GH issues by repo (#21292) 2021-04-15 19:56:41 -04:00
Brian VaughnandGitHub 63c495d451 DevTools error boundary: Search for pre-existing GH issues (#21279) 2021-04-15 13:34:54 -04:00
Brian VaughnandGitHub c237bfb8d2 DevTools should use reconciler version (rather than renderer version)
when available (#21269)
2021-04-14 14:48:05 -04:00
Brian VaughnandGitHub fdc7b79ef2 DevTools shows which fibers scheduled the current update (#21171) 2021-04-09 10:35:06 -04:00
Brian VaughnandGitHub 29a8f028c6 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 SilbermannandGitHub abf15a6cb5 test: Fix "couldn't locate all inline snapshots" (#21205) 2021-04-08 11:18:13 -04:00
8d1611f658 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 <[email protected]>
2021-04-07 07:57:43 -07:00
Brian VaughnandGitHub 80b89f577b 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 e92c1c329d Revert "Remove redundant initial of isArray (#21163)"
This reverts commit 619546c554.
2021-04-01 15:19:00 -04:00
Behnam MohammadiandGitHub 619546c554 Remove redundant initial of isArray (#21163) 2021-04-01 10:50:48 -07:00
Andrew ClarkandGitHub 78b51e97c2 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
ErikandGitHub 43d7929add Remove redundant if statement (#21101) 2021-03-26 13:50:58 -04:00
Andrew ClarkandGitHub 6120d9ad06 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 VaughnandGitHub 1315196d10 Fixed primitive hook badge colors for light theme (#21034) 2021-03-19 09:52:59 -04:00