Skip to content

Unify serverAct helpers #33327

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 6 commits into from
May 21, 2025
Merged

Unify serverAct helpers #33327

merged 6 commits into from
May 21, 2025

Conversation

sebmarkbage
Copy link
Collaborator

This uses the richer serverAct helper that we already use in other tests.

This avoids using the Scheduler. We don't use that package on the server so it doesn't make sense to simulate going through it. Additionally, we really should be getting rid of it on the client too to favor postTask polyfills.

@sebmarkbage sebmarkbage requested a review from gnoff May 21, 2025 19:00
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label May 21, 2025
// those will also fire now, too, which is not ideal. (The public
// version of `act` doesn't do this.) For this reason, we should try
// to avoid using timers in our internal tests.
j.runAllTicks();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getTimerCount() includes process.nextTick mocks but runOnlyPendingTimers() alone doesn't run them. We don't use it ourselves but JSDOM uses it internally. This was driving me insane debugging this infinite loop.

Copy link
Collaborator

Choose a reason for hiding this comment

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

should we waitForMicrotasks here before running timers. that probably more closely approximates a real loop

Copy link
Collaborator

Choose a reason for hiding this comment

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

could continue the loop if runAllTicks changes the timer count. It's unfortunate you can't know if ticks ran. unless there isa. getTickCount or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically yes, but we also don't wait between multiple timers or multiple ticks.

What we really want is the runAllTimersAsync() but for whatever reason that's not available on the legacy mocks. I guess we'd have to upgrade to newer mock timers.

@react-sizebot
Copy link

react-sizebot commented May 21, 2025

Comparing: 3710c4d...30dafe0

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 = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 529.83 kB 529.83 kB = 93.52 kB 93.52 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 651.73 kB 651.57 kB = 114.81 kB 114.78 kB
facebook-www/ReactDOM-prod.classic.js = 676.00 kB 675.81 kB = 118.91 kB 118.87 kB
facebook-www/ReactDOM-prod.modern.js = 666.28 kB 666.09 kB = 117.30 kB 117.26 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 30dafe0

These are not flushed by runOnlyPendingTimers but are included in the
fake timer count so this would infinite loop as soon as you had a tick.
// those will also fire now, too, which is not ideal. (The public
// version of `act` doesn't do this.) For this reason, we should try
// to avoid using timers in our internal tests.
j.runAllTicks();
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we waitForMicrotasks here before running timers. that probably more closely approximates a real loop

// those will also fire now, too, which is not ideal. (The public
// version of `act` doesn't do this.) For this reason, we should try
// to avoid using timers in our internal tests.
j.runAllTicks();
Copy link
Collaborator

Choose a reason for hiding this comment

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

could continue the loop if runAllTicks changes the timer count. It's unfortunate you can't know if ticks ran. unless there isa. getTickCount or something

@sebmarkbage sebmarkbage merged commit 1c43d0a into facebook:main May 21, 2025
240 checks passed
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