Commit Graph

14417 Commits

Author SHA1 Message Date
Andrew Clark 34600f4fad
Refactor "reappear" logic into its own traversal (#21898)
When a Suspense boundary switches to its fallback state — or similarly,
when an Offscreen boundary switches from visible to hidden — we unmount
all its layout effects. When it resolves — or when Offscreen switches
back to visible — we mount them again. This "reappearing" logic
currently happens in the same commit phase traversal where we perform
normal layout effects.

I've changed it so that the "reappear" logic happens in its own
recurisve traversal that is separate from the commit phase one.

In the next step, I will do the same for the "disappear" logic that
currently lives in the `hideOrUnhideAllChildren` function.

There are a few reasons to model it this way, related to future
Offscreen features that we have planned. For example, we intend to
provide an imperative API to "appear" and "reappear" all the effects
within an Offscreen boundary. This API would be called from outside the
commit phase, during an arbitrary event. Which means it can't rely on
the regular commit phase — it's not part of a commit. This isn't the
only motivation but it illustrates why the separation makes sense.
2021-07-16 15:05:39 -07:00
Ricky 310187264d
Clean up flushSync flow types (#21887) 2021-07-16 10:37:57 -04:00
Brian Vaughn d0ec283819 DevTools 4.13.5 -> 4.14.0 2021-07-16 00:25:01 -04:00
Brian Vaughn 6840c98c32
Remove named hooks feature flag (#21894) 2021-07-16 00:14:20 -04:00
Brian Vaughn e26cb8f86d
Clear named hooks Suspense and AST cache after a Fast Refresh (#21891) 2021-07-15 23:39:30 -04:00
Ricky 682bbd0e72
Cache local reference to global Promise (#21886) 2021-07-15 12:39:56 -04:00
houssemchebeb d5de45820a
Fix typo (#21671) 2021-07-14 20:42:54 -04:00
Steve Rubin 232c67e911
Devtools Profiler: allow user to enter commit number (#19957)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-14 20:37:02 -04:00
Brian Vaughn 87b3ada89d
DevTools: Named hooks supports "cheap-module-source-map" (#21874)
"cheap-module-source-map" is the default source-map generation mode used in created-react-dev mode because of speed. The major trade-off is that the source maps generated don't contain column numbers, so DevTools needs to be more lenient when matching AST nodes in this mode.

In this case, it can ignore column numbers and match nodes using line numbers only– so long as only a single node matches. If more than one match is found, treat it the same as if none were found, and fall back to no name.
2021-07-14 14:37:27 -04:00
Andrew Clark a97b5ac078
[Bugfix] Don't hide/unhide unless visibility changes (#21875)
* Use Visibility flag to schedule a hide/show effect

Instead of the Update flag, which is also used for other side-effects,
like refs.

I originally added the Visibility flag for this purpose in #20043 but
it got reverted last winter when we were bisecting the effects refactor.

* Added failing test case

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-14 10:37:10 -07:00
Andrew Clark f0efb7b70f
Add comment support to `@gate` pragma (#21881)
So you can more easily comment on why a test is gated.
2021-07-14 10:36:24 -07:00
Andrew Clark 81346764bb
Run persistent tests in more configurations in CI (#21880)
I noticed that `enableSuspenseLayoutEffectSemantics` is not fully
implemented in persistent mode. I believe this was an oversight
because we don't have a CI job that runs tests in persistent mode and
with experimental flags enabled.

This adds additional test configurations to the CI job so we don't miss
stuff like this again. It doesn't fix the failing tests — I'll address
that separately.
2021-07-14 08:40:20 -07:00
Sebastian Silbermann 9090257e6e
fix: restore execution context after RetryAfterError completed (#21766)
* test: Add failing test due to executionContext not being restored

* fix: restore execution context after RetryAfterError completed

* Poke codesandbox/ci

* Completely restore executionContext

* expect a specific error
2021-07-13 22:38:25 +01:00
Brian Vaughn 9fec3f2add
DevTools: Ignore multiple sourceMappingUrls for external source maps (#21871)
Added an edge case regression test and bugfix.
2021-07-13 16:39:29 -04:00
Ricky 14bac6193a
Allow components to render undefined (#21869) 2021-07-13 15:48:11 -04:00
Brian Vaughn 87b67d319f
Enable scheduling profiler flag for react-dom profiling builds (#21867) 2021-07-13 13:41:19 -04:00
Brian Vaughn 64bbd7a7f1
Adjust Error stack columns numbers by 1 (#21865)
To account for differences between error stacks (1-based) and ASTs (0-based). In practice this change should not make an observable difference.
2021-07-13 13:28:01 -04:00
Ehsan Hosseini 464f275724
Update link to flow (#21862)
`main` branch does not exist in the `flow` project and it is `master`.

Co-authored-by: Ehsan Hosseini <53467610+dh-hosseini@users.noreply.github.com>
2021-07-13 10:55:54 -04:00
Ehsan Hosseini b03293faaa
Fix link to fbjs (#21863)
`fbjs` doesn't have the `main` branch and it is `master`
2021-07-13 10:55:33 -04:00
Dan Abramov 9f5224a9c6
Restore DevTools console message (#21864) 2021-07-13 15:41:51 +01:00
Andrew Clark a4ecd85e86
act: Batch updates, even in legacy roots (#21797)
In legacy roots, if an update originates outside of `batchedUpdates`,
check if it's inside an `act` scope; if so, treat it as if it were
batched. This is only necessary in legacy roots because in concurrent
roots, updates are batched by default.

With this change, the Test Utils and Test Renderer versions of `act` are
nothing more than aliases of the isomorphic API (still not exposed, but
will likely be the recommended API that replaces the others).
2021-07-12 17:15:20 -07:00
Ricky c2c6ea1fde
Capture suspense boundaries with undefined fallbacks (#21854) 2021-07-12 14:50:33 -04:00
Andrew Clark bfa50f8272
Inline discreteUpdates (#21784)
This API is only used by the event system, to set the event priority for
the scope of a function. We don't need it anymore because we can modify
the priority directly, like we already do for continuous input events.
2021-07-12 07:55:09 -07:00
Andrew Clark 0f09f14ae6 Check if already rendering before flushing
Forgot to stage this before committing 54e88ed12

I don't think is currently observable but should include the guard to
protect against regressions (though this whole block will be deleted
along with legacy mode, anyway).
2021-07-10 18:02:00 -04:00
Andrew Clark 54e88ed12c
Bugfix: Flush legacy sync passive effects at beginning of event (#21846)
* Re-land recent flushSync changes

Adds back #21776 and #21775, which were removed due to an internal
e2e test failure.

Will attempt to fix in subsequent commits.

* Failing test: Legacy mode sync passive effects

In concurrent roots, if a render is synchronous, we flush its passive
effects synchronously. In legacy roots, we don't do this because all
updates are synchronous — so we need to flush at the beginning of the
next event. This is how `discreteUpdates` worked.

* Flush legacy passive effects at beginning of event

Fixes test added in previous commit.
2021-07-10 11:15:11 -07:00
Andrew Clark cb8afda183
Add test for #21837 (#21842)
Taken from https://github.com/facebook/react/pull/21837#issuecomment-876788973

Co-Authored-By: Timothy Yung <yungsters@fb.com>

Co-authored-by: Timothy Yung <yungsters@fb.com>
2021-07-08 20:01:29 -07:00
Andrew Clark f85f429d55
Use `act()` in ReactFabric tests (#21839) (#21841)
Co-authored-by: Timothy Yung <yungsters@fb.com>
2021-07-08 19:35:46 -07:00
Timothy Yung 84639ab53f
Guard against reused fibers in React Native commands (#21837) 2021-07-08 16:01:51 -07:00
Timothy Yung c549bc4918
Revert "Use `act()` in ReactFabric tests (#21839)" (#21840)
This reverts commit 59d3aca686.
2021-07-08 15:05:51 -07:00
Timothy Yung 59d3aca686
Use `act()` in ReactFabric tests (#21839) 2021-07-08 15:02:02 -07:00
Brian Vaughn 25984e5231
Update CONTRIBUTING.md 2021-07-08 17:38:59 -04:00
Brian Vaughn 32d88d4332
DevTools: Don't load source files contaning only unnamed hooks (#21835)
This wastes CPU cycles.
2021-07-08 16:46:17 -04:00
Brian Vaughn f52b73f9d0
DevTools: Update named hooks match to use column number also (#21833)
This prevents edge cases where AST nodes are incorrectly matched.
2021-07-08 16:12:22 -04:00
Brian Vaughn 92af60afb2
Update CONTRIBUTING.md 2021-07-08 14:37:13 -04:00
Brian Vaughn 27423de395
Update CONTRIBUTING.md 2021-07-08 14:28:53 -04:00
Brian Vaughn 8148fe5ff4 Added DevTools CONTRIBUTING guide 2021-07-08 14:11:30 -04:00
Brian Vaughn 92f3414d03
Reset inspected element cache in the event of an error (#21821) 2021-07-08 14:07:15 -04:00
Brian Vaughn feb2f6892a
DevTool: hook names cache no longer loses entries between selection (#21831)
Made several changes to the hooks name cache to avoid losing cached data between selected elements:
1. No longer use React-managed cache. This had the unfortunate side effect of the inspected element cache also clearing the hook names cache. For now, instead, a module-level WeakMap cache is used. This isn't great but we can revisit it later.
2. Hooks are no longer the cache keys (since hook objects get recreated between element inspections). Instead a hook key string made of fileName + line number + column number is used.
3. If hook names have already been loaded for a component, skip showing the load button and just show the hook names by default when selecting the component.
2021-07-08 13:54:16 -04:00
Shannon Feng 241485a2c4
[SSR2 Fixture] Delete duplicate DOCTYPE (#21824) 2021-07-08 03:11:42 +01:00
Brian Vaughn 8b34d5a905
DevTools show error icon when hook name parsing fails (#21820) 2021-07-07 16:27:39 -04:00
Brian Vaughn 9ccc25a0ea
Reverting recent flushSync changes (#21816) 2021-07-07 15:07:55 -04:00
Brian Vaughn b6258b05f4
DevTools named hooks: Support FLow syntax (#21815)
Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)
2021-07-07 14:29:41 -04:00
Brian Vaughn 42b3c89c57
DevTooks: Don't dehydrate hook source fileNames (#21814) 2021-07-07 14:24:17 -04:00
Moti Zilberman 9c7f29ebe7
[WIP] DevTools: Support named hooks for >1 module in a bundle (#21790)
* Add named hooks test case built with Rollup

* Fix prepareStackTrace unpatching, remove sourceURL

* Prettier

* Resolve source map URL/path relative to the script

* Add failing tests for multi-module bundle

* Parse hook names from multiple modules in a bundle

* Create a HookSourceData per location key (file, line, column).
* Cache the source map per runtime URL ( = file part of location key).
* Don't store sourceMapContents - only store a consumer instance.
* Look up original source URLs in the source map correctly.
* Cache the code + AST per original URL.
* Fix off-by-one column number lookup.
* Some naming and typing tweaks related to the above.
* Stop storing the consumer outside the with() callback, which is a bug.

* Lint fix for 8d8dd25

* Added devDependencies to react-devtools-extensions package.json

* Added some debug logging and TODO comments

* Added additional DEBUG logging to hook names cache

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-07 13:07:58 -04:00
Andrew Clark ed6c091fe9
Replace unbatchedUpdates with flushSync (#21776)
There's a weird quirk leftover from the old Stack (pre-Fiber)
implementation where the initial mount of a leagcy (ReactDOM.render)
root is flushed synchronously even inside `batchedUpdates`.

The original workaround for this was an internal method called
`unbatchedUpdates`. We've since added another API that works almost the
same way, `flushSync`.

The only difference is that `unbatchedUpdates` would not cause other
pending updates to flush too, only the newly mounted root. `flushSync`
flushes all pending sync work across all roots. This was to preserve
the exact behavior of the Stack implementation.

But since it's close enough, let's just use `flushSync`. It's unlikely
anyone's app accidentally relies on this subtle difference, and the
legacy API is deprecated in 18, anyway.
2021-07-01 15:14:07 -07:00
Andrew Clark 32eefcb3c5
Replace flushDiscreteUpdates with flushSync (#21775)
* Replace flushDiscreteUpdates with flushSync

flushDiscreteUpdates is almost the same as flushSync. It forces passive
effects to fire, because of an outdated heuristic, which isn't ideal but
not that important.

Besides that, the only remaining difference between flushDiscreteUpdates
and flushSync is that flushDiscreteUpdates does not warn if you call it
from inside an effect/lifecycle. This is because it might get triggered
by a nested event dispatch, like `el.focus()`.

So I added a new method, flushSyncWithWarningIfAlreadyRendering, which
is used for the public flushSync API. It includes the warning. And I
removed the warning from flushSync, so the event system can call that
one. In production, flushSyncWithWarningIfAlreadyRendering gets inlined
to flushSync, so the behavior is identical.

Another way of thinking about this PR is that I renamed flushSync to
flushSyncWithWarningIfAlreadyRendering and flushDiscreteUpdates to
flushSync (and fixed the passive effects thing). The point is to prevent
these from subtly diverging in the future.

* Invert so the one with the warning is the default one

To make Seb happy
2021-07-01 15:13:00 -07:00
Brian Vaughn c5cfa71948
DevTools: Show hook names based on variable usage (#21641)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
Co-authored-by: Saphal Patro <saphal1998@gmail.com>
Co-authored-by: VibhorCodecianGupta <vibhordelgupta@gmail.com>
2021-07-01 14:39:18 -04:00
Brian Vaughn ab390c65ee
ReactDebugHooks optionally includes fileName, and line/column numbers (#21781) 2021-07-01 13:08:46 -04:00
Brian Vaughn 6bf111772a
Install nested packages from Yarn cache before running build tests (#21779) 2021-07-01 11:37:56 -04:00
Andrew Clark c96761c7b2
Delete batchedEventUpdates (#21774)
No longer used anywhere.
2021-06-30 15:09:14 -07:00