Skip to content

[Fiber] Warn for Conditional Use of use() Based on Cache - #37104

Merged
hoxyq merged 1 commit into
mainfrom
reconciler/warn-conditional-use
Jul 31, 2026
Merged

[Fiber] Warn for Conditional Use of use() Based on Cache#37104
hoxyq merged 1 commit into
mainfrom
reconciler/warn-conditional-use

Conversation

@hoxyq

@hoxyq hoxyq commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

This is a cherry-pick of #34030, with a feature flag gating and a test coverage.

The flag is disabled by default and dynamic for FB builds to understand first how noisy this warning can be.


See #34030 for more context on the change.

@hoxyq
hoxyq requested review from acdlite, eps1lon and jackpope July 23, 2026 12:38
@meta-cla meta-cla Bot added the CLA Signed label Jul 23, 2026
@react-sizebot

react-sizebot commented Jul 23, 2026

Copy link
Copy Markdown

Comparing: 0f42eac...5c35f9f

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 = 7.45 kB 7.45 kB +0.05% 1.99 kB 1.99 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 616.59 kB 616.59 kB = 109.28 kB 109.28 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.46 kB 7.46 kB +0.05% 2.00 kB 2.00 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 687.80 kB 687.80 kB = 120.74 kB 120.74 kB
facebook-www/ReactDOM-prod.classic.js = 707.88 kB 707.88 kB = 124.23 kB 124.23 kB
facebook-www/ReactDOM-prod.modern.js = 698.20 kB 698.20 kB = 122.66 kB 122.66 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-www/ReactART-dev.modern.js +0.24% 779.66 kB 781.51 kB +0.38% 122.29 kB 122.75 kB
facebook-www/ReactART-dev.classic.js +0.23% 789.19 kB 791.04 kB +0.39% 124.08 kB 124.57 kB
react-native/implementations/ReactFabric-dev.fb.js +0.22% 819.92 kB 821.74 kB +0.36% 131.46 kB 131.93 kB

Generated by 🚫 dangerJS against 5c35f9f

daltino

This comment was marked as spam.

});

// @gate __DEV__ && enableConditionalUseWarning
it('warns if use(promise) is called conditionally based on a cache', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: could also use a test asserting that warning does not fire on correct usage, though thats likely covered by other use tests. And maybe rerender this at the end to make sure warning doesn't fire again.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

could also use a test asserting that warning does not fire on correct usage

That would be complicated, because our gating mechanism for tests asserts that any test run that doesn't pass the check should fail. In other words, the base scenario should fail, but this won't be true for the behavior that will be tested.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I could just remove these gating conditions

'did not call use() when it finished. This indicates an incorrect use of use(). ' +
'A common mistake is to call use() only when something is not cached.\n\n' +
' if (cache.value !== undefined) use(cache.promise) else return cache.value\n\n' +
'The correct way is to always call use() with a Promise and resolve it with the value.\n\n' +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should follow up with documenting the fulfilled optimization somewhere

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docs team added in a note about this optimization with the following pitfall.

Image

Comment thread packages/react-reconciler/src/__tests__/ActivitySuspense-test.js
@hoxyq
hoxyq force-pushed the reconciler/warn-conditional-use branch from 7de52db to b95fba5 Compare July 30, 2026 16:57
@hoxyq
hoxyq requested review from eps1lon and jackpope July 30, 2026 16:57
@hoxyq
hoxyq force-pushed the reconciler/warn-conditional-use branch from b95fba5 to 7c5c268 Compare July 30, 2026 17:13
@hoxyq
hoxyq force-pushed the reconciler/warn-conditional-use branch from 7c5c268 to fa0f78d Compare July 30, 2026 20:55
@hoxyq
hoxyq requested a review from eps1lon July 30, 2026 20:56
@hoxyq

hoxyq commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

@eps1lon Had a merge conflict, need a stamp again :(

Comment on lines +331 to +335
lastSuspendedStack = new Error(
'This library called use() to suspend in a previous render but ' +
'did not call use() when it finished. This indicates an incorrect use of use(). ' +
'Learn more: https://react.dev/warnings/conditional-use-of-use.',
);

@hoxyq hoxyq Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Amended warning message, added a link to docs. See reactjs/react.dev#8567.

Comment thread packages/react-reconciler/src/ReactFiberThenable.js Outdated
Comment thread scripts/error-codes/codes.json Outdated
@hoxyq
hoxyq force-pushed the reconciler/warn-conditional-use branch from 9a87d38 to 5c35f9f Compare July 31, 2026 12:41
@hoxyq
hoxyq requested a review from eps1lon July 31, 2026 12:46
@hoxyq
hoxyq merged commit cbb046a into main Jul 31, 2026
238 checks passed
@hoxyq
hoxyq deleted the reconciler/warn-conditional-use branch July 31, 2026 14:24
github-actions Bot pushed a commit that referenced this pull request Jul 31, 2026
This is a cherry-pick of #34030, with
a feature flag gating and a test coverage.

The flag is disabled by default and dynamic for FB builds to understand
first how noisy this warning can be.

---

See #34030 for more context on the
change.

DiffTrain build for [cbb046a](cbb046a)
github-actions Bot pushed a commit that referenced this pull request Jul 31, 2026
This is a cherry-pick of #34030, with
a feature flag gating and a test coverage.

The flag is disabled by default and dynamic for FB builds to understand
first how noisy this warning can be.

---

See #34030 for more context on the
change.

DiffTrain build for [cbb046a](cbb046a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants