Skip to content

Conversation

@userquin
Copy link
Contributor

@userquin userquin commented Feb 9, 2026

From time to time my chrome browser hangs, disabling view transitions seems to fix the issue and so I asked Gemini PRO, the issue is gone on my local applying the suggestion, here the reasoning:

Analysis of the View Transitions Deadlock

This PR fixes a critical browser freeze issue caused by a promise deadlock within the View Transitions plugin.

The Flow & The Deadlock

  1. router.beforeResolve is triggered. It creates a ready promise and returns it. Vue Router pauses navigation until this promise resolves.
  2. document.startViewTransition(callback) is called. The browser captures the current state (screenshot) and then executes the callback.
  3. Inside the callback:
    • changeRoute() is called, which resolves the ready promise.
    • The callback returns a promise that waits for finishTransition (triggered by page:finish).
  4. The Deadlock:
    • Vue Router awaits ready.
    • ready resolves inside the startViewTransition callback.
    • Crucially, if document.startViewTransition throws an error synchronously (e.g., if a transition is already active or invalid) or if the browser delays the callback execution unexpectedly while the main thread is blocked waiting for the router, changeRoute() is never called.
    • Result: beforeResolve hangs indefinitely, freezing the application navigation.

The Fix

We wrapped the transition logic in a try/catch block and improved state management:

  1. Error Handling: If document.startViewTransition fails, we immediately call changeRoute() and finishTransition() in the catch block to ensure the router is unblocked.
  2. Lifecycle Management: We moved resetTransitionState to transition.finished.finally(...). This ensures cleanup happens reliably whether the transition completes, is skipped, or fails, avoiding race conditions where state might be cleared prematurely.

Analysis generated with AI assistance.

@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 9, 2026 2:05pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 9, 2026 2:05pm
npmx-lunaria Ignored Ignored Feb 9, 2026 2:05pm

Request Review

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/plugins/view-transitions.client.ts 0.00% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

The plugin app/plugins/view-transitions.client.ts now wraps document.startViewTransition in a try/catch. On success it starts the transition, awaits the page:view-transition:start hook, returns the transition promise and wires transition.finished to a finally handler to reset state. On failure it logs the error, invokes changeRoute(), completes finishTransition, and calls resetTransitionState. changeRoute is initialised to ensure a defined function before use. The page:finish hook no longer auto-resets state and relies on transition.finished for reset.

Possibly related PRs

Suggested reviewers

  • serhalp
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining a deadlock issue in view transitions and how the changes fix it.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@danielroe
Copy link
Member

can you reproduce the bug?

@userquin
Copy link
Contributor Author

userquin commented Feb 9, 2026

can you reproduce the bug?

it is hard, since it happens from time to time when navigating to some package page, on local dev or npmx.dev or pr preview (maybe a page refresh, maybe when searching (a lot of _payload.json?dev requests network errors))

@carwack
Copy link
Contributor

carwack commented Feb 9, 2026

Could this also solve this, I could be wrong? #1234

I looked at it briefly and I locally got out of memory errors when trying to fetch the docs since some package could not be found on esm. And expected to see the no docs found page. This did happen after a refresh sometimes.

@danielroe
Copy link
Member

no, this isn't #1234

@danielroe
Copy link
Member

@userquin i actually disabled view transitions for the site earlier today except for index <> search pages so it's unlikely to be related unless you're on an outdated branch

I don't think this pr is correct

let me know if you experience any issues from now on - it might have been fixed by my change already

@userquin
Copy link
Contributor Author

userquin commented Feb 9, 2026

The main branch on my local contains the same view transition code at main here, maybe the issue when navigating npmx.dev, just add on-hold label to this PR, will try to reproduce the issue with npmx.dev (should contain your fix).

@danielroe danielroe marked this pull request as draft February 9, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants