Skip to content

VideoPress: fix runaway render loop on admin library pagination#48411

Merged
obenland merged 3 commits into
trunkfrom
fix/videopress-admin-render-loop
Apr 30, 2026
Merged

VideoPress: fix runaway render loop on admin library pagination#48411
obenland merged 3 commits into
trunkfrom
fix/videopress-admin-render-loop

Conversation

@obenland
Copy link
Copy Markdown
Member

Fixes #48408

Proposed changes

  • Extract useDashboardVideos from admin-page/index.tsx to projects/packages/videopress/src/client/admin/hooks/use-dashboard-videos/, matching the project's convention for hooks and decoupling it from the heavy admin-page UI imports so it can be unit-tested in isolation.
  • Remove tempPage.current from the URL/store sync useEffect's dependency array. Refs do not participate in re-render scheduling; including .current while the same effect mutates it caused the effect to alternate between its two branches indefinitely on every re-render.
  • Replace the per-render Array(n).fill({}).map(() => ({ id: uid() })) placeholder with a useMemo keyed on the inputs that determine count, using deterministic placeholder-{i} IDs so children's useEffect/useMemo deps stop seeing fresh references every render.
  • Add 4 unit tests covering both regressions and pinning down the surviving URL/store sync behaviour (URL reset on total === 0, URL push after store-side page change).

Together these stop the ~12k commits/sec render storm reported on WP 7.0-Beta admin pagination, which was starving the REST .then() handler of microtask slots and leaving the library stuck on skeleton placeholders.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  1. Spin up an Atomic site (or other WP install) running WP 7.0-Beta with the VideoPress plugin and a library of ~200+ videos.
  2. Navigate to /wp-admin/admin.php?page=jetpack-videopress and wait for page 1 thumbnails to load fully.
  3. Open DevTools → Console and paste the commit-counter snippet from issue VideoPress admin library page enters runaway render loop on client-side pagination WP7 issue #48408 (the __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot version, or the MutationObserver fallback).
  4. Click a pagination control other than page 1 (page 5 was the canonical repro).
  5. Expected: skeleton grid resolves to thumbnails within ~1 s, and the commit counter shows fewer than ~30 commits per pagination click — not the previously-observed 12,000+/sec sustained for minutes.
  6. Verify direct-URL pagination (e.g. ?paged=5) still works.
  7. Smoke test on WP 6.9.x to confirm no regression on the previously-working path.
  8. Run unit tests: pnpm jest --testPathPatterns='use-dashboard-videos' from projects/packages/videopress/ — 4 tests should pass.

The admin-page useDashboardVideos hook had two anti-patterns that, on
WP 7.0-Beta sites, combined into a sustained ~12k commits/sec loop after
clicking pagination, starving the REST .then() handler of microtask slots.

- Extract useDashboardVideos to projects/packages/videopress/src/client/
  admin/hooks/use-dashboard-videos/ to match project convention and to
  decouple it from the heavy admin-page UI imports for unit testing.
- Drop tempPage.current from the URL/store sync useEffect deps array.
  Refs do not participate in re-render scheduling; including .current
  while mutating it inside the effect made it re-fire indefinitely.
- Replace the per-render uid() placeholder array with a useMemo of
  deterministic placeholder-{i} ids so child keys stay stable across
  renders while isFetching.

Adds 4 tests covering the two regressions and the surviving sync logic.

Fixes #48408
Copilot AI review requested due to automatic review settings April 30, 2026 13:16
@obenland obenland added [Status] Needs Review This PR is ready for review. [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. labels Apr 30, 2026
@obenland obenland self-assigned this Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/videopress-admin-render-loop branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/videopress-admin-render-loop

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Videopress plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a severe React render storm on the VideoPress admin library pagination path (notably on WordPress 7.0-beta), by stabilizing URL/store sync behavior and preventing placeholder list churn during fetches.

Changes:

  • Extracts useDashboardVideos into a dedicated hook module to decouple it from the admin page component and enable isolated unit testing.
  • Fixes the URL/store pagination sync effect by removing a mutable ref (tempPage.current) from the effect dependency array to prevent oscillation.
  • Stabilizes loading placeholders via useMemo and deterministic IDs, and adds unit tests to cover the regressions and expected sync behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
projects/packages/videopress/src/client/admin/hooks/use-dashboard-videos/index.ts New extracted hook implementing the pagination URL/store sync fix and stable placeholders.
projects/packages/videopress/src/client/admin/hooks/use-dashboard-videos/test/index.test.ts Adds unit tests covering the prior render-loop triggers and expected URL/store sync behavior.
projects/packages/videopress/src/client/admin/components/admin-page/index.tsx Switches the admin page to consume the extracted useDashboardVideos hook and removes inlined hook logic.
projects/packages/videopress/changelog/fix-videopress-admin-render-loop Adds a changelog entry documenting the pagination render-loop fix.

Comment thread projects/packages/videopress/src/client/admin/hooks/use-dashboard-videos/index.ts Outdated
`parseInt(getParam('page', '1'))` returns NaN when the URL has a
non-numeric `?page=` value. The total>0 bounds check did not catch this
(every comparison with NaN is false), so the page-sync branch could
dispatch `setVideosQuery({ page: NaN })`. Pass an explicit radix and
fall back to 1 when the parsed value is NaN, and add a regression test
exercising `?page=foo`.
- Trim two verbose multi-line comments down to one line each.
- Use `??` so the items spread isn't computed when placeholders are active.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/videopress/src/client/admin/components/admin-page/index.tsx 0/24 (0.00%) 0.00% -44 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/videopress/src/client/admin/hooks/use-dashboard-videos/index.ts 37/47 (78.72%) 💚

Full summary · PHP report · JS report

@gin0115
Copy link
Copy Markdown

gin0115 commented Apr 30, 2026

wow that was fast, thanks :)

@obenland obenland merged commit 7b9e261 into trunk Apr 30, 2026
74 checks passed
@obenland obenland deleted the fix/videopress-admin-render-loop branch April 30, 2026 16:08
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Apr 30, 2026
@obenland obenland added this to the jetpack/15.8 milestone Apr 30, 2026
Copilot AI pushed a commit to dognose24/jetpack that referenced this pull request May 4, 2026
…mattic#48411)

Co-authored-by: dognose24 <6869813+dognose24@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] VideoPress [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VideoPress admin library page enters runaway render loop on client-side pagination WP7 issue

3 participants