Commit Graph

13089 Commits

Author SHA1 Message Date
Dan Abramov
048fe53b22 Revert "Clear more Fiber fields in detachFiber (#18556)"
This reverts commit d48dbb8249.
2020-04-09 20:43:50 +01:00
Sebastian Markbåge
cbab25bb51
Exclude forwardRef and memo from stack frames (#18559)
We can't patch the row. We could give these their own "built-in" stack
frame since they're conceptually HoCs. However, from a debugging
perspective this is not very useful meta data and quite noisy. So I'm
just going to exclude them.
2020-04-09 11:42:22 -07:00
Andrew Clark
26fc16484e
Script for syncing changes between forks (#18550)
Adds command `yarn merge-fork`.

```sh
yarn merge-fork --base-dir=packages/react-reconciler/src ReactFiberWorkLoop
```

This will take all the changes in `ReactFiberWorkLoop.new.js` and apply
them to `ReactFiberWorkLoop.old.js`.

You can merge multiple modules at a time:

```sh
yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop \
  ReactFiberBeginWork \
  ReactFiberCompleteWork \
  ReactFiberCommitWork
```

You can provide explicit "old" and "new" file names. This only works
for one module at a time:

```sh
yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  --old=ReactFiberExpirationTime.js \
  --new=ReactFiberLane.js
```

The default is to merge changes from the new module to the old one. To
merge changes in the opposite direction, use `--reverse`.

```sh
yarn merge-fork \
  --reverse \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop
```

By default, the changes are compared to HEAD. You can use `--base-ref`
to compare to any rev. For example, while working on a PR, you might
make multiple commits to the new fork before you're ready to backport
them to the old one. In that case, you want to compare to the merge
base of your PR branch:

```sh
yarn merge-fork \
  --base-ref=$(git merge-base HEAD origin/master)
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop
```
2020-04-09 11:37:13 -07:00
Sebastian Markbåge
11ac10b44e
Port error boundaries test to yieldValue (#18558) 2020-04-09 11:13:01 -07:00
Dominic Gannaway
d48dbb8249
Clear more Fiber fields in detachFiber (#18556) 2020-04-09 18:31:34 +01:00
Dominic Gannaway
0566b706ee
Fix fiber memory leak with runAllPassiveEffectDestroysBeforeCreates (#18554) 2020-04-09 15:35:07 +01:00
Dominic Gannaway
ca1a703d21
Make enableLegacyFBSupport flag dynamic for www (#18551) 2020-04-09 15:31:36 +01:00
Dominic Gannaway
8cbce05be1
Move plugins into their own directory (#18553) 2020-04-09 14:18:33 +01:00
Dan Abramov
c74f0b0646
Update stale.yml 2020-04-09 13:36:11 +01:00
Andrew Clark
4c6470cb3b Point ReactDOMForked to the new implementation
Updates Rollup, Jest, and Flow configuration to point to the new
entry points.
2020-04-09 00:03:35 -07:00
Andrew Clark
17f582e045 Add forked copies of reconciler modules
All changes in this commit were generated by the following commands.

Copy each module that ends with `.old` to a new file that ends
with `.new`:

```sh
for f in packages/react-reconciler/src/*.old.js; do cp "$f" "$(echo "$f" | sed s/\.old/\.new/)"; done
```

Then transform the internal imports:

```sh
grep -rl --include="*.new.js" '.old' packages/react-reconciler/src/| xargs sed -i '' "s/\.old\'/\.new\'/g"
```
2020-04-09 00:03:35 -07:00
Andrew Clark
376d5c1b5a Split cross-package types from implementation
Some of our internal reconciler types have leaked into other packages.
Usually, these types are treated as opaque; we don't read and write
to its fields. This is good.

However, the type is often passed back to a reconciler method. For
example, React DOM creates a FiberRoot with `createContainer`, then
passes that root to `updateContainer`. It doesn't do anything with the
root except pass it through, but because `updateContainer` expects a
full FiberRoot, React DOM is still coupled to all its fields.

I don't know if there's an idiomatic way to handle this in Flow. Opaque
types are simlar, but those only work within a single file. AFAIK,
there's no way to use a package as the boundary for opaqueness.

The immediate problem this presents is that the reconciler refactor will
involve changes to our internal data structures. I don't want to have to
fork every single package that happens to pass through a Fiber or
FiberRoot, or access any one of its fields. So my current plan is to
share the same Flow type across both forks. The shared type will be a
superset of each implementation's type, e.g. Fiber will have both an
`expirationTime` field and a `lanes` field. The implementations will
diverge, but not the types.

To do this, I lifted the type definitions into a separate module.
2020-04-08 23:49:23 -07:00
Andrew Clark
d686f3f16a Add .old prefix to reconciler modules 2020-04-08 23:49:19 -07:00
Sebastian Markbåge
147bdef11b
Port more tests to the Scheduler.unstable_yieldValue pattern and drop internal.js (#18549)
* Drop the .internal.js suffix on some files that don't need it anymore

* Port some ops patterns to scheduler yield

* Fix triangle test to avoid side-effects in constructor

* Move replaying of setState updaters until after the effect

Otherwise any warnings get silenced if they're deduped.

* Drop .internal.js in more files

* Don't check propTypes on a simple memo component unless it's lazy

Comparing the elementType doesn't work for this because it will never be
the same for a simple element.

This caused us to double validate these. This was covered up because in
internal tests this was deduped since they shared the prop types cache
but since we now inline it, it doesn't get deduped.
2020-04-08 20:54:54 -07:00
Sebastian Markbåge
b014e2d5e3
Don't use closures in DevTools injection (#18278)
* Don't use closures in DevTools injection

Nested closures are tricky. They're not super efficient and when they share
scope between multiple closures they're hard for a compiler to optimize.
It's also unclear how many versions will be created.

By hoisting things out an just make it simple calls the compiler can do
a much better job.

* Store injected hook to work around fast refresh
2020-04-08 17:57:17 -07:00
Sebastian Markbåge
5474a83e25
Disable console.logs in the second render pass of DEV mode double render (#18547)
* Disable console log during the second rerender

* Use the disabled log to avoid double yielding values in scheduler mock

* Reenable debugRenderPhaseSideEffectsForStrictMode in tests that can
2020-04-08 16:43:51 -07:00
Dan Abramov
b225d4f261
Revert "Revert "Refactor commitPlacement to recursively insert nodes (#17996)" (#18517)" (#18540)
This reverts commit e69ca310ea.
2020-04-08 11:22:02 +01:00
jddxf
241103a6fb
Fix bailout broken in lazy components due to default props resolving (#18539)
* Add failing tests for lazy components

* Fix bailout broken in lazy components due to default props resolving

We should never compare unresolved props with resolved props. Since comparing
resolved props by reference doesn't make sense, we use unresolved props in that
case. Otherwise, resolved props are used.

* Avoid reassigning props warning when we bailout
2020-04-08 10:58:57 +01:00
Andrew Clark
2dddd1e00c
Bugfix: Render phase update causes remaining updates in same component to be dropped (#18537)
* Bugfix: Render phase update leads to dropped work

Render phase updates should not affect the `fiber.expirationTime` field.
We don't have to set anything on the fiber because we're going to
process the render phase update immediately.

We also shouldn't reset the `expirationTime` field in between render
passes because it represents the remaining work left in the update
queues. During the re-render, the updates that were skipped in the
original pass are not processed again.

I think my original motivation for using this field for render phase
updates was so I didn't have to add another module level variable.

* Add repro case for #18486

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-04-07 19:17:01 -07:00
Andrew Clark
2def7b3caf
More robust fix for #18515 (#18535)
* Add another test for #18515 using pings

Adds a regression test for the same underlying bug as #18515 but using
pings.

Test already passes, but I confirmed it fails if you revert the fix
in #18515.

* Set nextPendingLevel after commit, too
2020-04-07 18:52:31 -07:00
Dominic Gannaway
948fad357b
Improve detachFiber (#18536) 2020-04-08 01:45:23 +01:00
Carl Vitullo
03de849af0
Make uncontrolled -> controlled warning clearer (#17070)
* Make uncontrolled -> controlled warning clearer

* Update phrasing, mirror for opposite direction

* Remove unused substitution

* Update warning tests

* Literally got these backwards, womp womp

* Rerere-fix tests
2020-04-07 23:19:56 +01:00
jddxf
ddc4b65cfe
Clear finished discrete updates during commit phase (#18515)
* Reproduce a bug where `flushDiscreteUpdates` causes fallback never to be committed

* Ping suspended level when canceling its timer

Make sure the suspended level is marked as pinged so that we return back
to it later, in case the render we're about to start gets aborted.
Generally we only reach this path via a ping, but we shouldn't assume
that will always be the case.

* Clear finished discrete updates during commit phase

If a root is finished at a priority lower than that of the latest pending discrete
updates on it, these updates must have been finished so we can clear them now.
Otherwise, a later call of `flushDiscreteUpdates` would start a new empty render
pass which may cause a scheduled timeout to be cancelled.

* Add TODO

Happened to find this while writing a test. A JSX element comparison
failed because one of them elements had a functional component as an
owner, which should ever happen.

I'll add a regression test later.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2020-04-07 13:34:41 -07:00
Dominic Gannaway
d53a4dbbc2
Export unstable_useEvent for www FB ReactDOM builds (#18532) 2020-04-07 21:32:38 +01:00
Brian Vaughn
8edcd03b64
DevTools Profiler: Fix "cannot read property 'memoizedState' of null" (#18522) 2020-04-07 10:30:25 -07:00
Brian Vaughn
e8ac48f90b
Fix whitespace problem wiht DevTools Components search (#18527) 2020-04-07 10:28:21 -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
Dan Abramov
bce982b799
Change stalebot messages (#18524) 2020-04-07 17:30:45 +01:00
Brian Vaughn
32621a354f
Improved Profiler tooltip confusing/misleading wording (#18523) 2020-04-07 09:26:50 -07:00
Dan Abramov
e69ca310ea
Revert "Refactor commitPlacement to recursively insert nodes (#17996)" (#18517)
This reverts commit df5faddcc2.
2020-04-07 13:41:51 +01:00
Luna Ruan
3278d24218
Add useOpaqueIdentifier Hook (#17322)
* Add useOpaqueIdentifier Hook

We currently use unique IDs in a lot of places. Examples are:
  * `<label for="ID">`
  * `aria-labelledby`

This can cause some issues:
  1. If we server side render and then hydrate, this could cause an
     hydration ID mismatch
  2. If we server side render one part of the page and client side
     render another part of the page, the ID for one part could be
     different than the ID for another part even though they are
     supposed to be the same
  3. If we conditionally render something with an ID ,  this might also
     cause an ID mismatch because the ID will be different on other
     parts of the page

This PR creates a new hook `useUniqueId` that generates a different
unique ID based on whether the hook was called on the server or client.
If the hook is called during hydration, it generates an opaque object
that will rerender the hook so that the IDs match.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2020-04-06 17:17:27 -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
Dominic Gannaway
a3875663f6
React Event System: cleanup plugins + break out update batching logic (#18503) 2020-04-06 22:01:20 +01:00
dependabot[bot]
717a33abb9
Bump minimist from 1.2.0 to 1.2.3 in /scripts/bench (#18500)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-06 19:29:11 +01:00
dependabot[bot]
8c974a70c9
Bump minimist from 1.2.0 to 1.2.3 (#18501)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-06 19:28:56 +01:00
Brian Vaughn
3498f13669
Profiler tooltip shows self duration (#18510) 2020-04-06 09:47:15 -07:00
Faelivrinx
c781156163
Fix performance issue in react-devtools when highlight enabled (#18498)
* Fix performance issue in react-devtools when highlight enabled

* getting minimum expiration time (fix)
2020-04-06 16:17:45 +01:00
Sophie Alpert
fe2cb52554
[eslint] Consider useRef() as ... as constant (#18496)
Sometimes you need to use casts, eg: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28884#issuecomment-471341041. This change ignores them and allows you to still omit the ref object from the deps list.

Test Plan: unit tests
2020-04-05 14:13:34 -07:00
Sebastian Markbåge
1fd45437d7
Don't use checkPropTypes for internals (#18488)
We use console.error for internal warnings.
2020-04-04 15:10:46 -07:00
Zen
2ff27ec112
[eslint] strip tailing property in assignments (#16784)
* [eslint] strip tailing property in assignments

* inline `stripTailingPropInAssignment`
2020-04-04 14:26:39 +01:00
Nick Reiley
f625fce857
Add KeyboardEvent.code to synthetic event (#18287)
* Add KeyboardEvent.code to synthetic event

* remove null to 0 transformation

* make onKeyPress work
2020-04-04 14:24:46 +01:00
Sebastian Markbåge
5022fdfd5f
Refactor Error Dialog Logging (#18487)
* Remove unnecessary CapturedError fields.

componentName is not necessary and is misleading when the error is caused
elsewhere in the stack. The stack is sufficient.

The many error boundary fields are unnecessary because they can be inferred
by the boundary itself.

* Don't attempt to build a stack twice

If it was possible, it would've been done in createCapturedValue.

* Push the work needed by the works into the forks

This avoids needing this in the npm published case.
2020-04-03 19:01:40 -07:00
Sebastian Markbåge
e2dd30898e
[Flight] Lazily parse models and allow any value to suspend (#18476)
* Lazily initialize models as they're read intead of eagerly when received

This ensures that we don't spend CPU cycles processing models that we're
not going to end up rendering.

This model will also allow us to suspend during this initialization if
data is not yet available to satisfy the model.

* Refactoring carefully to ensure bundles still compile to something optimal

* Remove generic from Response

The root model needs to be cast at one point or another same as othe
chunks. So we can parameterize the read instead of the whole Response.

* Read roots from the 0 key of the map

The special case to read the root isn't worth the field and code.

* Store response on each Chunk

Instead of storing it on the data tuple which is kind of dynamic, we store
it on each Chunk. This uses more memory. Especially compared to just making
initializeBlock a closure, but overall is simpler.

* Rename private fields to underscores

Response objects are exposed.

* Encode server components as delayed references

This allows us to stream in server components one after another over the
wire. It also allows parallelizing their fetches and resuming only the
server component instead of the whole parent block.

This doesn't yet allow us to suspend deeper while waiting on this content
because we don't have "lazy elements".
2020-04-03 14:58:02 -07:00
Sebastian Markbåge
59fd09cb67
[Flight] Add webpack plugin build (#18485)
* Eject CRA from Flight

We need to eject because we're going to add a custom Webpack Plugin.

We can undo this once the plugin has upstreamed into CRA.

* Add Webpack plugin build

I call this entry point "webpack-plugin" instead of "plugin" even though
this is a webpack specific package. That's because there will also be a
Node.js plugin to do the server transform.

* Add Flight Webpack plugin to fixture

* Rm UMD builds

* Transform classes

* Rename webpack-plugin to plugin

This avoids the double webpack name. We're going to reuse this for both
server and client.
2020-04-03 14:04:56 -07:00
Luna Ruan
a876808f0a
remove jsx plugin from react (#18484)
Now that the React JSX Babel Plugin is in Babel, remove this code from react
2020-04-03 13:00:50 -07:00
Hristo Kanchev
7785a5263e
[DevTools] - Highlight rendered by elements on hover. (#18479)
* [DevTools] - Highlight rendered by elements on hover.

* Fixed formatting issue.

* DevTools - Extracted highlight logic to custom hook. Added highlight support for rendered by elements.

* Removed unnecessary padding style

* Removed unnecessary wrapper function.

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-04-03 10:49:49 -07:00
Brian Vaughn
f312a3fc36
useMutableSource: bugfix for new getSnapshot with mutation (#18297) 2020-04-03 10:20:17 -07:00
Dan Abramov
a8f2165e83
Update to Jest 25 (#18480)
* Revert "Revert "Upgrade to jest 25 (#17896)" (#18376)"

This reverts commit fc7835c657.

* Other fixes

* Fix a broken test
2020-04-03 16:37:36 +01:00
Nick Reiley
c083a643b1
Add <progress> to DOM fixtures (#18293)
* Add <progress> to DOM fixtures

* Remove uncontrolled
2020-04-03 14:39:59 +01:00
Sebastian Markbåge
3c16baf848
Remove /dist/ UMD builds (#18473)
* Remove /dist/ UMD builds

We publish UMDs to npm (and we're considering stopping even that).

This means we'll stop publishing to http://react.zpao.com/builds/master/latest/

* Update fixture paths
2020-04-02 17:52:32 -07:00