react/scripts/jest
Andrew Clark 33226fadaa
Check for store mutations before commit (#22290)
* [useSyncExternalStore] Remove extra hook object

Because we already track `getSnapshot` and `value` on the store
instance, we don't need to also track them as effect dependencies. And
because the effect doesn't require any clean-up, we don't need to track
a `destroy` function.

So, we don't need to store any additional state for this effect. We can
call `pushEffect` directly, and only during renders where something
has changed.

This saves some memory, but my main motivation is because I plan to use
this same logic to schedule a pre-commit consistency check. (See the
inline comments for more details.)

* Split shouldTimeSlice into two separate functions

Lanes that are blocking (SyncLane, and DefaultLane inside a blocking-
by-default root) are always blocking for a given root. Whereas expired
lanes can expire while the render phase is already in progress.

I want to check if a lane is blocking without checking whether it
expired, so I split `shouldTimeSlice` into two separate functions.

I'll use this in the next step.

* Check for store mutations before commit

When a store is read for the first time, or when `subscribe` or
`getSnapshot` changes, during a concurrent render, we have to check
at the end of the render phase whether the store was mutated by
an concurrent event.

In the userspace shim, we perform this check in a layout effect, and
patch up any inconsistencies by scheduling another render + commit.
However, even though we patch them up in the next render, the parent
layout effects that fire in the original render will still observe an
inconsistent tree.

In the native implementation, we can instead check for inconsistencies
right after the root is completed, before entering the commit phase. If
we do detect a mutaiton, we can discard the tree and re-render before
firing any effects. The re-render is synchronous to block further
concurrent mutations (which is also what we do to recover from tearing
bugs that result in an error). After the synchronous re-render, we can
assume the tree the tree is consistent and continue with the normal
algorithm for finishing a completed root (i.e. either suspend
or commit).

The result is that layout effects will always observe a consistent tree.
2021-09-13 08:07:46 -07:00
..
matchers Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
spec-equivalence-reporter Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
typescript Remove internal `act` builds from public modules (#21721) 2021-06-22 14:29:35 -07:00
TestFlags.js Check for store mutations before commit (#22290) 2021-09-13 08:07:46 -07:00
config.base.js Update jest to v26 (#21574) 2021-05-27 16:33:57 +01:00
config.build-devtools.js Moved named hooks code (and tests) from react-devtools-extensions to react-devtools-shared (#22260) 2021-09-07 11:44:49 -04:00
config.build.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
config.source-persistent.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
config.source-www.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
config.source.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
dont-run-jest-directly.js Add error when running jest directly (#12726) 2018-05-01 12:46:17 -07:00
jest-cli.js Clean up my "hard to read" code (#22295) 2021-09-11 15:05:54 -04:00
jest.js Add new test cli (#19184) 2020-06-25 20:39:50 -04:00
jestSequencer.js Parallelize Jest in CI (#19552) 2020-08-07 16:32:59 -04:00
noHaste.js Forbid Haste in Jest (#11647) 2017-11-23 18:02:47 +00:00
preprocessor.js Update DevTools to use getCacheForType API (#20548) 2021-01-19 09:51:32 -05:00
setupEnvironment.js [DevTools] Add DevTools forked Feature flags (#18994) 2020-10-12 13:07:10 -04:00
setupGlobal.js Use toMatchInlineSnapshot for dehydrated values (#20618) 2021-04-26 12:30:34 -04:00
setupHostConfigs.js Resolve the true entry point during tests (#21505) 2021-06-02 18:03:29 -07:00
setupTests.build.js Update jest to v26 (#21574) 2021-05-27 16:33:57 +01:00
setupTests.js Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
setupTests.persistent.js Update jest to v26 (#21574) 2021-05-27 16:33:57 +01:00
setupTests.www.js Set up test infra for dynamic Scheduler flags (#22139) 2021-08-20 06:56:20 -07:00
shouldIgnoreConsoleError.js Throw when `act` is used in production (#21686) 2021-06-16 16:29:51 -04:00