Commit Graph

14975 Commits

Author SHA1 Message Date
Andrew Clark a412d787e9
Remove dependency on build artifacts mirror (#24575)
This reverts #24106.

There was a regression in CircleCI's artifacts API recently where you
could no longer access artifacts without an authorization token. This
broke our size reporting CI job because we can't use an authorization
token on external PRs without potentially leaking it. As a temporary
workaround, I changed the size reporting job to use a public mirror of
our build artifacts.

The CircleCI API has since been fixed to no longer require
authorization, so we can revert the workaround.
2022-05-18 11:13:19 -04:00
Luna Ruan 357a61324f
[DevTools][Transition Tracing] Added support for Suspense Boundaries (#23365)
This PR:

* During the passive effect complete phase for Offscreen, we add all the transitions that were added to the update queue in the render phase to the transitions set on the memoziedState. We also add the stateNode for the Offscreen component to the root pendingSuspenseBoundaries map if the suspense boundary has gone from shown to fallback. We remove the stateNode if the boundary goes from fallback to shown.
* During the passive effect complete phase for the HostRoot, for each transition that was initiated during this commit, we add a pending transitionStart callback. We also add them to the transition set on the memoizedState for the HostRoot. If the root pendingSuspenseBoundaries is empty, we add a pending transitionComplete callback.
2022-05-16 13:23:46 -04:00
Luna Ruan c5e039d9b0
[DevTools] Add jest-cli --reactVersion argument (#24556)
Add `--reactVersion` argument. This argument is only used in DevTools. When this is specified, run only the tests that have the `// @reactVersion` pragma that satisfies the semver version range. Otherwise, run tests as normal
2022-05-16 08:30:43 -07:00
Luna Ruan 4c03bb6ed0
[DevTools] ignore tests without reactVersion pragma if REACT_VERSION specified (#24555)
In DevTools tests, if the REACT_VERSION specified, we know this is a regression test (testing older React Versions). Because a lot of tests test the DevTools front end and we don't want to run them in the regression test scenario, we decided to only run tests that have the // @reactVersion pragma defined.

Because if there are no tests specified, jest will fail, we also opt to use jest.skip to skip all the tests that we don't want to run for a specific React version istead.

This PR makes this change.
2022-05-14 00:54:50 -04:00
Luna Ruan 0ecb77d4c5
[DevTools] Fix formatWithStyles not styling the results if the first argument is an object + Added unit tests (#24554)
formatWithStyles currently doesn't style the array argument if the first argument is an object. This PR fixes this and also adds unit tests.
2022-05-13 15:34:33 -07:00
dan 2c8a1452b8
Fix ignored setState in Safari when iframe is touched (#24459) 2022-05-12 17:58:18 +01:00
Ricky 62662633d1
Remove enableFlipOffscreenUnhideOrder (#24545) 2022-05-12 12:40:17 -04:00
Mengdi "Monday" Chen 52c434be1d
React DevTools 4.24.5 -> 4.24.6 (#24547) 2022-05-12 10:52:55 -04:00
Mengdi "Monday" Chen 852f10b5cf
fix a bug in console.log with non-string args (#24546) 2022-05-12 10:29:36 -04:00
Ricky 34da5aa69b
Only treat updates to lazy as a new mount in legacy mode (#24530)
* Only treat updates to lazy as a new mount in legacy mode

* Update name and swap current check

* Flip order back
2022-05-12 08:51:32 -04:00
Luna Ruan 7d9e17a982
[DevTools] Add Pragma to Only Run Tests if Version Requirement Satisfied (#24533)
This PR:

Adds a transform-react-version-pragma that transforms // @reactVersion SEMVER_VERSION into _test_react_version(...) and _test_react_version_focus(...) that lets us only run a test if it satisfies the right react version.
Adds _test_react_version and _test_react_version_focus to the devtools setupEnv file
Add a devtools preprocessor file for devtools specific plugins
2022-05-11 12:01:05 -04:00
Josh Story 8197c73ec3
Support document rendering (#24523)
* Support Document as a container for hydration and rendering

Previously Document was not handled effectively as a container. in particual when hydrating if there was a fallback to client rendering React would attempt to append a new <html> element into the document before clearing out the existing one which errored leaving the application in brokent state.

The initial approach I took was to recycle the documentElement and never remove or append it, always just moving it to the right fiber and appending the right children (heady/body) as needed. However in testing a simple approach in modern browsers it seems like treating the documentElement like any other element works fine. This change modifies the clearContainer method to remove the documentElement if the container is a DOCUMENT_NODE. Once the container is cleared React can append a new documentElement via normal means.

* Allow Document as container for createRoot

previously rendering into Document was broken and only hydration worked because React did not properly deal with the documentElement and would error in a broken state if used that way. With the previous commit addressing this limitation this change re-adds Document as a valid container for createRoot.

It should be noted that if you use document with createRoot it will drop anything a 3rd party scripts adds the page before rendering for the first time.
2022-05-10 10:17:36 -07:00
Luna Ruan d20c3af9d1
[DevTools][Bug] Fix Race Condition When Unmounting Fibers (#24510)
When we delete fibers, we will call onCommitFiberUnmount on every deleted fiber to also remove them from the element tree. However, there are some cases where fibers aren't deleted but we still want to remove them from the element tree (ex. offscreen). In the second case, we recursively remove these children during handleCommitFiberRoot.

When we remove an element, we will untrack its corresponding fiber ID. However, because of fast refresh, we don't do this immediately, opting to instead add the value to a set to process later. However, before the set has been processed, we unmount that fiber again, we will get duplicate unmounts.

To fix this, handleCommitFiberRoot explicitly flushes all the fibers in the set before starting the deletion process. We also need to do this in handleCommitFiberUnmount in case handleCommitFiberRoot gets called first.
2022-05-06 15:36:03 -04:00
Timothy Yung 46a6d77e32
Unify JSResourceReference Interfaces (#24507) 2022-05-06 11:24:04 -07:00
Mengdi "Monday" Chen e531a4a62d
[React DevTools] Improve DevTools UI when Inspecting a user Component that Throws an Error (#24248)
* [ReactDevTools] custom view for errors occur in user's code

* [ReactDevTools] show message for unsupported feature

* fix bad import

* fix typo

* fix issues from rebasing

* prettier

* sync error names

* sync error name with upstream

* fix lint & better comment

* fix error message for test

* better error message per review

* add missing file

* remove dead enum & provide component name in error message

* better error message

* better user facing error message
2022-05-05 20:17:23 -04:00
Brian Vaughn 547b707493
React DevTools 4.24.4 -> 4.24.5 (#24503) 2022-05-05 10:19:08 -07:00
Brian Vaughn d4acbe85d5
Fixed possible undefined error in TreeContext reducer (#24501) 2022-05-05 08:46:57 -07:00
Sebastian Markbåge 024a7274fb
Constrain the container type of createPortal (#24496)
We already constrained the type of createRoot (can't take document) and hydrateRoot (can't take fragments).
2022-05-04 23:05:37 -04:00
Luna Ruan 3dc9a8af05
fix forward ref (#24494)
Resolves #24428

---

For fiber types that render user code, we check the PerformedWork flag rather than the props, ref, and state to see if the fiber rendered (rather than bailing out/etc.) so we know whether we need to do things like record profile durations. ForwardRef wasn't added to this list, which caused #24428.
2022-05-04 13:25:27 -07:00
Luna Ruan c7e494b553
[React DevTools] Fix regex for formateWithStyles function (#24486)
The previous regex to detect string substitutions is not quite right, this PR fixes it by:

Check to make sure we are starting either at the beginning of the line or we match a character that's not % to make sure we capture all the % in a row.
Make sure there are an odd number of % (the first X pairs are escaped % characters. The odd % followed by a letter is the string substitution)
2022-05-03 15:52:56 -07:00
Ricky 6cbf0f7fac
Fork ReactSymbols (#24484)
* Fork ReactSymbols

* Fix tests

* Update jest config
2022-05-03 17:12:23 -04:00
Ricky a10a9a6b5b
Add test for hiding children after layout destroy (#24483) 2022-05-03 14:24:23 -04:00
Josh Story b4eb0ad71f
Do not replay erroring beginWork with invokeGuardedCallback when suspended or previously errored (#24480)
When hydrating a suspense boundary an error or a suspending fiber can often lead to a cascade of hydration errors. While in many cases these errors are simply discarded (e.g. when teh root does not commit and we fall back to client rendering) the use of invokeGuardedCallback can lead to many of these errors appearing as uncaught in the browser console. This change avoids error replaying using invokeGuardedCallback when we are hydrating a suspense boundary and have either already suspended or we have one previous error which was replayed.
2022-05-03 11:07:47 -07:00
Ricky 99eef9e2df
Hide children of Offscreen after destroy effects (#24446) 2022-05-03 10:16:53 -04:00
Brian Vaughn 6c36aee944
Fixed wrong method call for LRU cache (#24477) 2022-05-02 21:17:01 -04:00
Andrew Clark ce13860281
Remove enablePersistentOffscreenHostContainer flag (#24460)
This was a Fabric-related experiment that we ended up not shipping.
2022-04-28 15:05:41 -04:00
dan 340060cccd
Add @Andarist to changelog credits 2022-04-28 16:03:34 +01:00
dan 9f80a48ad4
Add missing item to the changelog 2022-04-27 02:03:08 +01:00
Andrew Clark 53b95e5511
Fill in date in changelog for 18.1 (#24449) 2022-04-26 17:09:08 -04:00
dan d78460490b
Add date to changelog 2022-04-26 22:07:33 +01:00
dan 9c25728d10
Changelog for 18.1 (#24411)
* 1810-changelog

* Update CHANGELOG.md

Co-authored-by: Strek <ssharishkumar@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Strek <ssharishkumar@gmail.com>
2022-04-26 22:05:29 +01:00
Andrew Clark 2633a6efc4
Bump `@next` versions (#24448)
18.2 will be the next release
2022-04-26 16:58:53 -04:00
Andrew Clark 72b7462fe7
Bump local package.json versions for 18.1 release (#24447) 2022-04-26 16:58:44 -04:00
Andrew Clark 22edb9f777
React `version` field should match package.json (#24445)
The `version` field exported by the React package currently corresponds
to the `@next` release for that build. This updates the build script
to output the same version that is used in the package.json file.

It works by doing a find-and-replace of the React version after the
build has completed. This is a bit weird but it saves us from having
to build the `@next` and `@latest` releases separately; they are
identical except for the version numbers.
2022-04-26 16:28:48 -04:00
Michael サイトー 中村 Bashurov 6bf3deef59
Upgrade react-shallow-renderer to support react 18 (#24442)
To a minimum version that support react 18
2022-04-26 19:45:04 +01:00
dan bd4784c8f8
Revert #24236 (Don't recreate the same fallback on the client if hydrating suspends) (#24434)
* Revert #24236 (Don't recreate the same fallback on the client if hydrating suspends)

* Use @gate FIXME
2022-04-25 16:16:32 +01:00
Andrew Clark 6d3b6d0f40
forwardRef et al shouldn't affect if props reused (#24421)
We don't have strong guarantees that the props object is referentially
equal during updates where we can't bail out anyway — like if the props
are shallowly equal, but there's a local state or context update in the
same batch.

However, as a principle, we should aim to make the behavior consistent
across different ways of memoizing a component. For example, React.memo
has a different internal Fiber layout if you pass a normal function
component (SimpleMemoComponent) versus if you pass a different type like
forwardRef (MemoComponent). But this is an implementation detail.
Wrapping a component in forwardRef (or React.lazy, etc) shouldn't affect
whether the props object is reused during a bailout.

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2022-04-22 14:23:26 -04:00
Andrew Clark bd08137666
Fix: useDeferredValue should reuse previous value (#24413)
During an urgent update, useDeferredValue should reuse the previous
value. The regression test I added shows that it was reverting to
the initial value instead.

The cause of the bug was trivial: the update path doesn't update the
hook's `memoizedState` field. Only the mount path.

None of the existing tests happened to catch this because to trigger the
bug, you have to do an urgent update that isn't the first update after
initial render. In all of the existing tests that included an urgent
update, it was the first update, so the "previous" value and the initial
value happened to be the same thing.
2022-04-20 23:30:46 -04:00
Josh Story 9ae80d6a2b
Suppress hydration warnings when a preceding sibling suspends (#24404)
* Add failing test case for #24384

If a components suspends during hydration we expect there to be mismatches with server rendered HTML but we were not always supressing warning messages related to these expected mismatches

* Mark hydration as suspending on every thrownException

previously hydration would only be marked as supsending when a genuine error was thrown. This created an opportunity for a hydration mismatch that would warn after which later hydration mismatches would not lead to warnings. By moving the marker check earlier in the thrownException function we get the hydration context to enter the didSuspend state on both error and thrown promise cases which eliminates this gap.

* Fix failing test related to client render fallbacks

This test was actually subject to the project identified in the issue fixed in this branch. After fixing the underlying issue the assertion logic needed to change to pick the right warning which now emits after hydration successfully completes on promise resolution. I changed the container type to 'section' to make the error message slightly easier to read/understand (for me)

* Only mark didSuspend on suspense path

For unknown reasons the didSuspend was being set only on the error path and nto the suspense path. The original change hoisted this to happen on both paths. This change moves the didSuspend call to the suspense path only. This appears to be a noop because if the error path marked didSuspend it would suppress later warnings but if it does not the warning functions themsevles do that suppression (after the first one which necessarily already happened)

* gate test on hydration fallback flags

* refactor didSuspend to didSuspendOrError

the orignial behavior applied the hydration warning bailout to error paths only. originally I moved it to Suspense paths only but this commit restores it to both paths and renames the marker function as didThrow rather than didSuspend

The logic here is that for either case if we get a mismatch in hydration we want to warm up components but effectively consider the hydration for this boundary halted

* factor tests to assert different behavior between prod and dev

* add DEV suffix to didSuspendOrError to better indicate this feature should only affect dev behavior

* move tests back to ReactDOMFizzServer-test

* fix comment casing

* drop extra flag gates in tests

* add test for user error case

* remove unnecessary gate

* Make test better

it now has an intentional client mismatch that would error if there wasn't suppression brought about by the earlier error. when it client renders it has the updated value not found in the server response but we do not see a hydration warning because it was superseded by the thrown error in that render
2022-04-20 14:52:54 -07:00
Andrew Clark 0dc4e6663d
Land enableClientRenderFallbackOnHydrationMismatch (#24410)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 14:09:11 -04:00
Andrew Clark 354772952a
Land enableSelectiveHydration flag (#24406)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:26:25 -04:00
Andrew Clark 392808a1f7
Land enableClientRenderFallbackOnTextMismatch flag (#24405)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:21:36 -04:00
Andrew Clark 1e748b4528
Land enableLazyElements flag (#24407)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:17:52 -04:00
Ricky 4175f05934
Temporarily feature flag numeric fallback for symbols (#24401) 2022-04-19 17:34:49 -04:00
Ricky a6d53f3468
Revert "Clean up Selective Hydration / Event Replay flag (#24156)" (#24402)
This reverts commit b5cca182ff.
2022-04-19 17:34:30 -04:00
Andrew Clark ab9cdd34fb
Bugfix: In legacy mode, call suspended tree's unmount effects when it is deleted (#24400)
* Bug: Missing unmount when suspended tree deleted

When a suspended tree switches to a fallback, we unmount the effects.
If the suspended tree is then deleted, there's a guard to prevent us
from unmounting the effects again.

However, in legacy mode, we don't unmount effects when a tree suspends.
So if the suspended tree is then deleted, we do need to unmount
the effects.

We're missing a check for legacy/concurrent mode.

* Fix: Unmount suspended tree when it is deleted
2022-04-19 17:09:07 -04:00
Josh Story 2bf5eba724
explain the rationale for the chosen escaping implemenation in a comment (#24389) 2022-04-16 14:29:12 -07:00
Josh Story d40dc73cf9
Escape bootstrapScriptContent for javascript embedding into HTML (#24385)
The previous escape was for Text into HTML and breaks script contents. The new escaping ensures that the script contents cannot prematurely close the host script tag by escaping script open and close string sequences using a unicode escape substitution.
2022-04-16 10:47:46 -07:00
Billy Janitsch 726ba80298
Synchronize implementations of second render logging (#24381)
Minor followup to #24373. The fix for #24373 (comment) didn't get synchronized to the hook implementation.
2022-04-15 10:35:35 -05:00
Luna Ruan d63cd97245
don't stringify objects for console log second render (#24373)
Fixes #24302 based on #24306.
---

The current implementation for strict mode double logging stringiness and dims the second log. However, because we stringify everything, including objects, this causes objects to be logged as `[object Object]` etc.

This PR creates a new function that formats console log arguments with a specified style. It does this by:
1. The first param is a string that contains %c: Bail out and return the args without modifying the styles. We don't want to affect styles that the developer deliberately set.
2. The first param is a string that doesn't contain %c but contains string formatting: `[`%c${args[0]}`, style, ...args.slice(1)]` Note: we assume that the string formatting that the developer uses is correct.
3. The first param is a string that doesn't contain string formatting OR is not a string: Create a formatting string where:
   -  boolean, string, symbol -> %s
   -  number -> %f OR %i depending on if it's an int or float
   -  default -> %o
---
Co-authored-by: Billy Janitsch <billy@kensho.com>
2022-04-14 11:30:04 -05:00