Commit Graph

3841 Commits

Author SHA1 Message Date
Brian Vaughn
13036bfbc8 DevTools should not crawl unmounted subtrees when profiling starts (#23162)
Previously we crawled all subtrees, even not-yet-mounted ones, to initialize context values. This was not only unecessary, but it also caused an error to be thrown. This commit adds a test and fixes that behavior.
2022-01-21 11:05:49 -05:00
Andrew Clark
ca143e18d8 Prettier 2022-01-21 09:59:11 -05:00
Behnam Mohammadi
26baf6a174 styles: replace Array.isArray with module isArray (#23154) 2022-01-21 09:33:00 -05:00
Luna Ruan
7bee1379b7 Filter out deleted components that are added to the updaters list (#23156)
There was a bug that occurred when a destroy effect is called that causes an update. The update would be added to the updaters list even though the fiber that was calling the destroy effect was unmounted and no longer exists. This PR:

* Adds a patch to Devtools to filter out all in the update list that aren't in the fiberToIDMap (which contains all fibers currently on screen)
2022-01-20 13:29:43 -08:00
Brian Vaughn
a637084320 DevTools: Add Jest snapshot serializer for number formatting (#23139)
Numbers in JavaScript can have precision issues due to how they are encoded. This shows up in snapshot tests sometimes with values like 0.0009999999999999992, which makes the tests hard to read and visually diff.

This PR adds a new snapshot serializers which clamps numbers at 3 decimal points (e.g. the above number 0.0009999999999999992 is serialized as 0.001). This new serializer does not impact non-numeric values, integers, and special numbers like NaN and Infinity.
2022-01-20 15:52:17 -05:00
Brian Vaughn
505c15c9ef Don't inject timeline hooks unless React supports profiling (#23151)
This gives DevTools a way to detect whether the current React renderer supports Timeline profiling. (Version alone isn't enough to detect this, neither is general profiling support– since these two are controlled by different feature flags.)
2022-01-20 11:11:26 -05:00
Douglas Armstrong
e12a9dfc96 Fix production-only updateSyncExternalStore() crash when doing setState in render (#23150)
* Update ReactFiberHooks.new.js

* Add regression test + replace-fork

* Prettier

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2022-01-20 15:22:17 +00:00
Dan Abramov
e489402557 Warn when a callback ref returns a function (#23145) 2022-01-20 15:18:38 +00:00
Joey Arhar
05a55a4b09 Fix change events for custom elements (#22938)
* Bypass react event system for custom elements

* Going to try fixing react event system instead

* finally got it to call onChange, but perhaps too many times

* update test

* Removed ReactDOMComponent changes, now works but still doubles for bubbles

* Maybe i should only support bubbling events

* removed some old stuff

* cleaned up changeeventplugin stuff

* prettier, lint

* removed changeeventplugin stuff

* remove unneeded gate for onInput test

* Go back to using ChangeEventPlugin

* Add input+change test

* lint

* Move logic to shouldUseChangeEvent

* use memoizedProps instead of pendingProps

* Run form control behavior before custom element behavior

* add bubbling test

* forgot to append container to body

* add child event target test

* expand <input is=...> test expectations

* Make tests more realistic

* Add extra test

* Add missing gating

* Actually fix gating

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2022-01-19 19:34:07 +00:00
Dan Abramov
d8cfeaf221 Fix context propagation for offscreen/fallback trees (#23095)
* Failing test for Context.Consumer in suspended Suspense

See issue #19701.

* Fix context propagation for offscreen trees

* Address nits

* Specify propagation root for Suspense too

* Pass correct propagation root

* Harden test coverage

This test will fail if we remove propagation, or if we propagate with a root node like fiber.return or fiber.return.return. The additional DEV-only error helps detect a different kind of mistake, like if the thing being passed hasn't actually been encountered on the way up. However, we still leave the actual production loop to check against null so that there is no way we loop forever if the propagation root is wrong.

* Remove superfluous warning

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2022-01-19 16:30:34 +00:00
Brian Vaughn
d504824780 Enable scheduling profiler flag in react-dom/testing builds (#23142) 2022-01-19 11:20:42 -05:00
Dan Abramov
790b5246f6 Fix setState ignored in Safari when iframe is added to DOM in the same commit (#23111)
* Fix setState being ignored in Safari

* Add a regression test

* Add comment
2022-01-18 18:25:34 +00:00
Brian Vaughn
51947a14bb Refactored how React/DevTools log Timeline performance data (#23102)
Until now, DEV and PROFILING builds of React recorded Timeline profiling data using the User Timing API. This commit changes things so that React records this data by calling methods on the DevTools hook. (For now, DevTools still records that data using the User Timing API, to match previous behavior.)

This commit is large but most of it is just moving things around:

* New methods have been added to the DevTools hook (in "backend/profilingHooks") for recording the Timeline performance events.
* Reconciler's "ReactFiberDevToolsHook" has been updated to call these new methods (when they're present).
* User Timing method calls in "SchedulingProfiler" have been moved to DevTools "backend/profilingHooks" (to match previous behavior, for now).
* The old reconciler tests, "SchedulingProfiler-test" and "SchedulingProfilerLabels-test", have been moved into DevTools "TimelineProfiler-test" to ensure behavior didn't change unexpectedly.
* Two new methods have been added to the injected renderer interface: injectProfilingHooks() and getLaneLabelMap().

Relates to #22529.
2022-01-13 14:55:54 -05:00
Joey Arhar
a87adefecd Allow functions to be passed to custom element setters (#23042)
This is part of the new custom element features that were implemented
here:
24dd07bd26

When a custom element has a setter for a property and passes the `in`
heuristic, the value passed to the react property should be assigned
directly to the custom element's property, regardless of the type of the
value. However, it was discovered that this isn't working with
functions. This patch makes it work with functions.

Fixes https://github.com/facebook/react/issues/23041
2022-01-12 20:12:07 +00:00
Stefan Sundin
9a7e6bf0d0 Add --no-show-signature to "git show" commands (#23038)
* Add --no-show-signature to "git show" commands.

This fixes errors if the user has configured the following in their ~/.gitconfig:
[log]
showSignature = true

* yarn prettier-all
2022-01-11 12:14:08 -05:00
Gray Zhang
2f26eb85d6 Add exports field to react-refresh's package.json (#23087)
* Add exports field to react-refresh's package.json

* Update package.json

* Add runtime to exports
2022-01-11 16:48:09 +00:00
Luna Ruan
811634762a add enableTransitionTracing feature flag (#23079)
This PR adds the enableTransitionTracing feature flag
2022-01-10 12:32:40 -08:00
Jack Works
fe905f152f Update package.json (#22954) 2022-01-07 12:59:47 -08:00
Borja Paz Rodríguez
42c30e8b12 Correct typing errors detected in several files (#22965)
* Correct spelling errors in several files
* Correct typos in devtools-shared package files
2022-01-04 10:30:07 -05:00
btea
3dc41d8a25 fix: parseExportNamesInto specifiers typo (#22537) 2021-12-23 13:08:56 -05:00
BIKI DAS
20212349ad Fix variable name (#23021) 2021-12-23 08:35:54 -05:00
BIKI DAS
a8e9bbe0fe Made the variable name more meaningful (#23017) 2021-12-22 15:58:06 -05:00
Brian Vaughn
bcd24a6706 DevTools: Only show StrictMode badge on root elements (#23012)
* DevTools: Only show StrictMode badge on root elements

Showing an inline non-compliance badge for every element in the tree is noisy. This commit changes it so that we only show inline icons for root elements (although we continue to show an icon for inspected elements regardless).
2021-12-21 15:26:42 -05:00
Brian Vaughn
a4ead704ba Use ReactDOM Test Selector API in DevTools e2e tests (#22978)
Builds on top of the existing Playwright tests to plug in the test selector API: https://gist.github.com/bvaughn/d3c8b8842faf2ac2439bb11773a19cec

My goals in doing this are to...
1. Experiment with the new API to see what works and what doesn't.
2. Add some test selector attributes (and remove DOM-structure based selectors).
3. Focus the tests on DevTools itself (rather than the test app).

I also took this opportunity to add a few new test cases– like named hooks, editable props, component search, and profiling- just to play around more with the Playwright API.

Relates to issue #22646
2021-12-21 11:58:04 -05:00
Sebastian Markbåge
ceee524a8f Remove unnecessary clearContainer call (#22979)
This was added when we added error recovery for hydration errors. However,
when the fix up pass happens later on, it'll still call clearContainer in
the commit phase. So this call is unnecessary.
2021-12-17 09:40:39 -08:00
Brian Vaughn
aa8f2bdbce Refactored DevTools test shell for e2e (#22968)
Fixes a regression in the e2e target and makes things easier (hopefully) going forward when adding new e2e tests.
2021-12-15 11:42:59 -05:00
Brian Vaughn
e59233aa85 react-devtools-inline README updates (#22967) 2021-12-15 10:44:14 -05:00
Brian Vaughn
5b69c94eed React DevTools 4.22.0 -> 4.22.1 (#22962) 2021-12-14 23:52:50 -05:00
Brian Vaughn
b10c378024 Revert changes to react-devtools-inline Webpack config from PR #22760 (#22961) 2021-12-14 23:45:46 -05:00
Brian Vaughn
3f45b68141 Re-added deleted files array to react-devtools package.json (#22960) 2021-12-14 23:28:57 -05:00
Brian Vaughn
75d34aa083 Updated DevTools changelog 2021-12-14 16:50:17 -05:00
jstejada
0229baee21 React DevTools 4.21.0 -> 4.22.0 (#22951) 2021-12-14 14:19:21 -05:00
Brian Vaughn
911f92a44d DevTools: Support mulitple DevTools instances per page (#22949)
This is being done so that we can embed DevTools within the new React (beta) docs.

The primary changes here are to `react-devtools-inline/backend`:
* Add a new `createBridge` API
* Add an option to the `activate` method to support passing in the custom bridge object.

The `react-devtools-inline` README has been updated to include these new methods.

To verify these changes, this commit also updates the test shell to add a new entry-point for multiple DevTools.

This commit also replaces two direct calls to `window.postMessage()` with `bridge.send()` (and adds the related Flow types).
2021-12-14 12:16:16 -05:00
jstejada
5757919256 DevTools: Correctly log errors reported from the store (#22950) 2021-12-13 12:02:14 -05:00
jstejada
a049aa0155 [DevTools] Log errors occurring or reported to the frontend (#22948) 2021-12-13 11:38:45 -05:00
Brian Vaughn
3b3daf5573 Advocate for StrictMode usage within Components tree (#22886)
Adds the concept of subtree modes to DevTools to bridge protocol as follows:
1. Add-root messages get two new attributes: one specifying whether the root is running in strict mode and another specifying whether the root (really the root's renderer) supports the concept of strict mode.
2. A new backend message type (TREE_OPERATION_SET_SUBTREE_MODE). This type specifies a subtree root (id) and a mode (bitmask). For now, the only mode this message deals with is strict mode.

The DevTools frontend has been updated as well to highlight non-StrictMode compliant components.

The changes to the bridge protocol require incrementing the bridge protocol version number, which will also require updating the version of react-devtools-core backend that is shipped with React Native.
2021-12-10 11:05:18 -05:00
Brian Vaughn
2c1cf5618a DevTools should inject itself for XHTML pages too (not just HTML) (#22932) 2021-12-09 15:32:11 -05:00
salazarm
f2a59df48b Remove unstableAvoidThisFallback from OSS (#22884)
* avoidThisFallbackFlag

* avoidThisFallback flag

* missed a spot

* rm gating
2021-12-08 08:21:02 -08:00
Joey Arhar
24dd07bd26 Add custom element property support behind a flag (#22184)
* custom element props

* custom element events

* use function type for on*

* tests, htmlFor

* className

* fix ReactDOMComponent-test

* started on adding feature flag

* added feature flag to all feature flag files

* everything passes

* tried to fix getPropertyInfo

* used @gate and __experimental__

* remove flag gating for test which already passes

* fix onClick test

* add __EXPERIMENTAL__ to www flags, rename eventProxy

* Add innerText and textContent to reservedProps

* Emit warning when assigning to read only properties in client

* Revert "Emit warning when assigning to read only properties in client"

This reverts commit 1a093e584c.

* Emit warning when assigning to read only properties during hydration

* yarn prettier-all

* Gate hydration warning test on flag

* Fix gating in hydration warning test

* Fix assignment to boolean properties

* Replace _listeners with random suffix matching

* Improve gating for hydration warning test

* Add outerText and outerHTML to server warning properties

* remove nameLower logic

* fix capture event listener test

* Add coverage for changing custom event listeners

* yarn prettier-all

* yarn lint --fix

* replace getCustomElementEventHandlersFromNode with getFiberCurrentPropsFromNode

* Remove previous value when adding event listener

* flow, lint, prettier

* Add dispatchEvent to make sure nothing crashes

* Add state change to reserved attribute tests

* Add missing feature flag test gate

* Reimplement SSR changes in ReactDOMServerFormatConfig

* Test hydration for objects and functions

* add missing test gate

* remove extraneous comment

* Add attribute->property test
2021-12-08 15:11:42 +00:00
Andrew Clark
ec78b135fb Don't override use-sync-external-store peerDeps (#22882)
Usually the build script updates transitive React dependencies so that
they refer to the corresponding release version.

For use-sync-external-store, though, we also want to support older
versions of React, too. So the normal behavior of the build script
isn't sufficient.

For now, to unblock, I hardcoded a special case, but we should consider
a better way to handle this in the future.
2021-12-07 23:26:12 -08:00
Brian Vaughn
ad607469c5 StyleX plug-in for resolving atomic styles to values for props.xstyle (#22808)
Adds the concept of "plugins" to the inspected element payload. Also adds the first plugin, one that resolves StyleX atomic style names to their values and displays them as a unified style object (rather than a nested array of objects and booleans).

Source file names are displayed first, in dim color, followed by an ordered set of resolved style values.

For builds with the new feature flag disabled, there is no observable change.

A next step to build on top of this could be to make the style values editable, but change the logic such that editing one directly added an inline style to the item (rather than modifying the stylex class– which may be shared between multiple other components).
2021-12-07 20:04:12 -05:00
salazarm
5041c37d27 Remove hydrate option from createRoot (#22878)
* remove hydrate: true option

* remove missed comment

* lint

* warning

* circumvent flow
2021-12-07 16:10:00 -05:00
salazarm
c7917fe769 Test showing that a mismatch at the root recovers with client render but shows loading state (#22873)
* rm console.log

* gate test

* move test

* show fallback state
2021-12-06 12:36:02 -05:00
jstejada
12bffc78d8 [DevTools] Emit new event when DevTools connects in standalone app (#22848) 2021-12-06 08:49:15 -05:00
salazarm
3f9480f0f5 enable continuous replay flag (#22863) 2021-12-03 19:35:20 -05:00
Brian Vaughn
8b8817845a Timeline search (#22799)
Refactor SearchInput component (used in Components tree) to be generic DevTools component with two uses: ComponentSearchInput and TimelineSearchInput.

Refactored Timeline Suspense to more closely match other, newer Suspense patterns (e.g. inspect component, named hooks) and colocated Susepnse code in timelineCache file.

Add search by component name functionality to the Timeline. For now, searching zooms in to the component measure and you can step through each time it rendered using the next/previous arrows.
2021-12-03 16:23:48 -05:00
Andrew Clark
4729ff6d1f Implement identifierPrefix option for useId (#22855)
When an `identifierPrefix` option is given, React will add it to the
beginning of ids generated by `useId`.

The main use case is to avoid conflicts when there are multiple React
roots on a single page.

The server API already supported an `identifierPrefix` option. It's not
only used by `useId`, but also for React-generated ids that are used to
stitch together chunks of HTML, among other things. I added a
corresponding option to the client.

You must pass the same prefix option to both the server and client.
Eventually we may make this automatic by sending the prefix from the
server as part of the HTML stream.
2021-12-02 17:49:43 -08:00
Dan Abramov
71d16750c5 Replay capture phase for continuous events (#22856)
Co-authored-by: Dan Abramov <dan.abramov@me.com>

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:33:44 +00:00
Dan Abramov
44f99d75fa Track currently replaying event (#22853)
* Track currently replaying event

Co-authored-by: Dan Abramov <dan.abramov@me.com>

* Add warnings

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:11:21 +00:00
Dan Abramov
e737ea9655 Fork dispatch function based on the flag (#22852)
* Fork function based on a flag

* Prune false branches

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:02:49 +00:00