Commit Graph

14294 Commits

Author SHA1 Message Date
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
Andrew Clark ae5afb3b9d Simplify discreteUpdates (#21773)
Now that discrete updates are flushed synchronously in a microtask,
the `discreteUpdates` method used by our event system is only a
optimization to save us from having to check `window.event.type` on
every update. So we should be able to remove the extra logic.

Assuming this lands successfully, we can remove `batchedEventUpdates`
and probably inline `discreteUpdates` into the renderer, like we do
for continuous updates.
2021-06-30 11:29:31 -07:00
郭帅彬 3e8c86c1c8 fix: maxYieldInterval should not compare with currentTime directly in Scheduler-shouldYieldToHost 2021-06-30 10:01:04 -04:00
Sebastian Silbermann f6112ffe5a chore: Ignore build2/ when linting (#21204) 2021-06-30 14:27:32 +01:00
dependabot[bot] 2442d988ef Bump ws from 6.1.2 to 6.2.2 in /scripts/release (#21628)
Bumps [ws](https://github.com/websockets/ws) from 6.1.2 to 6.2.2.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/commits)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-29 16:53:39 -04:00
dependabot[bot] 83f38d0768 Bump ecstatic from 2.2.1 to 2.2.2 in /scripts/bench (#20468)
Bumps [ecstatic](https://github.com/jfhbrook/node-ecstatic) from 2.2.1 to 2.2.2.
- [Release notes](https://github.com/jfhbrook/node-ecstatic/releases)
- [Changelog](https://github.com/jfhbrook/node-ecstatic/blob/2.2.2/CHANGELOG.md)
- [Commits](https://github.com/jfhbrook/node-ecstatic/compare/2.2.1...2.2.2)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-29 16:53:31 -04:00
Brian Vaughn d483463bc8 Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Andrew Clark cae635054e act: Resolve to return value of scope function (#21759)
When migrating some internal tests I found it annoying that I couldn't
return anything from the `act` scope. You would have to declare the
variable on the outside then assign to it. But this doesn't play well
with type systems — when you use the variable, you have to check
the type.

Before:

```js
let renderer;
act(() => {
  renderer = ReactTestRenderer.create(<App />);
})

// Type system can't tell that renderer is never undefined
renderer?.root.findByType(Component);
```

After:

```js
const renderer = await act(() => {
  return ReactTestRenderer.create(<App />);
})
renderer.root.findByType(Component);
```
2021-06-26 11:51:23 -07:00
Andrew Clark e2453e2007 act: Add test for bypassing queueMicrotask (#21743)
Test for fix added in #21740
2021-06-25 12:39:46 -07:00
Brian Vaughn 73ffce1b6f DevTools: Update tests to fix warnings/errors (#21748)
Some new ones had slipped in (e.g. deprecated ReactDOM.render message from 18)
2021-06-24 22:42:44 -04:00
Dan Abramov 534c9c52ec Move error logging to update callback (#21737)
* Move error logging to update callback

This prevents double logging for gDSFE boundaries with createRoot.

* Add an explanation for the rest of duplicates
2021-06-24 20:57:10 +01:00
Dan Abramov 51b0becf3e Always keep disabled logs in the second pass (#21739)
* Add tests for disabled logs

* Always keep disabled logs in the second pass

* Jest nit

* Always use the second result
2021-06-24 19:50:07 +01:00
Brian Vaughn 386e8f2ea7 DevTools: Fix Settings dialog scroll/size bug in Firefox (#21747) 2021-06-24 11:19:57 -04:00
Dan Abramov 7fec38041f Log and show error overlay for commit phase errors (#21723)
* Enable skipped tests from #21723

* Report uncaught errors in DEV

* Clear caught error

This is not necessary (as proven by tests) because next invokeGuardedCallback clears it anyway. But I'll keep it for consistency with other calls.
2021-06-24 15:48:28 +01:00
Andrew Clark 27c9c95e23 act: Bypass microtask for "default sync" updates (#21740)
When wrapping an update in act, instead of scheduling a microtask,
we can add the task to our internal queue.

The benefit is that the user doesn't have to await the act call. We can
flush the work synchronously. This doesn't account for microtasks that
are scheduled in userspace, of course, but it at least covers
React's usage.
2021-06-23 17:32:44 -07:00
Brian Vaughn 8426bb6956 Pass Jest useStderr flag when debugging (#21741)
This prevents it from buffering adn suppressing all console logs until a test has completed running (When debugging in Chrome).
2021-06-23 16:58:46 -04:00
Dan Abramov e577bfb1ce Add tests for invokeGuardedCallback (#21734)
* Add tests for invokeGuardedCallback

* Add skipped failing tests

* Check next render works

* Mirror tests for createRoot

* Move comments around
2021-06-23 21:47:47 +01:00
Brian Vaughn 355591add4 Next/experimental release versions include commit date (#21700)
Change format of @next and @experimental release versions from <number>-<sha> to <number>-<sha>-<date> to make them more human readable. This format still preserves the ability for us to easily map a version number to the changes it contains, while also being able to more easily know at a glance how recent a release is.
2021-06-23 13:50:09 -04:00
Andrew Clark d7dce572c7 Remove internal act builds from public modules (#21721)
* Move internal version of act to shared module

No reason to have three different copies of this anymore.

I've left the the renderer-specific `act` entry points because legacy
mode tests need to also be wrapped in `batchedUpdates`. Next, I'll update
the tests to use `batchedUpdates` manually when needed.

* Migrates tests to use internal module directly

Instead of the `unstable_concurrentAct` exports. Now we can drop those
from the public builds.

I put it in the jest-react package since that's where we put our other
testing utilities (like `toFlushAndYield`). Not so much so it can be
consumed publicly (nobody uses that package except us), but so it works
with our build tests.

* Remove unused internal fields

These were used by the old act implementation. No longer needed.
2021-06-22 14:29:35 -07:00
Andrew Clark 06f7b4f43a act should work without mock Scheduler (#21714)
Currently, in a React 18 root, `act` only works if you mock the
Scheduler package. This was because we didn't want to add additional
checks at runtime.

But now that the `act` testing API is dev-only, we can simplify its
implementation.

Now when an update is wrapped with `act`, React will bypass Scheduler
entirely and push its tasks onto a special internal queue. Then, when
the outermost `act` scope exists, we'll flush that queue.

I also removed the "wrong act" warning, because the plan is to move
`act` to an isomorphic entry point, simlar to `startTransition`. That's
not directly related to this PR, but I didn't want to bother
re-implementing that warning only to immediately remove it.

I'll add the isomorphic API in a follow up.

Note that the internal version of `act` that we use in our own tests
still depends on mocking the Scheduler package, because it needs to work
in production. I'm planning to move that implementation to a shared
(internal) module, too.
2021-06-22 14:25:07 -07:00
Andrew Clark 422e0bb360 Delete test-utils implementation of act (#21703)
* Delete test-utils implementation of `act`

Since it's dev-only now, we can use the one provided by the reconciler.

* Move act related stuff out of EventInternals
2021-06-22 14:21:22 -07:00
Sebastian Markbåge 568dc3532e Remove unstable_createRoot from internal builds (#21698)
These callsites were already removed as far as I can tell.
2021-06-17 11:29:30 -07:00
Dan Abramov 43f4cc1608 Fix failing test (#21697) 2021-06-17 13:56:18 +01:00
Brian Vaughn d0f348dc1b Fix for failed Suspense layout semantics (#21694)
Co-authored-by: Dan Abramov <dan.abramov@me.com>
2021-06-16 19:44:44 -04:00