Commit Graph

455 Commits

Author SHA1 Message Date
Tianyu Yao c08d8b8041
Revert "Add SyncHydrationLane" (#25708)
Reverts facebook/react#25698
DevTools CI for older version are failing
2022-11-18 15:00:35 -08:00
Tianyu Yao f31005d6ad
Add SyncHydrationLane (#25698)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn debug-test --watch TestName`, open
`chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
For more context: https://github.com/facebook/react/pull/25692

Based on https://github.com/facebook/react/pull/25695. This PR adds the
`SyncHydrationLane` so we rewind on sync updates during selective
hydration. Also added tests for ContinuouseHydration and
DefaultHydration lanes.


## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
yarn test
2022-11-17 12:14:49 -08:00
Mengdi Chen c54e3541b2
[DevTools] bug fix for Hydrating fibers (#25663)
## Summary

This PR is to fix a bug: an "element cannot be found" error when
hydrating Server Components

### The problem
<img width="1061" alt="image"
src="https://user-images.githubusercontent.com/1001890/201206046-ac32a5e3-b08a-4dc2-99f4-221dad504b28.png">

To reproduce:
1. setting up a vercel next.js 13 playground locally
https://github.com/vercel/app-playground
2. visit http://localhost:3000/loading
3. click "electronics" button to navigate to
http://localhost:3000/loading/electronics to trigger hydrating
4. inspect one of the skeleton card UI from React DevTools extension

### The root cause & fix
This bug was introduced in #22527. When syncing reconciler changes, the
value of `Hydrating` was copied from another variable `Visibility` (one
more zero in the binary number).
To avoid this kind of issue in the future, a new file `ReactFiberFlags`
is created following the same format of the one in reconciler, so that
it's easier to sync the number without making mistakes.
The reconciler fiber flag file is also updated to reflect which of the
flags are used in devtools

## How did you test this change?

I build it locally and the bug no longer exist on
http://localhost:3000/loading
2022-11-11 15:18:06 -05:00
Mengdi Chen 18dff7990a
[DevTools] add support for HostSingleton & HostResource (#25616)
## Summary

This is to support two new reconciler work tags `HostSingleton` and
`HostResource` introduced in PRs #25243 #25426. The behavior is
described below.
I also renamed an option in components settings from an internal concept
"host" to more understood "dom nodes"

## How did you test this change?

Tested on the latest Vercel playground app
https://github.com/vercel/app-playground/

Before the change, devtools cannot show correct display name for these
new elements. Also, some unnecessary internal details are exposed to
users.
<img width="1395" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578181-c4e4ea74-baa1-4507-83d0-91a62ad7de5f.png">

After the change, the display names are correctly shown and the "state"
would always be hidden in the detail view.
<img width="1417" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578442-adc1951d-7d5b-4b84-ad64-85bcf7a8ebcc.png">

These elements will also be hidden just like other native dom elements
(e.g. `<div>`)
<img width="836" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578598-2dfacf64-ddc9-42b5-a246-dd0b09f629af.png">
2022-11-07 15:23:17 -05:00
Robert Balicki fecc288b7d
[react devtools] Device storage support (#25452)
# Summary
* This PR adds support for persisting certain settings to device
storage, allowing e.g. RN apps to properly patch the console when
restarted.
* The device storage APIs have signature `getConsolePatchSettings()` and
`setConsolePatchSettings(string)`, in iOS, are thin wrappers around the
`Library/Settings` turbomodule, and wrap a new TM that uses the `SharedPreferences` class in Android.
* Pass device storage getters/setters from RN to DevTools'
`connectToDevtools`. The setters are then used to populate values on
`window`. Later, the console is patched using these values.
* If we receive a notification from DevTools that the console patching
fields have been updated, we write values back to local storage.
* See https://github.com/facebook/react-native/pull/34903

# How did you test this change?
Manual testing, `yarn run test-build-devtools`, `yarn run prettier`,
`yarn run flow dom`

## Manual testing setup:

### React DevTools Frontend
* Get the DevTools frontend in flipper:
* `nvm install -g react-devtools-core`, then replace that package with a
symlink to the local package
  * enable "use globally installed devtools" in flipper
* yarn run start in react-devtools, etc. as well

### React DevTools Backend
* `yarn run build:backend` in react-devtools-core, then copy-paste that
file to the expo app's node_modules directory

### React Native
* A local version of React Native can be patched in by modifying an expo
app's package.json, as in `"react-native":
"rbalicki2/react-native#branch-name"`

# Versioning safety
* There are three versioned modules to worry about: react native, the
devtools frontend and the devtools backend.
* The react devtools backend checks for whether a `cachedSettingsStore`
is passed from react native. If not (e.g. if React Native is outdated),
then no behavior changes.
* The devtools backend reads the patched console values from the cached
settings store. However, if nothing has been stored, for example because
the frontend is outdated or has never synced its settings, then behavior
doesn't change.
* The devtools frontend sends no new messages. However, if it did send a
new message (e.g. "store this value at this key"), and the backend was
outdated, that message would be silently ignored.
2022-10-25 13:25:33 +11:00
Mengdi Chen 6dbccb9249
[DevTools] upgrade to Manifest V3 (#25145)
## Summary

resolves #24522

To upgrade to Manifest V3, one of the biggest issue is that we are no
longer allowed to add a script element with code in textContent so that
it would run synchronously. It's necessary for us because we need to
inject a global hook for react reconciler to detect whether devtools
exist.
To do that, we'll leverage a new API
`chrome.scripting.registerContentScripts` in V3. Particularly, we rely
on the "world" option (added in Chrome v102
[commit](e5ad3451c1))
to run it in the "main world" on the page.

This PR also renames a few content script files so that it's easier to
tell them apart from other extension scripts and understand the purpose
of each of them.

Manifest V3 is not yet ready for Firefox, so we need to keep some code
for compatibility.

## How did you test this change?

`yarn build:chrome && yarn test:chrome`
`yarn build:edge && yarn test:edge`
`yarn build:firefox && yarn test:firefox`
2022-10-21 22:52:18 -04:00
Andrew Clark 9cdf8a99ed
[Codemod] Update copyright header to Meta (#25315)
* Facebook -> Meta in copyright

rg --files | xargs sed -i 's#Copyright (c) Facebook, Inc. and its affiliates.#Copyright (c) Meta Platforms, Inc. and affiliates.#g'

* Manual tweaks
2022-10-18 11:19:24 -04:00
c0dedance 9fb581c7cc
Refactor: merge duplicate imports (#25489)
Co-authored-by: Jan Kassens <jan@kassens.net>
2022-10-16 21:58:58 -04:00
Jan Kassens ea04a486a7
Flow: remove unused suppressions (#25424)
Removes $FlowFixMe's that are no longer needed.

Used flow/tool from the Flow repo:

```
 ~/Developer/flow/tool update-suppressions .
```
2022-10-04 16:18:12 -04:00
Jan Kassens 9813edef29 Flow upgrade to 0.188
ghstack-source-id: 5c359b97cc
Pull Request resolved: https://github.com/facebook/react/pull/25423
2022-10-04 15:49:48 -04:00
Jan Kassens 3b6826ed9e Flow: inference_mode=constrain_writes
This mode is going to be the new default in Flow going forward.
There was an unfortuante large number of suppressions in this update.

More on the changes can be found in this [Flow blog post](https://medium.com/flow-type/new-flow-language-rule-constrained-writes-4c70e375d190).

Added some of the required annotations using the provided codemod:

```sh
node_modules/.bin/flow codemod annotate-declarations --write .
```

ghstack-source-id: 0b168e1b23
Pull Request resolved: https://github.com/facebook/react/pull/25422
2022-10-04 15:49:48 -04:00
Jan Kassens f02a5f5c79 Flow upgrade to 0.182
ghstack-source-id: b9bb8c1560
Pull Request resolved: https://github.com/facebook/react/pull/25419
2022-10-04 13:37:58 -04:00
Jan Kassens 72593f008e Flow upgrade to 0.176
This upgrade deprecated calling `new` on functions which introduced
the majority of breakages and I suppressed those.

ghstack-source-id: 545363f3c5
Pull Request resolved: https://github.com/facebook/react/pull/25418
2022-10-04 13:37:58 -04:00
Jan Kassens 1089faf0d8 Flow: run codemod to remove existential type
The existential type `*` was deprecated and a codemod provided to replace it. Ran that and did some manual fixups:

```sh
node_modules/.bin/flow codemod replace-existentials --write .
```

ghstack-source-id: 4c98b8db6a
Pull Request resolved: https://github.com/facebook/react/pull/25416
2022-10-04 13:37:58 -04:00
Jan Kassens 338e6a967c Flow upgrade to 0.155
This version banned use of this in object functions.

ghstack-source-id: f49fd5e1b7
Pull Request resolved: https://github.com/facebook/react/pull/25414
2022-10-04 11:49:15 -04:00
Jan Kassens 8bc95bb3c8 Flow upgrade to 0.154
ghstack-source-id: d84024950a
Pull Request resolved: https://github.com/facebook/react/pull/25413
2022-10-04 11:49:14 -04:00
Jan Kassens 9f8a98a390 Flow upgrade to 0.153
- method unbinding is no longer supported in Flow for soundness, this added a bunch of suppressions
- Flow now prevents objects to be supertypes of interfaces/classes

ghstack-source-id: d7749cbad8
Pull Request resolved: https://github.com/facebook/react/pull/25412
2022-10-04 11:30:06 -04:00
Jan Kassens adb58f529d Flow upgrade to 0.152
- 0.147 removes access to Object.prototype via the global object.
- 0.149 removed deprecated config options

ghstack-source-id: c77f9b3739
Pull Request resolved: https://github.com/facebook/react/pull/25411
2022-10-04 11:30:06 -04:00
Jan Kassens 64fe791be8 Flow upgrade to 0.146
This upgrade made more expressions invalidate refinements. In some
places this lead to a large number of suppressions that I automatically
suppressed and should be followed up on when the code is touched.
I think most of them might require either manual annotations or moving
a value into a const to allow refinement.

ghstack-source-id: a45b40abf0
Pull Request resolved: https://github.com/facebook/react/pull/25410
2022-10-04 11:01:50 -04:00
Jan Kassens 0a3072278e
Flow: complete types first migration (#25389)
This complete the "types first" migration and enables the config everywhere.
2022-10-03 21:59:33 -04:00
Vic Graf 5b59dd6400
Fix duplicate words tests (#25333)
* refactor: removed duplicated words in comments
* refactor: removed duplicate words in tests
2022-09-27 10:07:06 -04:00
Victoria Graf 3d615fc14a
Grammar. Removed doubles of the word "the". (#25295) 2022-09-19 10:04:03 -04:00
Jan Kassens fc16293f3f
Flow: well_formed_exports for devtools (#25266) 2022-09-15 16:45:29 -04:00
Jan Kassens e6a062bd2a
Flow: add simple explicit export types to Devtools (#25251) 2022-09-13 12:03:20 -04:00
Robert Balicki 271bf90a94
[react devtools][easy] Centralize calls to patchConsoleUsingWindowValues (#25222)
* Instead of reading from window in two separate places, do this in a single function
* Add some type safety
2022-09-13 11:24:10 -04:00
Jan Kassens 6aa38e74c7
Flow: enable unsafe-addition error (#25242) 2022-09-12 16:22:50 -04:00
Jan Kassens ba7b6f4183
Flow: upgrade to 0.132 (#25244) 2022-09-12 14:36:02 -04:00
Jan Kassens 8003ab9cf5
Flow: remove explicit object syntax (#25223) 2022-09-09 16:03:48 -04:00
Robert Balicki 425f9fbba0
[react devtools] Don't check for NODE_ENV==='test' because it never is (#25186)
* remove useless condition
2022-09-09 11:31:32 -04:00
Robert Balicki 540ba5b403
[react devtools][easy] Change variable names, etc. (#25211)
* Change variable names, put stuff in constants, etc. in preparation for next diff
2022-09-09 11:09:30 -04:00
Jan Kassens 8a9e7b6cef
Flow: implicit-inexact-object=error (#25210)
* implicit-inexact-object=error
* default everything ambiguous to exact object
* inexact where exact causes errors
2022-09-09 10:13:58 -04:00
Jan Kassens a473d08fce
Update to Flow from 0.97 to 0.122 (#25204)
* flow 0.122
* update ReactModel type
2022-09-08 11:46:07 -04:00
Luna Ruan c80e54116e
[DevTools][Bugfix] Don't hide fragment if it has a key (#25197)
resolves #25187

---

We shouldn't hide fragments that have a key because this is important information that the user might want in the future.
2022-09-07 10:21:30 -07:00
Tim Neutkens a9dc73cfd4
Handle info, group, and groupCollapsed in Strict Mode logging (#25172)
* Handle info, group, and groupCollapsed in Strict Mode logging

While working on the new Next.js router which heavily relies on useReducer I noticed that `group` and `groupCollapsed` which both take labels were showing as-is in the console for the second render/dispatch in Strict Mode logs. While looking at the code I found that `info` was also not instrumented.

I've added additional handling for:
- `info`
- `group`
- `groupCollapsed`

* Remove console.log

* Fix tests
2022-09-06 10:03:27 -07:00
Robert Balicki 7e5322ccf2
run prettier (#25164) 2022-08-31 14:20:01 -04:00
Robert Balicki 47867a772e
[react devtools][easy] Fix code highlighting in VSCode (#25155)
* Minor change that fixes code highlighting in VSCode in a particular file
2022-08-31 14:07:37 -04:00
Jan Kassens a40ddf3124
Fix CI: run `yarn prettier-all` (#25163) 2022-08-31 18:50:04 +01:00
Robert Balicki aa80a309b1
[react devtools][easy] Rename LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY to LOCAL_STORAGE_SHOULD_APPEND_COMPONENT_STACK_KEY (#25154)
* This more accurately describes what this constant does
2022-08-30 13:32:52 -04:00
Tianyu Yao 181525338e
[DevTools] Highlight RN elements on hover (#25106)
* [DevTools] Highlight RN elements on hover

* Remove unused TODO
2022-08-24 11:25:22 -07:00
Tianyu Yao 26ba5fb2e0
[DevTools] Add events necessary for click to inspect on RN (#25111)
* Add inspectingNative events for RN

* Enable inspection toggle UI for RN

* Add a stopInspectingNative method for agent
2022-08-19 16:18:14 -07:00
Mengdi Chen 5f34b051df
[Devtools] add logs for profiler tab switch & settings change (#24966)
* [devtools] add logs for profiler tab switch & settings change

* prettier

* remove unnecessary console.log

* better naming: logEvent -> loggerEvent

* use same object for event and metadata
2022-07-25 11:53:38 -04:00
Sebastian Silbermann b66936ece7
devtools: Remove ForwardRef/Memo from display name if `displayName` is set (#21952)
* feat(devtools): Remove ForwardRef/Memo from display name if `displayName` is set

* Avoid potentially wasting work by inlining `functionName`
2022-07-25 09:02:12 +02:00
Mengdi Chen 3ddbedd052
[devtools] log more events + metadata (#24951)
* [devtools] log more events + metadata

* better typing

* consistent string type
2022-07-19 15:22:09 -04:00
Mengdi Chen 992911981b
[DevTools] add simple usage events for internal logging (#24888)
* [DevTools] add simple events for internal logging

* fix lint

* fix lint

* better event name

* fix flow

* better way to fix flow

* combine 'select-element'

* use same event name for selecting element by inspecting
2022-07-18 15:52:53 -04:00
Mengdi Chen 4bc83e6821
[DevTools] enable `enableProfilerComponentTree` flag for all builds (#24921) 2022-07-13 15:21:32 -04:00
Luna Ruan c3b18571db
[DevTools][Bugfix] Fix DevTools Perf Issue When Unmounting Large React Subtrees (#24863)
We've recently had multiple reports where, if React DevTools was installed, unmounting large React subtrees would take a huge performance hit (ex. from 50ms to 7 seconds). 

Digging in more, we realized for every fiber that unmounts, we called `untrackFibers`, which calls `clearTimeout` (and does some work manipulating a set, but this wasn't the bulk of the time). We ten call `recordUnmount`, which adds the timer back. Adding and removing the timer so many times was taking upwards of 50ms per timer add/remove call, which was resulting in exorbitant amounts of time spent in DevTools deleting subtrees.

It looks like we are calling `untrackFibers` so many times to avoid a race condition with Suspense children where we unmount them twice (first a "virtual" unmount when the suspense boundary is toggled from visible to invisible, and then an actual unmount when the new children are rendered) without modifying `fiberIDMap`. We can fix this race condition by using the `untrackFibersSet` as a lock and not calling `recordUnmount` if the fiber is in the set and hasn't been processed yet. This works because the only way fibers are added in the set is via `recordUnmount` anyway.

This PR also adds a test to make sure this change doesn't regress the previous behavior.

**Before**
![image](https://user-images.githubusercontent.com/2735514/177655428-774ee306-0568-49ce-987e-b5213b613265.png)

**After**
![image](https://user-images.githubusercontent.com/2735514/177655604-a217583f-787e-438e-b6f9-18953fe32444.png)
2022-07-07 10:43:25 -04:00
Luna Ruan 4e1fcfa771
[DevTools] Resign Timeline Profiler Sidebar (#24816)
This PR:
* Redesigned the sidebar to resemble the flamegraph profiler sidebar and added title and timestamp to the sidebar
* Added ability to copy the component stack (for places where you're unable to link to source)

https://user-images.githubusercontent.com/2735514/176564897-5301d6d4-429a-4ea3-86cd-74427cff4ce6.mov
2022-06-29 17:54:06 -07:00
Luna Ruan 1974d08c93
[DevTools] Fix Bugs With Component Stacks (#24815)
This PR:
* Simplifies the code in `SidebarEventInfo` by passing it the actual clicked event rather than an index.
* Lightly refactored the `SidebarEventInfo` code so that it can be used for more than just `schedulingEvents`
* Fixes bug. Previously, whenever a state update event was clicked, we updated the `selectedCommitIndex` in the `ProfilerContext`. However, this index is used for the selected commit in the Flamegraph profiler, which caused a bug where if you would change the contents of the event sidebar, the commit sidebar in the Flamegraph profiler would change too. This PR replaces this with the actual event info instead
2022-06-29 16:00:48 -07:00
Luna Ruan cd80d3274d
[DevTools] Add column number to viewSourceLineFunction (#24814)
Add column number for `viewSourceLineFunction` and renamed the function to `viewUrlSourceFunction` to match the other source function naming conventions
2022-06-29 10:38:27 -07:00
Mengdi Chen f01e119b7d
[DevTools] Log page URL in internal build (#24799)
* test log

* fix attribute name

* fix lint

* tabs can be empty

* improve coding style per comments
2022-06-29 13:02:53 -04:00