Commit Graph

267 Commits

Author SHA1 Message Date
Jan Kassens
ee85098019
[cleanup] remove deletedTreeCleanUpLevel feature flag (#25529)
I noticed this was an experiment concluded 16 months ago (#21679) that
this extra work is beneficial
to break up cycles leaking memory in product code.
2023-01-17 11:03:29 -05:00
Jan Kassens
0fce6bb498
[cleanup] remove feature flags warnAboutDefaultPropsOnFunctionComponents and warnAboutStringRefs (#25980)
These feature flags are fully rolled out and easy to clean up. Let's
remove them!
2023-01-11 12:19:46 -05:00
Jan Kassens
a48e54f2b7
[cleanup] remove old feature flag warnAboutDeprecatedLifecycles (#25978)
This feature flag was always set to true, we can easily clean it up.
2023-01-10 15:30:42 -05:00
Tianyu Yao
5379b6123f
Batch sync, default and continuous lanes (#25700)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn debug-test --watch TestName`, open
`chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This is the other approach for unifying default and sync lane
https://github.com/facebook/react/pull/25524.
The approach in that PR is to merge default and continuous lane into the
sync lane, and use a new field to track the priority. But there are a
couple places that field will be needed, and it is difficult to
correctly reset the field when there is no sync lane.

In this PR we take the other approach that doesn't remove any lane, but
batch them to get the behavior we want.


## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
yarn test

Co-authored-by: Andrew Clark <hi@andrewclark.io>
2023-01-05 15:21:35 -08:00
Sebastian Markbåge
84a0a171ea
Rename experimental useEvent to useEffectEvent (#25881)
We originally had grand plans for using this Event concept for more but
now it's only meant to be used in combination with effects.

It's an Event in the FRP terms, that is triggered from an Effect.
Technically it can also be from another function that itself is
triggered from an existing side-effect but that's kind of an advanced
case.

The canonical case is an effect that triggers an event:

```js
const onHappened = useEffectEvent(() => ...);
useEffect(() => {
  onHappened();
}, []);
```
2022-12-14 15:08:29 -05:00
Jan Kassens
420f0b7fa1
Remove Reconciler fork (1/2) (#25774)
We've heard from multiple contributors that the Reconciler forking
mechanism was confusing and/or annoying to deal with. Since it's
currently unused and there's no immediate plans to start using it again,
this removes the forking.

Fully removing the fork is split into 2 steps to preserve file history:

**This PR**
- remove `enableNewReconciler` feature flag.
- remove `unstable_isNewReconciler` export
- remove eslint rules for cross fork imports
- remove `*.new.js` files and update imports
- merge non-suffixed files into `*.old` files where both exist
(sometimes types were defined there)

**#25775**
- rename `*.old` files
2022-12-01 23:06:25 -05:00
Sebastian Markbåge
7b17f7bbf3
Enable warning for defaultProps on function components for everyone (#25699)
This also fixes a gap where were weren't warning on memo components.
2022-11-17 12:22:23 -05:00
Sebastian Silbermann
6fb8133ed3
Turn on string ref deprecation warning for everybody (not codemoddable) (#25383)
## Summary
 
Alternate to https://github.com/facebook/react/pull/25334 without any
prod runtime changes i.e. the proposed codemod in
https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#deprecate-string-refs-and-remove-production-mode-_owner-field
would not work.

## How did you test this change?

- [x] CI
- [x] `yarn test` with and without `warnAboutStringRefs`
2022-11-16 19:15:57 -05:00
Sebastian Markbåge
07f46ecf2e
Turn on key spread warning in jsx-runtime for everyone (#25697)
This improves the error message a bit and ensures that we recommend
putting the key first, not last, which ensures that the faster
`jsx-runtime` is used.

This only affects the modern "automatic" JSX transform.
2022-11-16 18:57:50 -05:00
mofeiZ
6883d79445
[ServerRenderer] Setup for adding data attributes streaming format (#25567) 2022-11-01 12:04:50 -04:00
Sebastian Markbåge
e7c5af45ce
Update cache() and use() to the canary aka next channel (#25502)
Testing what it would look like to move this to the `next` channel.
2022-10-23 23:20:52 -04:00
Sebastian Markbåge
65e32e58b6
Add fetch Instrumentation to Dedupe Fetches (#25516)
* Add fetch instrumentation in cached contexts

* Avoid unhandled rejection errors for Promises that we intentionally ignore

In the final passes, we ignore the newly generated Promises and use
the previous ones. This ensures that if those generate errors, that we
intentionally ignore those.

* Add extra fetch properties if there were any
2022-10-19 18:37:00 -04:00
Samuel Susla
987292815c
Remove feature flag enableStrictEffects (#25387) 2022-10-19 10:57:09 +01:00
Andrew Clark
9cdf8a99ed
[Codemod] Update copyright header to Meta (#25315)
* Facebook -> Meta in copyright

rg --files | xargs sed -i 's#Copyright (c) Facebook, Inc. and its affiliates.#Copyright (c) Meta Platforms, Inc. and affiliates.#g'

* Manual tweaks
2022-10-18 11:19:24 -04:00
Andrew Clark
500bea532d
Add option to load Fizz runtime from external file (#25499)
* Add feature flag for external Fizz runtime

Only enabled for www for now

* Add option to load Fizz runtime from external file

When unstable_externalRuntimeSrc is provided, React will inject a script
tag that points to the provided URL.

Then, instead of emitting inline scripts, the Fizz stream will emit
HTML nodes with data attributes that encode the instructions. The
external runtime will detect these with a mutation observer and
translate them into runtime commands. This part isn't implemented in 
this PR, though — all this does is set up the option to use 
an external runtime, and inject the script tag.

The external runtime is injected at the same time as bootstrap scripts.
2022-10-17 17:57:59 -04:00
Josh Story
2cf4352e1c
Implement HostSingleton Fiber type (#25426) 2022-10-11 08:42:42 -07:00
Samuel Susla
abbbdf4cec
Put modern StrictMode behind a feature flag (#25365)
* Put modern StrictMode behind a feature flag

* Remove unneeded flag
2022-09-30 17:06:11 +01:00
Vic Graf
20a257c259
Refactor: more word doubles removed (#25352) 2022-09-29 09:57:49 -04:00
Lauren Tan
c91a1e03be
experimental_useEvent (#25229)
This commit adds a new hook `useEvent` per the RFC [here](https://github.com/reactjs/rfcs/pull/220), gated as experimental. 

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>
2022-09-14 11:39:06 -07:00
Ricky
0de3ddf56e
Remove Symbol Polyfill (again) (#25144) 2022-08-25 17:01:30 -04:00
Andrew Clark
b6978bc38f
experimental_use(promise) (#25084)
* Internal `act`: Unwrapping resolved promises

This update our internal implementation of `act` to support React's new
behavior for unwrapping promises. Like we did with Scheduler, when 
something suspends, it will yield to the main thread so the microtasks
can run, then continue in a new task.

I need to implement the same behavior in the public version of `act`,
but there are some additional considerations so I'll do that in a
separate commit.

* Move throwException to after work loop resumes

throwException is the function that finds the nearest boundary and
schedules it for a second render pass. We should only call it right 
before we unwind the stack — not if we receive an immediate ping and
render the fiber again.

This was an oversight in 8ef3a7c that I didn't notice because it happens
to mostly work, anyway. What made me notice the mistake is that
throwException also marks the entire render phase as suspended
(RootDidSuspend or RootDidSuspendWithDelay), which is only supposed to
be happen if we show a fallback. One consequence was that, in the 
RootDidSuspendWithDelay case, the entire commit phase was blocked,
because that's the exit status we use to block a bad fallback
from appearing.

* Use expando to check whether promise has resolved

Add a `status` expando to a thrown thenable to track when its value has
resolved.

In a later step, we'll also use `value` and `reason` expandos to track
the resolved value.

This is not part of the official JavaScript spec — think of
it as an extension of the Promise API, or a custom interface that is a
superset of Thenable. However, it's inspired by the terminology used
by `Promise.allSettled`.

The intent is that this will be a public API — Suspense implementations
can set these expandos to allow React to unwrap the value synchronously
without waiting a microtask.

* Scaffolding for `experimental_use` hook

Sets up a new experimental hook behind a feature flag, but does not
implement it yet.

* use(promise)

Adds experimental support to Fiber for unwrapping the value of a promise
inside a component. It is not yet implemented for Server Components, 
but that is planned.

If promise has already resolved, the value can be unwrapped
"immediately" without showing a fallback. The trick we use to implement
this is to yield to the main thread (literally suspending the work
loop), wait for the microtask queue to drain, then check if the promise
resolved in the meantime. If so, we can resume the last attempted fiber
without unwinding the stack. This functionality was implemented in 
previous commits.

Another feature is that the promises do not need to be cached between
attempts. Because we assume idempotent execution of components, React
will track the promises that were used during the previous attempt and
reuse the result. You shouldn't rely on this property, but during
initial render it mostly just works. Updates are trickier, though,
because if you used an uncached promise, we have no way of knowing 
whether the underlying data has changed, so we have to unwrap the
promise every time. It will still work, but it's inefficient and can
lead to unnecessary fallbacks if it happens during a discrete update.

When we implement this for Server Components, this will be less of an
issue because there are no updates in that environment. However, it's
still better for performance to cache data requests, so the same
principles largely apply.

The intention is that this will eventually be the only supported way to
suspend on arbitrary promises. Throwing a promise directly will
be deprecated.
2022-08-25 14:12:07 -04:00
Joseph Savona
9e67e7a315
Scaffolding for useMemoCache hook (#25123)
* Scaffolding for useMemoCache hook
* cleanup leftovers from copy/paste of use() diff

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-08-23 09:36:02 +01:00
Josh Story
796d31809b
Implement basic stylesheet Resources for react-dom (#25060)
Implement basic support for "Resources". In the context of this commit, the only thing that is currently a Resource are

<link rel="stylesheet" precedence="some-value" ...>

Resources can be rendered anywhere in the react tree, even outside of normal parenting rules, for instance you can render a resource before you have rendered the <html><head> tags for your application. In the stream we reorder this so the browser always receives valid HTML and resources are emitted either in place (normal circumstances) or at the top of the <head> (when you render them above or before the <head> in your react tree)

On the client, resources opt into an entirely different hydration path. Instead of matching the location within the Document these resources are queried for in the entire document. It is an error to have more than one resource with the same href attribute.

The use of precedence here as an opt-in signal for resourcifying the link is in preparation for a more complete Resource implementation which will dedupe resource references (multiple will be valid), hoist to the appropriate container (body, head, or elsewhere), order (according to precedence) and Suspend boundaries that depend on them. More details will come in the coming weeks on this plan.

This feature is gated by an experimental flag and will only be made available in experimental builds until some future time.
2022-08-12 13:27:53 -07:00
Andrew Clark
229c86af07
Revert "Land enableClientRenderFallbackOnTextMismatch" (#24738)
This reverts commit 327e4a1f96.

Turns out we hadn't rolled this out internally yet — I mistook
enableClientRenderFallbackOnHydrationMismatch for
said enableClientRenderFallbackOnTextMismatch. Need to revert
until we finish rolling out the change.
2022-06-16 11:38:37 -04:00
Andrew Clark
327e4a1f96 [Follow-up] Land enableClientRenderFallbackOnTextMismatch
This was meant to land in the previous commit; forgot to stage the
changes when I was rebasing.
2022-06-13 12:01:44 -04:00
Andrew Clark
a8c9cb18b7
Land enableSuspenseLayoutEffectSemantics flag (#24713)
This was released to open source in 18.0 and is already hardcoded to
true in www.
2022-06-13 11:27:40 -04:00
Ricky
62662633d1
Remove enableFlipOffscreenUnhideOrder (#24545) 2022-05-12 12:40:17 -04:00
Ricky
a10a9a6b5b
Add test for hiding children after layout destroy (#24483) 2022-05-03 14:24:23 -04:00
Ricky
99eef9e2df
Hide children of Offscreen after destroy effects (#24446) 2022-05-03 10:16:53 -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
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 b5cca182ffd5500b83f20f215d0e16d6dbae0efb.
2022-04-19 17:34:30 -04:00
salazarm
6b85823b35
Clean up Selective Hydration / Event Replay flag (#24156)
* clean up selective hydration / replay flag

* dont export return_targetInst
2022-03-24 14:12:43 -04:00
David McCabe
577f2de46c
enableCacheElement flag (#24131)
* enableCacheElement flag

* Update packages/shared/forks/ReactFeatureFlags.testing.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/forks/ReactFeatureFlags.test-renderer.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/forks/ReactFeatureFlags.native-oss.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/ReactFeatureFlags.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

Co-authored-by: Dave McCabe <davemccabe@fb.com>
Co-authored-by: Ricky <rickhanlonii@gmail.com>
2022-03-20 20:41:02 -07:00
salazarm
ef23a9ee81
Flag for text hydration mismatch (#24107)
* flag for text hydration mismatch

* rm unused import
2022-03-16 10:12:59 -04:00
Sebastian Markbåge
72a933d289
Gate legacy hidden (#24047)
* Gate legacy hidden

* Gate tests

* Remove export from experimental
2022-03-09 11:48:03 -05:00
salazarm
d5f1b067c8
[ServerContext] Flight support for ServerContext (#23244)
* Flight side of server context

* 1 more test

* rm unused function

* flow+prettier

* flow again =)

* duplicate ReactServerContext across packages

* store default value when lazily initializing server context

* .

* better comment

* derp... missing import

* rm optional chaining

* missed feature flag

* React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??

* add warning if non ServerContext passed into useServerContext

* pass context in as array of arrays

* make importServerContext nott pollute the global context state

* merge main

* remove useServerContext

* dont rely on object getters in ReactServerContext and disallow JSX

* add symbols to devtools + rename globalServerContextRegistry to just ContextRegistry

* gate test case as experimental

* feedback

* remove unions

* Lint

* fix oopsies (tests/lint/mismatching arguments/signatures

* lint again

* replace-fork

* remove extraneous change

* rebase

* 1 more test

* rm unused function

* flow+prettier

* flow again =)

* duplicate ReactServerContext across packages

* store default value when lazily initializing server context

* .

* better comment

* derp... missing import

* rm optional chaining

* missed feature flag

* React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??

* add warning if non ServerContext passed into useServerContext

* pass context in as array of arrays

* make importServerContext nott pollute the global context state

* merge main

* remove useServerContext

* dont rely on object getters in ReactServerContext and disallow JSX

* add symbols to devtools + rename globalServerContextRegistry to just ContextRegistry

* gate test case as experimental

* feedback

* remove unions

* Lint

* fix oopsies (tests/lint/mismatching arguments/signatures

* lint again

* replace-fork

* remove extraneous change

* rebase

* reinline

* rebase

* add back changes lost due to rebase being hard

* emit chunk for provider

* remove case for React provider type

* update type for SomeChunk

* enable flag with experimental

* add missing types

* fix flow type

* missing type

* t: any

* revert extraneous type change

* better type

* better type

* feedback

* change import to type import

* test?

* test?

* remove react-dom

* remove react-native-renderer from react-server-native-relay/package.json

* gate change in FiberNewContext, getComponentNameFromType, use switch statement in FlightServer

* getComponentNameFromTpe: server context type gated and use displayName if available

* fallthrough

* lint....

* POP

* lint
2022-03-08 07:55:32 -05:00
Sebastian Markbåge
6edd55a3ff
Gate unstable_expectedLoadTime on enableCPUSuspense (#24038) 2022-03-08 01:33:52 -05:00
Andrew Clark
a82ef6d40b
Add back skipUnmountedBoundaries flag only for www (#23383)
There are a few internal tests that still need to be updated, so I'm
adding this flag back for www only.

The desired behavior rolled out to 10% public, so we're confident there
are no issues.

The open source behavior remains (skipUnmountedBoundaries = true).
2022-02-28 11:14:30 -05:00
Andrew Clark
a5b22155c8
Warn if renderSubtreeIntoContainer is called (#23355)
We already warn for all the other legacy APIs. Forgot to enable
this one.
2022-02-24 01:42:22 -05:00
Andrew Clark
b3f3da205b
Land warnOnSubscriptionInsideStartTransition flag (#23353)
We're including this in 18. The feature was already enabled — this just
removes the flag.
2022-02-23 18:52:08 -05:00
Andrew Clark
990098f88a
Re-arrange main ReactFeatureFlags module (#23350)
@sebmarkbage and I audited the feature flags file to review the status
of each feature or experiment. Based on that, I've added some more
comments to the main ReactFeatureFlags module and rearranged them
into groups.

I haven't changed the value of any flags, yet. There are a few we're
going to land but I'll do them as separate PRs.
2022-02-23 18:49:16 -05:00
Andrew Clark
419ccc2b19
Land skipUnmountedBoundaries experiment (#23322)
This has been rolled out to 10% of Facebook users for months without
any issues.
2022-02-17 21:43:25 -05:00
Andrew Clark
54f785bc51
Disallow comments as DOM containers for createRoot (#23321)
This is an old feature that we no longer support. `hydrateRoot` already
throws if you pass a comment node; this change makes `createRoot`
throw, too.

Still enabled in the Facebook build until we migrate the callers.
2022-02-17 16:44:22 -05:00
salazarm
3a44621296
Disable avoidThisFallback support in Fizz (#23224)
* disable fizz avoidThisFallback support

* true
2022-02-01 18:22:04 -05:00
Dan Abramov
e489402557
Warn when a callback ref returns a function (#23145) 2022-01-20 15:18:38 +00:00