Skip to content

Current behavior for use resulting in stuck isPending - #29209

Closed
eps1lon wants to merge 1 commit into
react:mainfrom
eps1lon:sebbie/use-pending-stuck
Closed

Current behavior for use resulting in stuck isPending#29209
eps1lon wants to merge 1 commit into
react:mainfrom
eps1lon:sebbie/use-pending-stuck

Conversation

@eps1lon

@eps1loneps1lon commented May 22, 2024

Copy link
Copy Markdown
Collaborator

Summary

Test reproducing #28923

How did you test this change?

  • yarn test --watch packages/react-reconciler/src/__tests__/ReactUse-test.js -t "does not get stuck in pending state with usable values in state"

@vercel

vercelBot commented May 22, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

NameStatusPreviewCommentsUpdated (UTC)
react-compiler-playground✅ Ready (Inspect)Visit Preview💬 Add feedbackMay 22, 2024 11:20am

@facebook-github-botfacebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels May 22, 2024
'Value: initial, Pending: true',
'Value: updated, Pending: true',
]);
expect(root).toMatchRenderedOutput('Value: updated, Pending: true');

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We commit the value from the updated, resolved promise but don't flip isPending.

@eps1lon
eps1lonforce-pushed the sebbie/use-pending-stuck branch from 7b020c0 to 35b8802CompareMay 22, 2024 11:13
@react-sizebot

Copy link
Copy Markdown

Comparing: 81c5ff2...35b8802

Critical size changes

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

Name+/-BaseCurrent+/- gzipBase gzipCurrent gzip
oss-stable/react-dom/cjs/react-dom.production.js=6.66 kB6.66 kB+0.11%1.82 kB1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js=495.89 kB495.89 kB=88.82 kB88.83 kB
oss-experimental/react-dom/cjs/react-dom.production.js=6.67 kB6.67 kB+0.11%1.83 kB1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js=500.69 kB500.69 kB=89.51 kB89.51 kB
facebook-www/ReactDOM-prod.classic.js=593.05 kB593.05 kB=104.32 kB104.32 kB
facebook-www/ReactDOM-prod.modern.js=569.27 kB569.27 kB=100.72 kB100.72 kB
test_utils/ReactAllWarnings.jsDeleted64.35 kB0.00 kBDeleted16.05 kB0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name+/-BaseCurrent+/- gzipBase gzipCurrent gzip
test_utils/ReactAllWarnings.jsDeleted64.35 kB0.00 kBDeleted16.05 kB0.00 kB

Generated by 🚫 dangerJS against 35b8802

Comment on lines +1930 to +1933
const [isPending, startLocalTransition] = useTransition();
click = () => {
startLocalTransition(() => {
setPromise(

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Suggested change
const[isPending,startLocalTransition]=useTransition();
click=()=>{
startLocalTransition(()=>{
setPromise(
const[isPending,setIsPending]=useOptimistic(false);
click=()=>{
startTransition(()=>{
setIsPending(true);
setPromise(

does work.

acdlite added a commit that referenced this pull request May 31, 2024
When a component suspends with `use`, we switch to the "re-render"
dispatcher during the subsequent render attempt, so that we can reuse
the work from the initial attempt. However, once we run out of hooks
from the previous attempt, we should switch back to the regular "update"
dispatcher.
This is conceptually the same fix as the one introduced in
#26232. That fix only accounted
for initial mount, but the useTransition regression test added in
f829733 illustrates that we need to
handle updates, too.
The issue affects more than just useTransition but because most of the
behavior between the "re-render" and "update" dispatchers is the same
it's hard to contrive other scenarios in a test, which is probably why
it took so long for someone to notice.
Closes#28923 and #29209
---------
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
github-actionsBot pushed a commit that referenced this pull request May 31, 2024
When a component suspends with `use`, we switch to the "re-render"
dispatcher during the subsequent render attempt, so that we can reuse
the work from the initial attempt. However, once we run out of hooks
from the previous attempt, we should switch back to the regular "update"
dispatcher.
This is conceptually the same fix as the one introduced in
#26232. That fix only accounted
for initial mount, but the useTransition regression test added in
f829733 illustrates that we need to
handle updates, too.
The issue affects more than just useTransition but because most of the
behavior between the "re-render" and "update" dispatchers is the same
it's hard to contrive other scenarios in a test, which is probably why
it took so long for someone to notice.
Closes#28923 and #29209
---------
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
DiffTrain build for [adbec0c](adbec0c)
github-actionsBot pushed a commit that referenced this pull request May 31, 2024
When a component suspends with `use`, we switch to the "re-render"
dispatcher during the subsequent render attempt, so that we can reuse
the work from the initial attempt. However, once we run out of hooks
from the previous attempt, we should switch back to the regular "update"
dispatcher.
This is conceptually the same fix as the one introduced in
#26232. That fix only accounted
for initial mount, but the useTransition regression test added in
f829733 illustrates that we need to
handle updates, too.
The issue affects more than just useTransition but because most of the
behavior between the "re-render" and "update" dispatchers is the same
it's hard to contrive other scenarios in a test, which is probably why
it took so long for someone to notice.
Closes#28923 and #29209
---------
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
DiffTrain build for commit adbec0c.
@eps1lon

Copy link
Copy Markdown
CollaboratorAuthor

Fixed in #29670

@eps1loneps1lon closed this Jun 2, 2024
@eps1lon
eps1lon deleted the sebbie/use-pending-stuck branch June 3, 2024 09:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedReact Core TeamOpened by a member of the React Core TeamReact 19

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@eps1lon@react-sizebot@facebook-github-bot