Skip to content

[refactor] Add element type for Activity #32499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 17, 2025

Conversation

rickhanlonii
Copy link
Member

This PR separates Activity to it's own element type separate from Offscreen. The goal is to allow us to add Activity element boundary semantics during hydration similar to Suspense semantics, without impacting the Offscreen behavior in suspended children.

@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Mar 2, 2025
mode,
renderLanes,
);
primaryChildFragment.ref = workInProgress.ref;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebmarkbage currently I'm just forwarding the ref to the Offscreen element child, and not changing how manual mode works. As a follow up, should we make it so the ref is only exposed to the Activity element, which finds the Offscreen child to toggle visibility?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed manual mode in #32645

@react-sizebot
Copy link

react-sizebot commented Mar 2, 2025

Comparing: 99563e9...4deadd5

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.26% 516.17 kB 517.50 kB +0.18% 92.15 kB 92.31 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.22% 604.42 kB 605.76 kB +0.15% 107.31 kB 107.47 kB
facebook-www/ReactDOM-prod.classic.js +0.20% 649.90 kB 651.19 kB +0.14% 114.56 kB 114.73 kB
facebook-www/ReactDOM-prod.modern.js +0.19% 640.22 kB 641.47 kB +0.12% 113.00 kB 113.14 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-is/cjs/react-is.production.js +1.97% 4.57 kB 4.66 kB +1.91% 1.10 kB 1.12 kB
oss-stable/react-is/cjs/react-is.production.js +1.97% 4.57 kB 4.66 kB +1.91% 1.10 kB 1.12 kB
oss-experimental/react-is/cjs/react-is.production.js +1.95% 4.61 kB 4.70 kB +1.81% 1.11 kB 1.13 kB
oss-stable-semver/react-is/cjs/react-is.development.js +1.91% 5.12 kB 5.22 kB +1.56% 1.15 kB 1.17 kB
oss-stable/react-is/cjs/react-is.development.js +1.91% 5.12 kB 5.22 kB +1.56% 1.15 kB 1.17 kB
oss-experimental/react-is/cjs/react-is.development.js +1.90% 5.17 kB 5.26 kB +1.73% 1.16 kB 1.18 kB
facebook-react-native/react-is/cjs/ReactIs-prod.js +1.89% 4.77 kB 4.86 kB +1.79% 1.17 kB 1.19 kB
facebook-react-native/react-is/cjs/ReactIs-profiling.js +1.89% 4.77 kB 4.86 kB +1.79% 1.17 kB 1.19 kB
facebook-react-native/react-is/cjs/ReactIs-dev.js +1.85% 5.31 kB 5.41 kB +1.58% 1.20 kB 1.22 kB
facebook-www/ReactIs-prod.classic.js +1.50% 5.99 kB 6.08 kB +1.44% 1.39 kB 1.41 kB
facebook-www/ReactIs-prod.modern.js +1.50% 5.99 kB 6.08 kB +1.44% 1.39 kB 1.41 kB
facebook-www/ReactIs-dev.classic.js +1.49% 6.59 kB 6.69 kB +1.41% 1.42 kB 1.44 kB
facebook-www/ReactIs-dev.modern.js +1.49% 6.59 kB 6.69 kB +1.41% 1.42 kB 1.44 kB
oss-stable-semver/react/cjs/react-jsx-dev-runtime.development.js +1.09% 11.12 kB 11.24 kB +0.93% 3.11 kB 3.14 kB
oss-stable/react/cjs/react-jsx-dev-runtime.development.js +1.09% 11.12 kB 11.24 kB +0.93% 3.11 kB 3.14 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.development.js +1.07% 11.27 kB 11.39 kB +0.89% 3.15 kB 3.18 kB
oss-stable-semver/react/cjs/react-jsx-runtime.development.js +1.07% 11.32 kB 11.44 kB +0.93% 3.13 kB 3.16 kB
oss-stable/react/cjs/react-jsx-runtime.development.js +1.07% 11.32 kB 11.44 kB +0.93% 3.13 kB 3.16 kB
facebook-react-native/react/cjs/JSXDEVRuntime-dev.js +1.07% 11.34 kB 11.46 kB +0.92% 3.15 kB 3.18 kB
oss-experimental/react/cjs/react-jsx-runtime.development.js +1.06% 11.47 kB 11.59 kB +0.88% 3.17 kB 3.20 kB
facebook-react-native/react/cjs/JSXRuntime-dev.js +1.05% 11.54 kB 11.66 kB +0.91% 3.17 kB 3.20 kB
oss-stable-semver/react/cjs/react-jsx-runtime.react-server.development.js +1.01% 11.94 kB 12.06 kB +0.95% 3.25 kB 3.28 kB
oss-stable/react/cjs/react-jsx-runtime.react-server.development.js +1.01% 11.94 kB 12.06 kB +0.95% 3.25 kB 3.28 kB
oss-stable-semver/react/cjs/react-jsx-dev-runtime.react-server.development.js +1.01% 11.95 kB 12.07 kB +0.92% 3.26 kB 3.29 kB
oss-stable/react/cjs/react-jsx-dev-runtime.react-server.development.js +1.01% 11.95 kB 12.07 kB +0.92% 3.26 kB 3.29 kB
oss-experimental/react/cjs/react-jsx-runtime.react-server.development.js +1.00% 12.09 kB 12.21 kB +0.88% 3.30 kB 3.32 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.react-server.development.js +1.00% 12.09 kB 12.21 kB +0.88% 3.30 kB 3.33 kB
facebook-www/JSXDEVRuntime-dev.classic.js +0.96% 12.64 kB 12.76 kB +0.85% 3.42 kB 3.45 kB
facebook-www/JSXDEVRuntime-dev.modern.js +0.96% 12.64 kB 12.76 kB +0.85% 3.42 kB 3.45 kB
oss-stable-semver/react/cjs/react.react-server.development.js +0.56% 28.84 kB 29.00 kB +0.51% 6.91 kB 6.95 kB
oss-stable/react/cjs/react.react-server.development.js +0.56% 28.86 kB 29.02 kB +0.49% 6.94 kB 6.97 kB
oss-experimental/react/cjs/react.react-server.development.js +0.45% 35.90 kB 36.06 kB +0.46% 8.48 kB 8.51 kB
oss-stable-semver/react-art/cjs/react-art.production.js +0.44% 301.42 kB 302.75 kB +0.31% 51.32 kB 51.47 kB
oss-stable/react-art/cjs/react-art.production.js +0.44% 301.49 kB 302.83 kB +0.31% 51.34 kB 51.50 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js +0.43% 334.29 kB 335.73 kB +0.33% 58.34 kB 58.54 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.js +0.43% 313.54 kB 314.87 kB +0.29% 55.04 kB 55.20 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.js +0.43% 313.61 kB 314.95 kB +0.29% 55.06 kB 55.22 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.js +0.43% 313.79 kB 315.12 kB +0.29% 55.09 kB 55.25 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js +0.40% 356.47 kB 357.91 kB +0.31% 61.52 kB 61.71 kB
oss-experimental/react-art/cjs/react-art.production.js +0.40% 334.70 kB 336.04 kB +0.26% 56.64 kB 56.79 kB
react-native/implementations/ReactFabric-prod.js +0.39% 359.20 kB 360.59 kB +0.28% 62.51 kB 62.69 kB
react-native/implementations/ReactNativeRenderer-prod.js +0.38% 366.40 kB 367.79 kB +0.27% 63.62 kB 63.79 kB
react-native/implementations/ReactFabric-prod.fb.js +0.38% 381.22 kB 382.65 kB +0.28% 66.25 kB 66.44 kB
react-native/implementations/ReactNativeRenderer-prod.fb.js +0.37% 384.73 kB 386.16 kB +0.29% 66.87 kB 67.07 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.production.js +0.37% 391.81 kB 393.25 kB +0.29% 63.62 kB 63.80 kB
oss-stable/react-reconciler/cjs/react-reconciler.production.js +0.37% 391.83 kB 393.28 kB +0.29% 63.64 kB 63.82 kB
react-native/implementations/ReactFabric-profiling.js +0.37% 384.44 kB 385.84 kB +0.28% 66.22 kB 66.40 kB
oss-stable-semver/react/cjs/react.development.js +0.36% 45.18 kB 45.34 kB +0.31% 10.26 kB 10.29 kB
oss-stable/react/cjs/react.development.js +0.36% 45.21 kB 45.37 kB +0.33% 10.28 kB 10.32 kB
react-native/implementations/ReactNativeRenderer-profiling.js +0.36% 391.75 kB 393.14 kB +0.27% 67.41 kB 67.60 kB
react-native/implementations/ReactNativeRenderer-profiling.fb.js +0.36% 410.21 kB 411.67 kB +0.28% 70.71 kB 70.92 kB
react-native/implementations/ReactFabric-profiling.fb.js +0.35% 406.73 kB 408.16 kB +0.28% 70.13 kB 70.33 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.profiling.js +0.35% 418.00 kB 419.44 kB +0.30% 67.27 kB 67.47 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.js +0.35% 418.02 kB 419.47 kB +0.30% 67.29 kB 67.50 kB
oss-experimental/react/cjs/react.development.js +0.34% 46.95 kB 47.11 kB +0.29% 10.65 kB 10.68 kB
facebook-www/ReactART-prod.classic.js +0.33% 385.10 kB 386.39 kB +0.28% 64.70 kB 64.88 kB
facebook-www/ReactART-prod.modern.js +0.33% 375.15 kB 376.40 kB +0.25% 63.09 kB 63.25 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.js +0.32% 458.15 kB 459.60 kB +0.23% 73.60 kB 73.77 kB
facebook-react-native/react/cjs/React-dev.js +0.31% 51.21 kB 51.37 kB +0.28% 11.41 kB 11.44 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js +0.29% 511.11 kB 512.60 kB +0.24% 81.52 kB 81.72 kB
facebook-www/React-dev.modern.js +0.29% 55.41 kB 55.57 kB +0.26% 12.07 kB 12.10 kB
facebook-www/React-dev.classic.js +0.29% 55.41 kB 55.57 kB +0.26% 12.07 kB 12.10 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js +0.28% 557.87 kB 559.44 kB +0.21% 90.62 kB 90.82 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js +0.28% 557.90 kB 559.47 kB +0.21% 90.64 kB 90.83 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js +0.28% 557.95 kB 559.51 kB +0.21% 90.65 kB 90.84 kB
oss-stable-semver/react-art/cjs/react-art.development.js +0.28% 558.83 kB 560.40 kB +0.23% 89.93 kB 90.14 kB
oss-stable/react-art/cjs/react-art.development.js +0.28% 558.91 kB 560.47 kB +0.23% 89.96 kB 90.16 kB
facebook-www/ReactTestRenderer-dev.modern.js +0.27% 575.83 kB 577.39 kB +0.20% 93.72 kB 93.90 kB
facebook-www/ReactTestRenderer-dev.classic.js +0.27% 575.83 kB 577.40 kB +0.20% 93.72 kB 93.90 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js +0.27% 598.82 kB 600.45 kB +0.23% 96.51 kB 96.73 kB
facebook-www/ReactReconciler-prod.classic.js +0.27% 500.72 kB 502.08 kB +0.23% 80.19 kB 80.37 kB
facebook-www/ReactReconciler-prod.modern.js +0.27% 490.46 kB 491.77 kB +0.21% 78.60 kB 78.76 kB
facebook-react-native/react-dom/cjs/ReactDOMClient-prod.js +0.26% 544.08 kB 545.51 kB +0.20% 96.68 kB 96.87 kB
facebook-react-native/react-dom/cjs/ReactDOMProfiling-prod.js +0.26% 549.58 kB 551.02 kB +0.19% 97.75 kB 97.94 kB
oss-stable-semver/react-dom/cjs/react-dom-client.production.js +0.26% 516.04 kB 517.38 kB +0.18% 92.12 kB 92.28 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.26% 516.17 kB 517.50 kB +0.18% 92.15 kB 92.31 kB
react-native/implementations/ReactFabric-dev.js +0.25% 640.51 kB 642.13 kB +0.22% 104.54 kB 104.77 kB
facebook-react-native/react-dom/cjs/ReactDOMClient-profiling.js +0.25% 568.94 kB 570.37 kB +0.20% 100.41 kB 100.61 kB
react-native/implementations/ReactNativeRenderer-dev.js +0.25% 648.88 kB 650.50 kB +0.23% 105.88 kB 106.12 kB
facebook-react-native/react-dom/cjs/ReactDOMProfiling-profiling.js +0.25% 574.88 kB 576.31 kB +0.19% 101.57 kB 101.76 kB
oss-experimental/react-art/cjs/react-art.development.js +0.25% 629.75 kB 631.31 kB +0.20% 99.91 kB 100.11 kB
oss-stable-semver/react-dom/cjs/react-dom-profiling.profiling.js +0.24% 546.45 kB 547.78 kB +0.17% 96.82 kB 96.98 kB
oss-stable/react-dom/cjs/react-dom-profiling.profiling.js +0.24% 546.57 kB 547.91 kB +0.17% 96.85 kB 97.01 kB
react-native/implementations/ReactFabric-dev.fb.js +0.24% 670.95 kB 672.58 kB +0.18% 109.14 kB 109.34 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js +0.24% 646.09 kB 647.65 kB +0.23% 103.05 kB 103.29 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js +0.24% 646.11 kB 647.68 kB +0.23% 103.08 kB 103.31 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js +0.24% 675.72 kB 677.35 kB +0.21% 109.99 kB 110.22 kB
facebook-www/ReactART-dev.modern.js +0.22% 699.51 kB 701.07 kB +0.18% 109.37 kB 109.56 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.22% 604.42 kB 605.76 kB +0.15% 107.31 kB 107.47 kB
facebook-www/ReactART-dev.classic.js +0.22% 709.01 kB 710.57 kB +0.19% 111.21 kB 111.42 kB
facebook-www/ReactReconciler-dev.modern.js +0.22% 808.46 kB 810.23 kB +0.55% 125.62 kB 126.31 kB
facebook-www/ReactReconciler-dev.classic.js +0.22% 817.67 kB 819.44 kB +0.54% 127.29 kB 127.98 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.production.js +0.22% 619.15 kB 620.48 kB +0.15% 110.91 kB 111.08 kB
oss-experimental/react-dom/cjs/react-dom-profiling.profiling.js +0.21% 659.83 kB 661.20 kB +0.15% 116.02 kB 116.19 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.21% 754.25 kB 755.82 kB +0.17% 118.65 kB 118.85 kB

Generated by 🚫 dangerJS against 6db24d0

key: null | string,
): Fiber {
const fiber = createFiber(ActivityComponent, pendingProps, key, mode);
fiber.elementType = REACT_ACTIVITY_TYPE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually right. This was wrong for Offscreen too.

In the case of const LazyActivity = React.lazy(async () => ({ default: React.Activity })); <LazyActivity /> the elementType should be the Lazy wrapper object. Otherwise reconciliation won't work correctly.

In fact, it looks like we get this wrong for all these built-ins so wrapping them would yield the wrong reconciliation.

So it's an existing bug that we need to fix separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this wrong for REACT_VIEW_TRANSITION_TYPE too?

What's the fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we throw for this case already with an error that says:

Caution

Element type is invalid. Received a promise that resolves to: ViewTransition. Lazy element type must resolve to a class or function.

This is broken for portal, so I fixed it and tested all the built-ins here: #32640

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is landable as is but spawns many follow ups from my comments.

rickhanlonii referenced this pull request Mar 15, 2025
Just adding the name so it shows up.

(Note that no experimental ones are added to the list of filters atm.
Including SuspenseList etc.)
@rickhanlonii
Copy link
Member Author

rickhanlonii commented Mar 16, 2025

Pushed some fixes for owner stacks and devtools. I decided to include those here so we can reference one PR with the changes needed to add a new element, instead of splitting it out.

In followups I'll:

@rickhanlonii rickhanlonii merged commit 1a19170 into facebook:main Mar 17, 2025
194 checks passed
@rickhanlonii rickhanlonii deleted the rh/activity-element branch March 17, 2025 13:17
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
This PR separates Activity to it's own element type separate from
Offscreen. The goal is to allow us to add Activity element boundary
semantics during hydration similar to Suspense semantics, without
impacting the Offscreen behavior in suspended children.

DiffTrain build for [1a19170](1a19170)
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
This PR separates Activity to it's own element type separate from
Offscreen. The goal is to allow us to add Activity element boundary
semantics during hydration similar to Suspense semantics, without
impacting the Offscreen behavior in suspended children.

DiffTrain build for [1a19170](1a19170)
rickhanlonii added a commit that referenced this pull request Mar 17, 2025
Based off #32499

This is no longer used.

[Review
commit](88c297d)
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
Based off #32499

This is no longer used.

[Review
commit](88c297d)

DiffTrain build for [df31952](df31952)
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
Based off #32499

This is no longer used.

[Review
commit](88c297d)

DiffTrain build for [df31952](df31952)
rickhanlonii added a commit that referenced this pull request Mar 17, 2025
Based off: #32499

While looking into `React.lazy` issues for built-ins, I noticed we
already error for `lazy` with build-ins, but we don't have any tests for
`getComponentNameFromType` using all the built-ins. This may be
something we should handle, but for now we should at least have tests.

Here's why: while writing tests, I noticed we check `type` instead of
`$$typeof` for portals:


https://github.com/facebook/react/blob/9cdf8a99edcfd94d7420835ea663edca04237527/packages/react-reconciler/src/ReactPortal.js#L25-L32

This PR adds tests for all the built-ins and fixes the portal bug.

[Commit to
review](e068c16)
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
Based off: #32499

While looking into `React.lazy` issues for built-ins, I noticed we
already error for `lazy` with build-ins, but we don't have any tests for
`getComponentNameFromType` using all the built-ins. This may be
something we should handle, but for now we should at least have tests.

Here's why: while writing tests, I noticed we check `type` instead of
`$$typeof` for portals:

https://github.com/facebook/react/blob/9cdf8a99edcfd94d7420835ea663edca04237527/packages/react-reconciler/src/ReactPortal.js#L25-L32

This PR adds tests for all the built-ins and fixes the portal bug.

[Commit to
review](e068c16)

DiffTrain build for [8243f3f](8243f3f)
github-actions bot pushed a commit that referenced this pull request Mar 17, 2025
Based off: #32499

While looking into `React.lazy` issues for built-ins, I noticed we
already error for `lazy` with build-ins, but we don't have any tests for
`getComponentNameFromType` using all the built-ins. This may be
something we should handle, but for now we should at least have tests.

Here's why: while writing tests, I noticed we check `type` instead of
`$$typeof` for portals:

https://github.com/facebook/react/blob/9cdf8a99edcfd94d7420835ea663edca04237527/packages/react-reconciler/src/ReactPortal.js#L25-L32

This PR adds tests for all the built-ins and fixes the portal bug.

[Commit to
review](e068c16)

DiffTrain build for [8243f3f](8243f3f)
rickhanlonii added a commit that referenced this pull request Mar 21, 2025
Followup from #32499

Manual mode is unused and has some bugs such as revealing hidden
boundaries when manually toggling. We also want to change how manual
mode works, and do some refactors to Activity to make it easier to
support. For now we'll remove it, then add it back after the other
changes we have planned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants