Commit Graph

14431 Commits

Author SHA1 Message Date
Luna Ruan 152ecce117
DevTools 4.15.0 -> 4.16.0 (#22104) 2021-08-16 14:55:47 -07:00
Luna Ruan f6ec4661db
make parseHookNames a separate bundle (#22102) 2021-08-16 16:46:46 -04:00
Brian Vaughn 55d01aa0f3
Scheduling profiler: Canvas views clip by default (#22100) 2021-08-16 13:20:07 -04:00
Tommy Groshong bc4e751121
Typo: 'occured' -> 'occurred' in comment (#22094) 2021-08-15 17:25:22 -04:00
Brian Vaughn 89910635f7
Scheduling Profiler: Inline snapshots (#22091) 2021-08-14 11:10:36 -04:00
Brian Vaughn 54e170c794
[DevTools] Add screenshots to Scheduling Profiler (#22088) 2021-08-13 17:14:29 -04:00
Brian Vaughn e4e8226c62
Fixed Components tree indentation bug for Chrome extension (#22083)
By upgrading react-virtualized-auto-sizer to 1.0.6

See https://github.com/bvaughn/react-virtualized-auto-sizer/pull/39
2021-08-12 20:41:56 -04:00
Brian Vaughn 82583617b7
Updated DevTools CHANGELOG
Fixed header typo
2021-08-12 11:03:33 -04:00
Brian Vaughn c2bb975337
Added Scheduling Profiler notes and videos to the DevTools CHANGELOG 2021-08-12 11:02:30 -04:00
Brian Vaughn 07e58658c9
Add script to generate DevTools changelog text (#22077) 2021-08-12 10:43:56 -04:00
Brian Vaughn ef582fbea1
Added taneliang and kartikcho to scheduling profiler credits 2021-08-11 17:48:37 -04:00
Juan c6f2188ed6
DevTools 4.14.0 -> 4.15.0 2021-08-11 16:47:20 -04:00
Juan 531c97ef7a
[DevTools] Updated source map extension format + more precise types (#22073)
## Summary

Follow up from https://github.com/facebook/react/pull/22010.

As suggested by @motiz88, update the way the react sources metadata is stored within the fb sources metadata. Specifically,  instead of `x_facebook_sources` directly containing a hook map in the second position of the metadata tuple for a given source, it contains the react sources metadata itself, which is also a tuple of react sources metadata for a given source, and which contains the hook map in the first position. This way the react sources metadata tuple can be extended to contain more react-specific metadata without taking up more positions in the top-level facebook sources metadata.

As part of this change:
- Adds more precise Flow types, mostly borrowed from Metro
- Fixes the facebook sources field name (we were using `x_fb_sources` but it should be `x_facebook_sources`

## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
2021-08-11 15:46:22 -04:00
Brian Vaughn ad150533d6
Updated @reach packages to fix unmount bug (#22075) 2021-08-11 14:43:25 -04:00
Brian Vaughn 280e3f936f
DevTools: Scheduling profiler: Add vertical scroll bar (#22005)
Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2021-08-11 14:19:45 -04:00
Juan 88d121899a
[DevTools] Support extended source maps with named hooks information (#22010)
## Summary

Adds support for statically extracting names for hook calls from source code, and extending source maps with that information so that DevTools does not have to directly parse source code at runtime, which will speed up the Named Hooks feature and allow it to be enabled by default.

Specifically, this PR includes the following parts:

- [x] Adding logic to statically extract relevant hook names from the parsed source code (i.e. the babel ast). Note that this logic differs slightly from the existing logic in that the existing logic also uses runtime information from DevTools (such as whether given hooks are a custom hook) to extract names for hooks, whereas this code is meant to run entirely at build time, so it does not rely on that information.
- [x] Generating an encoded "hook map", which encodes the information about a hooks *original* source location, and it's corresponding name. This "hook map" will be used to generate extended source maps, included tentatively under an extra `x_react_hook_map` field. The map itself is formatted and encoded in a very similar way as how the `names` and `mappings` fields of a standard source map are encoded ( = Base64 VLQ delta coding representing offsets into a string array), and how the "function map" in Metro is encoded, as suggested in #21782. Note that this initial version uses a very basic format, and we are not implementing our own custom encoding, but reusing the `encode` function from `sourcemap-codec`.
- [x] Updating the logic in `parseHookNames` to check if the source maps have been extended with the hook map information, and if so use that information to extract the hook names without loading the original source code. In this PR we are manually generating extended source maps in our tests in order to test that this functionality works as expected, even though we are not actually generating the extended source maps in production.

The second stage of this work, which will likely need to occur outside this repo, is to update bundlers such as Metro to use these new primitives to actually generate source maps that DevTools can use.

### Follow-ups

- Enable named hooks by default when extended source maps are present
- Support looking up hook names when column numbers are not present in source map.
- Measure performance improvement of using extended source maps (manual testing suggests ~4 to 5x faster)
- Update relevant bundlers to generate extended source maps.

## Test Plan

- yarn flow
- Tests still pass
  - yarn test
  - yarn test-build-devtools
- Named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, facebook).
- For new functionality:
  - New tests for statically extracting hook names.
  - New tests for using extended source maps to look up hook names at runtime.
2021-08-11 10:46:19 -04:00
Sota e9b2028b32
Show a soft error when a text string or number is supplied as a child to non text wrappers (#21953)
* Show soft errors when a text string or number is supplied as a child instead of throwing an error

* bring __DEV__ check first so that things inside get removed in prod.

* fix lint
2021-08-10 13:14:11 -07:00
Byron Luk da627ded86
Devtools/function context change (#22047) 2021-08-10 14:16:54 -04:00
Brian Vaughn 5634ed16aa
Scheduling Profiler: Misc UX and performance improvements (#22043) 2021-08-09 17:11:33 -04:00
Brian Vaughn ecd73e17bc
Enable enableSuspenseLayoutEffectSemantics flag statically for Facebook (#22050) 2021-08-09 15:45:12 -04:00
Konstantin Popov 64931821a9
Fix typo in parseHookNames.js (#22042)
representated -> represented
2021-08-08 15:58:50 -04:00
Brian Vaughn 2edf449803 Scheduling Profiler: Renamed a misnamed variable 2021-08-06 15:03:35 -04:00
Brian Vaughn 5660c52b89
Scheduling Profiler: Improve warnings and add unit tests (#22038)
* Scheduling Profiler: Updated instructions to mentioned v18+ requirement

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Updated nested update warning text

* Udpate warning about suspending outside of a transition

Handle edge case where component suspends before the first commit (and label metadata) has been logged.

Add unit tests.

* Fixed logic error in getBatchRange() with minStartTime

* PR feedback: Combined a conditional statement
2021-08-06 14:57:52 -04:00
Juan b9934d6db5
[DevTools] Hook names are correctly extracted when parsing nested hook calls (#22037)
## Summary

This commit fixes an issue where DevTools would currently not correctly extract the hook names for a hook call when the hook call was nested under *another* hook call, e.g.:

```javascript
function Component() {
  const InnerComponent = useMemo(() => () => {
    const [state, setState] = useState(0);

    return state;
  }); 
  return null;
};
```

Although it seems pretty rare to encounter this case in actual product code, DevTools wasn't handling it correctly:

**Expected Names:**
- `InnerComponent` for the `useMemo()` call.
- `state` for the `useState()` call.

**Actual**
- `InnerComponent` for the `useMemo()` call.
- `InnerComponent` for the `useState()` call.

The reason that we were extracting the name for the nested hook call incorrectly is that the `checkNodeLocation` function (which attempts to check if the location of the hook matches the location in the original source code), was too "lenient" and would return a match even if the start lines of the locations didn't match.

Specifically, for our example, it would consider that the location of the outer hook call "matched" the location of the inner hook call (even though they were on different lines), and would then return the wrong hook name.


### Fix

The fix in this commit is to update the `checkNodeLocation` function to more strictly check for matching start lines. The assumption here is that if 2 locations are on different starting lines, they can't possibly correspond to the same hook call.

## Test Plan

- yarn flow
- Tests still pass
  - yarn test
  - yarn test-build-devtools
- new regression tests added
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally). 
![image](https://user-images.githubusercontent.com/1271509/128409571-d62e0a74-6b7b-4c3f-ad86-6799ecd71962.png)

![image](https://user-images.githubusercontent.com/1271509/128409943-f898f27b-67ab-4260-a931-40d9c1942395.png)

![image](https://user-images.githubusercontent.com/1271509/128410326-79a0f822-55b1-4b90-a9b9-78f13fa0b5c5.png)
2021-08-05 16:36:59 -04:00
Brian Vaughn a8725a3e62
Scheduling profiler: Added lane labels and durations to React measures (#22029) 2021-08-05 13:50:39 -04:00
Andrew Clark 19092ac8c3
Re-add old Fabric Offscreen impl behind flag (#22018)
* Re-add old Fabric Offscreen impl behind flag

There's a chance that #21960 will affect layout in a way that we don't
expect, so I'm adding back the old implementation so we can toggle the
feature with a flag.

The flag should read from the ReactNativeFeatureFlags shim so that we
can change it at runtime. I'll do that separately.

* Import dynamic RN flags from external module

Internal feature flags that we wish to control with a GK can now be
imported from an external module, which I've called
"ReactNativeInternalFeatureFlags".

We'll need to add this module to the downstream repo.

We can't yet use this in our tests, because we don't have a test
configuration that runs against the React Native feature flags fork. We
should set up that up the same way we did for www.
2021-08-03 19:30:20 -07:00
Andrew Clark 215db465a2
[Fabric] Add `flex: 1` to Offscreen view container (#22019)
Without this style property, the layout of the children is messed up.

The goal is for the container view to have no layout at all. It should
be a completely transparent wrapper, except for when we set `display:
none` to hide its contents. On the web, the equivalent (at least in the
spec) is `display: contents`.

After some initial testing, this seems to be close enough to the desired
behavior that we can ship it. We'll try rolling it out behind a flag.
2021-08-03 19:26:49 -07:00
Sinan Sonmez (Chaush) 8a37b0ef3f
typos fixed (#21955) 2021-08-03 14:05:20 -04:00
Brian Vaughn e3049bb850
DevTools scheduling profiler: Add React component measures (#22013) 2021-08-03 13:03:29 -04:00
Vyacheslav 'SLEL' Solomin b54f36f2b6
[DevTools] Fix: highlight updates with memoized components (#22008) 2021-08-03 11:50:00 -04:00
Kevin Chavez 3a1dc3ec85
Switch on enableProfilerChangedHookIndices flag for OSS devtools builds (#22011) 2021-08-03 08:55:15 -04:00
Brian Vaughn 42251331d8
DevTools: Scheduling profiler (#22006) 2021-08-02 14:30:43 -04:00
houssemchebeb e3b76a85c5
Devtools: Refactor imperative theme code (#21950)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-08-02 11:20:04 -04:00
Ryota Murakami d3f8747c8d
[DevTools] Disable sizeBot on DevTools Rull Request (#21885)
* [DevTools] Disable sizeBot on DevTools Rull Request

Because DevTools code doesn't affect production bundle size.
Meaningless sizeBot comment give us frastration within Pull Request discussion.

* Revert "[DevTools] Disable sizeBot on DevTools Rull Request"

This reverts commit a43aab9207.

* check whether devtools package file only committed
2021-08-02 09:51:53 -04:00
Brian Vaughn d1a58da55d Optimized DevTools extension images 2021-08-02 09:32:46 -04:00
Ilham Syahid S dfd9d62636
[DevTools] Optimize Images yarn command (part 2) (#21968) 2021-08-02 09:32:17 -04:00
Brian Vaughn 27bf6f9a83
Scheduling profiler UX changes (#21990) 2021-08-02 09:23:48 -04:00
Juan b537247678
New devtools test for named hooks verifying case when hooks are used indirectly (#21996)
## Summary
Adds a new unit test to `parseHookNames-test` which verifies that we correctly give names to hooks when they are used indirectly: 

e.g.
```
  const countState = useState(0);
  const count = countState[0];
  const setCount = countState[1];
``` 

Should produce `count` as the name.

## Test plan

```
yarn test
yarn test-build-devtools
yarn test-build-devtools parseHookNames
```
2021-07-30 17:10:46 -04:00
Andrew Clark f0d354efc6
[Fabric] Fix reparenting bug in legacy Suspense mount (#21995)
* Add reparenting invariant to React Noop

Fabric does not allow nodes to be reparented, so I added the equivalent
invariant to React Noop's so we can catch regressions.

This causes some tests to fail, which I'll fix in the next step.

* Fix: Use getOffscreenContainerProps

The type of these props is different per renderer. An oversight
from #21960. Unfortunately wasn't caught by Flow because fiber props
are `any`-typed.

* [Fabric] Fix reparenting in legacy Suspense mount

Fixes a weird case during legacy Suspense mount where the offscreen host
container of a tree that suspends during initial mount is recreated
instead of cloned, since there's no current fiber to clone from.

Fabric considers this a reparent even though the parent from the first
pass never committed.

Instead we can override the props from the first pass before the
container completes. It's a bit of a hack, but no more so than the rest
of the legacy root Suspense implementation — the hacks are designed
to make it usable by non-strict mode-compliant trees.
2021-07-30 12:47:40 -07:00
Shubham Pandey 6f3fcbd6fa
Some remaining instances of master to main (#21982)
Co-authored-by: Shubham Pandey <shubham.pandey@mfine.co>
2021-07-30 08:56:55 -04:00
Andrew Clark 34308b5ada
Tidy up early bailout logic at start of begin phase (#21852)
* Extract early bailout to separate function

This block is getting hard to read so I moved it to a separate function.
I'm about to refactor the logic that wraps around this path.

Ideally this early bailout path would happen before the begin phase
phase. Perhaps during reconcilation of the parent fiber's children.

* Extract state and context check to separate function

The only reason we pass `updateLanes` to some begin functions is to
check if we can perform an early bail out. But this is also available
as `current.lanes`, so we can read it from there instead.

I think the only reason we didn't do it this way originally is because
components that have two phases — error and Suspense boundaries —
use `workInProgress.lanes` to prevent a bail out, since during the
initial render there is no `current`. But we can check the `DidCapture`
flag instead, which we use elsewhere to detect the second phase.
2021-07-29 06:59:59 -07:00
Brian Vaughn d9dd96530f
Added testing instructions to devtools contributing guide 2021-07-28 19:05:01 -04:00
Piotr Szulc 9f88b5355b
Devtools: Display as link if value is in specified protocols (#21964) 2021-07-28 09:29:13 -04:00
Sebastian Markbåge 321087d134
[Fizz] Don't add aborted segments to the completedSegments list (#21976)
* Don't add aborted segments to the completedSegments list

* Update error message to include aborted status
2021-07-27 21:53:37 -04:00
Brian Vaughn cdccdbe171
Display warnings in tooltips for native events that render sync updates (#21975) 2021-07-27 17:22:44 -04:00
Brian Vaughn d95434082f
Scheduling profiler: UX tweaks (#21971) 2021-07-27 14:34:05 -04:00
Brian Vaughn 87239321b0
Sceduling profiler: Added custom view cursors (#21970) 2021-07-27 12:23:01 -04:00
Timothy Yung 4cc8ec64c2
Separate unit tests for ReactFabricHostComponent (#21969) 2021-07-26 23:45:26 -07:00
Timothy Yung d4d7864934
Fix `ReactFabricHostComponent` methods if detached (#21967) 2021-07-26 21:02:06 -07:00
Brian Vaughn c21e8fccad
Scheduling profiler: Improve native events UI (#21966)
Also highlight events that have synchronous updates inside of them. (We may want to relax this highlighting later to not warn about event handlers that are still fast enough.)
2021-07-26 19:30:43 -04:00