fix(nuxt): handle rejected promise in view transition abort by oritwoen · Pull Request #34515 · nuxt/nuxt · GitHub
Skip to content

fix(nuxt): handle rejected promise in view transition abort - #34515

Merged
danielroe merged 3 commits into
nuxt:mainfrom
oritwoen:fix/view-transition-unhandled-rejection
Mar 11, 2026
Merged

danielroe merged 3 commits into
nuxt:mainfrom
oritwoen:fix/view-transition-unhandled-rejection

Conversation

@oritwoen

Copy link
Copy Markdown
Contributor

When a view transition gets aborted (navigation error, app error, or Vue error), the error handlers call abortTransition() which rejects the update callback's promise. This causes transition.finished to reject too, but .then(resetTransitionState) only attached a resolve handler - the derived promise rejected with no catch, producing an unhandled promise rejection warning in the browser console.

Added .catch(resetTransitionState) so rejections run the same idempotent cleanup. The error handlers already deal with the actual error; this just prevents the stray rejection.

Repro: enable experimental.viewTransition, trigger a navigation error (e.g. a middleware that throws) while a view transition is in progress.

@oritwoen
oritwoen requested a review from danielroe as a code owner March 11, 2026 18:37
@bolt-new-by-stackblitz

Copy link
Copy Markdown

@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Mar 11, 2026
@pkg-pr-new

pkg-pr-new Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34515

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34515

nuxt

npm i https://pkg.pr.new/nuxt@34515

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34515

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34515

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34515

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34515

commit: a15a69c

@coderabbitai

coderabbitai Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 609fea20-4bbc-4290-a610-053559ab182e

📥 Commits

Reviewing files that changed from the base of the PR and between 3373caf and 882706e.

📒 Files selected for processing (1)
  • packages/nuxt/src/app/plugins/view-transitions.client.ts

Walkthrough

The plugin's view-transition completion handling was modified: the promise chain on transition.finished was changed from using then(resetTransitionState) to catch(() => {}) followed by finally(resetTransitionState). This absorbs any rejection from the transition promise and guarantees resetTransitionState runs regardless of resolution or rejection. No other logic or exported declarations were changed.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: handling rejected promises in view transition abort scenarios, which directly matches the changeset's primary purpose.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem context, the solution implemented, and how to reproduce the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
packages/nuxt/src/app/plugins/view-transitions.client.ts (1)

96-96: Consider using .finally() for cleaner cleanup semantics.

The fix correctly addresses the unhandled promise rejection. Since resetTransitionState is idempotent cleanup that should run regardless of outcome, .finally() would be slightly more idiomatic:

-    transition.finished.then(resetTransitionState).catch(resetTransitionState)
+    transition.finished.finally(resetTransitionState)

Any browser supporting document.startViewTransition will support .finally(). This is purely a stylistic preference — the current approach works correctly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxt/src/app/plugins/view-transitions.client.ts` at line 96, Replace
the promise handling on transition.finished to use .finally() for cleanup:
instead of calling
transition.finished.then(resetTransitionState).catch(resetTransitionState), call
transition.finished.finally(resetTransitionState) so the idempotent cleanup
function resetTransitionState always runs once after the promise settles; locate
the call where transition.finished is used (inside the
document.startViewTransition handling) and update it to
.finally(resetTransitionState).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/nuxt/src/app/plugins/view-transitions.client.ts`:
- Line 96: Replace the promise handling on transition.finished to use .finally()
for cleanup: instead of calling
transition.finished.then(resetTransitionState).catch(resetTransitionState), call
transition.finished.finally(resetTransitionState) so the idempotent cleanup
function resetTransitionState always runs once after the promise settles; locate
the call where transition.finished is used (inside the
document.startViewTransition handling) and update it to
.finally(resetTransitionState).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ad53fe9-aa4c-4a7f-9c32-11292cc03dbc

📥 Commits

Reviewing files that changed from the base of the PR and between c0bbb6e and 588c7e5.

📒 Files selected for processing (1)
  • packages/nuxt/src/app/plugins/view-transitions.client.ts

@codspeed

codspeed Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 14.54%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 19 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ writeTypes in the basic-types fixture 96.8 ms 84.5 ms +14.54%

Comparing oritwoen:fix/view-transition-unhandled-rejection (882706e) with main (10ac237)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread packages/nuxt/src/app/plugins/view-transitions.client.ts Outdated
Comment thread packages/nuxt/src/app/plugins/view-transitions.client.ts Outdated
Co-authored-by: Daniel Roe <daniel@roe.dev>
@danielroe
danielroe enabled auto-merge March 11, 2026 21:57
@danielroe
danielroe added this pull request to the merge queue Mar 11, 2026
Merged via the queue into nuxt:main with commit d5d8ce2 Mar 11, 2026
44 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 11, 2026
2 of 5 tasks
danielroe added a commit that referenced this pull request Mar 12, 2026
@github-actions github-actions Bot mentioned this pull request Mar 11, 2026
danielroe added a commit that referenced this pull request Mar 12, 2026
@github-actions github-actions Bot mentioned this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants