Commit Graph

104 Commits

Author SHA1 Message Date
E-Liang Tan 40cddfeeb1
Add user timing marks for scheduling profiler tool (#19223)
High level breakdown of this commit:

* Add a enableSchedulingProfiling feature flag.
* Add functions that call User Timing APIs to a new SchedulingProfiler file. The file follows DebugTracing's structure.
* Add user timing marks to places where DebugTracing logs.
* Add user timing marks to most other places where @bvaughn's original draft DebugTracing branch marks.
* Tests added
* More context (and discussions with @bvaughn) available at our internal PR MLH-Fellowship#11 and issue MLH-Fellowship#5.

Similar to DebugTracing, we've only added scheduling profiling calls to the old reconciler fork.

Co-authored-by: Kartik Choudhary <kartik.c918@gmail.com>
Co-authored-by: Kartik Choudhary <kartikc.918@gmail.com>
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-07-08 10:36:02 -04:00
Ricky 91a2e8173f
Decouple update priority tracking from Scheduler package (#19121)
* Initial currentLanePriority implementation

* Minor updates from review

* Fix typos and enable flag

* Fix feature flags and lint

* Fix simple event tests by switching to withSuspenseConfig

* Don't lower the priority of setPending in startTransition below InputContinuous

* Move currentUpdateLanePriority in commit root into the first effect block

* Refactor requestUpdateLane to log for priority mismatches

Also verifies that the update lane priority matches the scheduler lane priority before using it

* Fix four tests by adding ReactDOM.unstable_runWithPriority

* Fix partial hydration when using update lane priority

* Fix partial hydration when using update lane priority

* Rename feature flag and only log for now

* Move unstable_runWithPriority to ReactFiberReconciler

* Add unstable_runWithPriority to ReactNoopPersistent too

* Bug fixes and performance improvements

* Initial currentLanePriority implementation

* Minor updates from review

* Fix typos and enable flag

* Remove higherLanePriority from ReactDOMEventReplaying.js

* Change warning implementation and startTransition update lane priority

* Inject reconciler functions to avoid importing src/

* Fix feature flags and lint

* Fix simple event tests by switching to withSuspenseConfig

* Don't lower the priority of setPending in startTransition below InputContinuous

* Move currentUpdateLanePriority in commit root into the first effect block

* Refactor requestUpdateLane to log for priority mismatches

Also verifies that the update lane priority matches the scheduler lane priority before using it

* Fix four tests by adding ReactDOM.unstable_runWithPriority

* Fix partial hydration when using update lane priority

* Fix partial hydration when using update lane priority

* Rename feature flag and only log for now

* Move unstable_runWithPriority to ReactFiberReconciler

* Bug fixes and performance improvements

* Remove higherLanePriority from ReactDOMEventReplaying.js

* Change warning implementation and startTransition update lane priority

* Inject reconciler functions to avoid importing src/

* Fixes from bad rebase
2020-07-06 18:53:42 -04:00
Dan Abramov 9fba65efa5
Enable modern event system and delete dead code (#19230) 2020-07-01 17:43:34 +01:00
Sebastian Markbåge 7f28234f84
Enable component stacks everywhere except RN (#19120)
This would still affect test renderer and isomorphic in RN.
2020-06-11 19:13:13 -07:00
Sebastian Markbåge 518ce9c25f
Add Lazy Elements Behind a Flag (#19033)
We really needed this for Flight before as well but we got away with it
because Blocks were lazy but with the removal of Blocks, we'll need this
to ensure that we can lazily stream in part of the content.

Luckily LazyComponent isn't really just a Component. It's just a generic
type that can resolve into anything kind of like a Promise.

So we can use that to resolve elements just like we can components.

This allows keys and props to become lazy as well.

To accomplish this, we suspend during reconciliation. This causes us to
not be able to render siblings because we don't know if the keys will
reconcile. For initial render we could probably special case this and
just render a lazy component fiber.

Throwing in reconciliation didn't work correctly with direct nested
siblings of a Suspense boundary before but it does now so it depends
on new reconciler.
2020-05-28 14:16:35 -07:00
Brian Vaughn 86b4070ddb
Cleaned up passive effects experimental flags (#19021) 2020-05-28 08:32:37 -07:00
Andrew Clark 64f50c667a
Remove disableHiddenPropDeprioritization flag (#18964)
This is rolled out to 100% public, so we can remove it.
2020-05-20 15:29:34 -07:00
Andrew Clark b4a1a4980c
Disable <div hidden /> API in old fork, too (#18917)
The motivation for doing this is to make it impossible for additional
uses of pre-rendering to sneak into www without going through the
LegacyHidden abstraction. Since this feature was already disabled in
the new fork, this brings the two closer to parity.

The LegacyHidden abstraction itself still needs to opt into
pre-rendering somehow, so rather than totally disabling the feature, I
updated the `hidden` prop check to be obnoxiously specific. Before, you
could set it to any truthy value; now, you must set it to the string
"unstable-do-not-use-legacy-hidden".

The node will still be hidden in the DOM, since any truthy value will
cause the browser to apply a style of `display: none`.

I will have to update the LegacyHidden component in www to use the
obnoxious string prop. This doesn't block merge, though, since the
behavior is gated by a dynamic flag. I will update the component before
I enable the flag.
2020-05-13 20:01:10 -07:00
Dominic Gannaway 80c4dea0d1
Modern Event System: Add scaffolding for createEventHandle (#18898) 2020-05-12 19:01:12 +01:00
Andrew Clark 8b9c4d1688
Expose LegacyHidden type and disable <div hidden /> API in new fork (#18891)
* Expose LegacyHidden type

I will use this internally at Facebook to migrate away from
<div hidden />. The end goal is to migrate to the Offscreen type, but
that has different semantics. This is an incremental step.

* Disable <div hidden /> API in new fork

Migrates to the unstable_LegacyHidden type instead. The old fork does
not support the new component type, so I updated the tests to use an
indirection that picks the correct API. I will remove this once the
LegacyHidden (and/or Offscreen) type has landed in both implementations.

* Add gated warning for `<div hidden />` API

Only exists so we can detect callers in www and migrate them to the new
API. Should not visible to anyone outside React Core team.
2020-05-11 20:02:08 -07:00
Andrew Clark 47ebc90b08
Put render phase update change behind a flag (#18850)
In the new reconciler, I made a change to how render phase updates
work. (By render phase updates, I mean when a component updates
another component during its render phase. Or when a class component
updates itself during the render phase. It does not include when
a hook updates its own component during the render phase. Those have
their own semantics. So really I mean anything triggers the "`setState`
in render" warning.)

The old behavior is to give the update the same "thread" (expiration
time) as whatever is currently rendering. So if you call `setState` on a
component that happens later in the same render, it will flush during
that render. Ideally, we want to remove the special case and treat them
as if they came from an interleaved event.

Regardless, this pattern is not officially supported. This behavior is
only a fallback. The flag only exists until we can roll out the
`setState` warnning, since existing code might accidentally rely on the
current behavior.
2020-05-06 19:19:14 -07:00
Dan Abramov 3e13d70984
[RN] Remove debugging invariant (#18813) 2020-05-04 15:48:35 +01:00
Dominic Gannaway ff431b7fc4
Remove ReactDOM.useEvent and associated types+tests (#18689) 2020-04-21 16:40:44 +01:00
Dan Abramov 0301f3e24f
Statically disable factory components for WWW (#18641) 2020-04-16 19:42:30 +01:00
Brian Vaughn 22dc2e42bd
Add experimental DebugTracing logger for internal use (#18531) 2020-04-15 19:10:15 -07:00
Andrew Clark b928fc030a
Delete flushSuspenseFallbacksInTests flag (#18596)
* Move renderer `act` to work loop

* Delete `flushSuspenseFallbacksInTests`

This was meant to be a temporary hack to unblock the `act` work, but it
quickly spread throughout our tests.

What it's meant to do is force fallbacks to flush inside `act` even in
Concurrent Mode. It does this by wrapping the `setTimeout` call in a
check to see if it's in an `act` context. If so, it skips the delay and
immediately commits the fallback.

Really this is only meant for our internal React tests that need to
incrementally render. Nobody outside our team (and Relay) needs to do
that, yet. Even if/when we do support that, it may or may not be with
the same `flushAndYield` pattern we use internally.

However, even for our internal purposes, the behavior isn't right
because a really common reason we flush work incrementally is to make
assertions on the "suspended" state, before the fallback has committed.
There's no way to do that from inside `act` with the behavior of this
flag, because it causes the fallback to immediately commit. This has led
us to *not* use `act` in a lot of our tests, or to write code that
doesn't match what would actually happen in a real environment.

What we really want is for the fallbacks to be flushed at the *end` of
the `act` scope. Not within it.

This only affects the noop and test renderer versions of `act`, which
are implemented inside the reconciler. Whereas `ReactTestUtils.act` is
implemented in "userspace" for backwards compatibility. This is fine
because we didn't have any DOM Suspense tests that relied on this flag;
they all use test renderer or noop.

In the future, we'll probably want to move always use the reconciler
implementation of `act`. It will not affect the prod bundle, because we
currently only plan to support `act` in dev. Though we still haven't
completely figured that out. However, regardless of whether we support a
production `act` for users, we'll still need to write internal React
tests in production mode. For that use case, we'll likely add our own
internal version of `act` that assumes a mock Scheduler and might rely
on hacks that don't 100% align up with the public one.
2020-04-13 20:02:18 -07:00
Brian Vaughn dc49ea108c
Filter certain DOM attributes (e.g. src) if value is empty string (#18513)
* Filter certain DOM attributes (e.g. src, href) if their values are empty strings

This prevents e.g. <img src=""> from making an unnecessar HTTP request for certain browsers.

* Expanded warning recommendation

* Improved error message

* Further refined error message
2020-04-07 09:52:36 -07:00
Sebastian Markbåge 4169420198
Refactor Component Stack Traces (#18495)
* Add feature flag

* Split stack from current fiber

You can get stack from any fiber, not just current.

* Refactor description of component frames

These should use fiber tags for switching. This also puts the relevant code
behind DEV flags.

* We no longer expose StrictMode in component stacks

They're not super useful and will go away later anyway.

* Update tests

Context is no longer part of SSR stacks. This was already the case on the
client.

forwardRef no longer is wrapped on the stack. It's still in getComponentName
but it's probably just noise in stacks. Eventually we'll remove the wrapper
so it'll go away anyway. If we use native stack frames they won't have this
extra wrapper.

It also doesn't pick up displayName from the outer wrapper. We could maybe
transfer it but this will also be fixed by removing the wrapper.

* Forward displayName onto the inner function for forwardRef and memo in DEV

This allows them to show up in stack traces.

I'm not doing this for lazy because lazy is supposed to be called on the
consuming side so you shouldn't assign it a name on that end. Especially
not one that mutates the inner.

* Use multiple instances of the fake component

We mutate the inner component for its name so we need multiple copies.
2020-04-06 15:43:39 -07:00
Brian Vaughn 4123d729e5
Revert "Revert: Enable new passive effect behavior for FB builds (#18467)" (#18468)
This reverts commit 3966081cf2.
2020-04-02 15:24:36 -07:00
Dominic Gannaway 3966081cf2
Revert: Enable new passive effect behavior for FB builds (#18467) 2020-04-02 16:25:35 +01:00
Dan Abramov 31734540dc
Remove a flag for style collision warning (#18462) 2020-04-02 11:55:17 +01:00
Dominic Gannaway dc3c6c9565
ReactDOM.useEvent: revert and add guard for null stateNode (#18441) 2020-04-01 12:45:26 +01:00
Brian Vaughn 4de3a60325
Remove disableMapsAsChildren flag (#18445)
Change warning to say the case is unsupported (not "will be deprecated")
2020-03-31 11:00:51 -07:00
Brian Vaughn f4cc970276
Enable new passive effect behavior for FB builds (#18444)
* Enable new passive effect behavior for FB builds

Previously this behavior was controlled by GKs. This PR updates the flags to be enabled statically. It also enables the flags in the test builds.
2020-03-31 10:05:15 -07:00
Andrew Clark 90e90ac8e0
Revert useEvent PRs (#18438)
* Revert "ReactDOM.useEvent: enable on internal www and add inspection test (#18395)"

This reverts commit e0ab1a429d.

* Revert "ReactDOM.useEvent: Add support for experimental scopes API (#18375)"

This reverts commit a16b349745.

* ReactDOM.useEvent: Add support for experimental scopes API
2020-03-30 19:16:28 -07:00
Dan Abramov bf30e370a5
Remove User Timings (#18417) 2020-03-31 00:29:53 +01:00
Dominic Gannaway e0ab1a429d
ReactDOM.useEvent: enable on internal www and add inspection test (#18395) 2020-03-26 17:13:05 +00:00
Dominic Gannaway 8311cb5d24
Modern Event System: refactor legacy FB support logic (#18336) 2020-03-19 13:22:36 +00:00
Andrew Clark cd48a06547
Set up infra for react-reconciler fork (#18285)
* ReactFiberReconciler -> ReactFiberReconciler.old

* Set up infra for react-reconciler fork

We're planning to land some significant refactors of the reconciler.
We want to be able to gradually roll out the new implementation side-by-
side with the existing one. So we'll create a short lived fork of the
react-reconciler package. Once the new implementation has stabilized,
we'll delete the old implementation and promote the new one.

This means, for as long as the fork exists, we'll need to maintain two
separate implementations. This sounds painful, but since the forks will
still be largely the same, most changes will not require two separate
implementations. In practice, you'll implement the change in the old
fork and then copy paste it to the new one.

This commit only sets up the build and testing infrastructure. It does
not actually fork any modules. I'll do that in subsequent PRs.

The forked version of the reconciler will be used to build a special
version of React DOM. I've called this build ReactDOMForked. It's only
built for www; there's no open source version.

The new reconciler is disabled by default. It's enabled in the
`yarn test-www-variant` command. The reconciler fork isn't really
related to the "variant" feature of the www builds, but I'm piggy
backing on that concept to avoid having to add yet another
testing dimension.
2020-03-12 11:38:32 -07:00
Dominic Gannaway 29534252ad
ReactDOM.useEvent add flag and entry point (#18267) 2020-03-10 12:18:49 +00:00
Dan Abramov 562cf013db
Add a flag to disable module pattern components (#18133) 2020-03-06 18:46:32 +00:00
Brian Vaughn 024a764310
Implemented Profiler onCommit() and onPostCommit() hooks (#17910)
* Implemented Profiler onCommit() and onPostCommit() hooks
* Added enableProfilerCommitHooks feature flag for commit hooks
* Moved onCommit and onPassiveCommit behind separate feature flag
2020-03-05 11:02:00 -08:00
Dominic Gannaway 503fd82b42
Modern Event System: Add support for internal FB Primer (#18210) 2020-03-04 23:41:59 +00:00
Eli White 26aa1987ce
[Native] Enable and remove targetAsInstance feature flag. (#18182) 2020-02-28 13:45:42 -08:00
Dan Abramov 4ee592e95a
Add an early invariant to debug a mystery crash (#18159) 2020-02-28 11:56:36 +00:00
Dan Abramov b4e3148918
Remove unused flag (#18132) 2020-02-27 12:58:15 +00:00
Sebastian Markbåge 60016c448b
Export React as Named Exports instead of CommonJS (#18106)
* Add options for forked entry points

We currently fork .fb.js entry points. This adds a few more options.

.modern.fb.js - experimental FB builds
.classic.fb.js - stable FB builds
.fb.js - if no other FB build, use this for FB builds
.experimental.js - experimental builds
.stable.js - stable builds
.js - used if no other override exists

This will be used to have different ES exports for different builds.

* Switch React to named exports

* Export named exports from the export point itself

We need to re-export the Flow exported types so we can use them in our code.

We don't want to use the Flow types from upstream since it doesn't have the non-public APIs that we have.

This should be able to use export * but I don't know why it doesn't work.

This actually enables Flow typing of React which was just "any" before.
This exposed some Flow errors that needs fixing.

* Create forks for the react entrypoint

None of our builds expose all exports and they all differ in at least one
way, so we need four forks.

* Set esModule flag to false

We don't want to emit the esModule compatibility flag on our CommonJS
output. For now we treat our named exports as if they're CommonJS.

This is a potentially breaking change for scheduler (but all those apis
are unstable), react-is and use-subscription. However, it seems unlikely
that anyone would rely on this since these only have named exports.

* Remove unused Feature Flags

* Let jest observe the stable fork for stable tests

This lets it do the negative test by ensuring that the right tests fail.

However, this in turn will make other tests that are not behind
__EXPERIMENTAL__ fail. So I need to do that next.

* Put all tests that depend on exports behind __EXPERIMENTAL__

Since there's no way to override the exports using feature flags
in .intern.js anymore we can't use these APIs in stable.

The tradeoff here is that we can either enable the negative tests on
"stable" that means experimental are expected to fail, or we can disable
tests on stable. This is unfortunate since some of these APIs now run on
a "stable" config at FB instead of the experimental.

* Switch ReactDOM to named exports

Same strategy as React.

I moved the ReactDOMFB runtime injection to classic.fb.js

Since we only fork the entrypoint, the `/testing` entrypoint needs to
be forked too to re-export the same things plus `act`. This is a bit
unfortunate. If it becomes a pattern we can consider forking in the
module resolution deeply.

fix flow

* Fix ReactDOM Flow Types

Now that ReactDOM is Flow type checked we need to fix up its types.

* Configure jest to use stable entry for ReactDOM in non-experimental

* Remove additional FeatureFlags that are no longer needed

These are only flagging the exports and no implementation details so we
can control them fully through the export overrides.
2020-02-25 13:54:27 -08:00
Sebastian Markbåge 65bbda7f16
Rename Chunks API to Blocks (#18086)
Sounds like this is the name we're going with. This also helps us
distinguish it from other "chunking" implementation details.
2020-02-20 23:56:40 -08:00
Sunil Pai b789060dca
Feature Flag for React.jsx` "spreading a key to jsx" warning (#18074)
Adds a feature flag for when React.jsx warns you about spreading a key into jsx. It's false for all builds, except as a dynamic flag for fb/www.

I also included the component name in the warning.
2020-02-20 11:30:04 +00:00
Dominic Gannaway 4912ba31e3
Add modern event system flag + rename legacy plugin module (#18073) 2020-02-19 14:36:39 +00:00
Brian Vaughn 691096c95d
Split recent passive effects changes into 2 flags (#18030)
* Split recent passive effects changes into 2 flags

Separate flags can now be used to opt passive effects into:
1) Deferring destroy functions on unmount to subsequent passive effects flush
2) Running all destroy functions (for all fibers) before create functions

This allows us to test the less risky feature (2) separately from the more risky one.

* deferPassiveEffectCleanupDuringUnmount is ignored unless runAllPassiveEffectDestroysBeforeCreates is true
2020-02-18 14:19:43 -08:00
Dan Abramov 8777b44e98
Add Modern WWW build (#18028)
* Build both stable and experimental WWW builds

* Flip already experimental WWW flags to true

* Remove FB-specific internals from modern FB builds

We think we're not going to need these.

* Disable classic features in modern WWW builds

* Disable legacy ReactDOM API for modern WWW build

* Don’t include user timing in prod

* Fix bad copy paste and add missing flags to test renderer

* Add testing WWW feature flag file

We need it because WWW has a different meaning of experimental now.
2020-02-13 20:33:53 +00:00
Dominic Gannaway 256d78d11f
Add feature flag for removing children Map support (#17990) 2020-02-06 13:19:35 +00:00
Sunil Pai 3e9251d605
make testing builds for React/ReactDOM (#17915)
This PR introduces adds `react/testing` and `react-dom/testing`.
- changes infra to generate these builds
- exports act on ReactDOM in these testing builds
- uses the new test builds in fixtures/dom

In the next PR -

- I'll use the new builds for all our own tests
- I'll replace usages of TestUtils.act with ReactDOM.act.
2020-02-03 23:31:31 +00:00
Brian Vaughn 7df32c4c8c
Flush `useEffect` clean up functions in the passive effects phase (#17925)
* Flush useEffect clean up functions in the passive effects phase

This is a change in behavior that may cause broken product code, so it has been added behind a killswitch (deferPassiveEffectCleanupDuringUnmount)

* Avoid scheduling unnecessary callbacks for cleanup effects

Updated enqueuePendingPassiveEffectDestroyFn() to check rootDoesHavePassiveEffects before scheduling a new callback. This way we'll only schedule (at most) one.

* Updated newly added test for added clarity.

* Cleaned up hooks effect tags

We previously used separate Mount* and Unmount* tags to track hooks work for each phase (snapshot, mutation, layout, and passive). This was somewhat complicated to trace through and there were man tag types we never even used (e.g. UnmountLayout, MountMutation, UnmountSnapshot). In addition to this, it left passive and layout hooks looking the same after renders without changed dependencies, which meant we were unable to reliably defer passive effect destroy functions until after the commit phase.

This commit reduces the effect tag types to only include Layout and Passive and differentiates between work and no-work with an HasEffect flag.

* Disabled deferred passive effects flushing in OSS builds for now

* Split up unmount and mount effects list traversal
2020-02-03 12:30:01 -08:00
Dominic Gannaway b2382a7150
Add ReactDOM.unstable_renderSubtreeIntoContainer warning flag (#17936) 2020-01-30 11:56:04 +00:00
Sebastian Markbåge cf7a0c24d4
Remove dynamic GKs for selective/train (#17888)
There are shipped/shipping.
2020-01-21 19:43:35 -08:00
Dominic Gannaway c322f5913f
Add unstable_renderSubtreeIntoContainer and unstable_createPortal feature flags (#17880) 2020-01-21 21:17:42 +00:00
Dominic Gannaway 9fd760ce75
Add disable <textarea/> children flag (#17874) 2020-01-20 15:12:30 +00:00
Dominic Gannaway a209a97ed7
Add feature flag around React.createFactory (#17873) 2020-01-20 15:00:18 +00:00