Skip to content

fix(nitro): clipboard copy in error overlay - #33873

Merged
danielroe merged 1 commit into
nuxt:mainfrom
onmax:fix/error-overlay-clipboard
Dec 19, 2025
Merged

danielroe merged 1 commit into
nuxt:mainfrom
onmax:fix/error-overlay-clipboard

Conversation

@onmax

@onmax onmax commented Dec 14, 2025 •

Copy link
Copy Markdown
Member

Fixes #33872

Summary

  • Iframe overrides copyErrorMessage to send postMessage to parent
  • Parent registers clipboard handler immediately (before host check)
  • Parent calls navigator.clipboard.writeText() which works in secure context

Reproduction

@onmax
onmax requested a review from danielroe as a code owner December 14, 2025 13:37
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added 4.x 🐛 bug Something isn't working as expected labels Dec 14, 2025
@danielroe danielroe changed the title fix(nitro-server): clipboard copy in error overlay fix(nitro): clipboard copy in error overlay Dec 14, 2025
@pkg-pr-new

pkg-pr-new Bot commented Dec 14, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

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

@nuxt/nitro-server

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: ea8debf

@coderabbitai

coderabbitai Bot commented Dec 14, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a postMessage-based clipboard relay between iframe and parent in dev utilities. The iframe registers a DOMContentLoaded handler to send clipboard-copy messages including a nonce and UI badge target; the parent defines the same nonce, listens for clipboard-copy messages, and invokes navigator.clipboard.writeText to perform writes from the secure parent context. The flow integrates with existing storage-sync and event messaging; no public/exported API signatures were changed.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(nitro): clipboard copy in error overlay' accurately summarizes the main change—fixing clipboard functionality in the error overlay component.
Description check ✅ Passed The description is directly related to the changeset, explaining the fix mechanism (postMessage delegation), the rationale (secure context requirement), and providing reproduction links.
Linked Issues check ✅ Passed The pull request implements the proposed solution from issue #33872 by delegating clipboard operations from the iframe to the parent window using postMessage, addressing the root cause of the clipboard failure.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the clipboard copy functionality in the error overlay as specified in issue #33872; no out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7fc136 and ea8debf.

📒 Files selected for processing (1)
  • packages/nitro-server/src/runtime/utils/dev.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nitro-server/src/runtime/utils/dev.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: test-benchmark
  • GitHub Check: test-size
  • GitHub Check: code

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/nitro-server/src/runtime/utils/dev.ts (2)

91-94: Consider logging errors and validating text parameter.

The clipboard write silently swallows all errors, which makes debugging difficult. Additionally, there's no validation that e.data.text is defined.

Apply this diff to improve error handling and validation:

   window.addEventListener('message', function(e) {
     if (e.data && e.data.type === 'clipboard-copy' && e.data.nonce === NONCE) {
-      navigator.clipboard.writeText(e.data.text).catch(function() {});
+      if (typeof e.data.text === 'string') {
+        navigator.clipboard.writeText(e.data.text).catch(function(err) {
+          console.warn('Failed to write to clipboard:', err);
+        });
+      }
     }
   });

76-83: Consider adding defensive checks if this function will be called from dynamic error overlays.

The copyErrorMessage function currently lacks validation for the button parameter and its dataset.errorText property. While this function isn't currently invoked anywhere in the codebase, adding defensive checks would be prudent if it's intended for future use or integration with dynamically generated error overlays:

   document.addEventListener('DOMContentLoaded', function() {
     window.copyErrorMessage = function(button) {
+      if (!button || !button.dataset || !button.dataset.errorText) return;
       window.parent.postMessage({ type: 'clipboard-copy', text: button.dataset.errorText, nonce: NONCE }, '*');
       button.classList.add('copied');
       setTimeout(function() { button.classList.remove('copied'); }, 2000);
     };
   });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01d459e and b7fc136.

📒 Files selected for processing (1)
  • packages/nitro-server/src/runtime/utils/dev.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nitro-server/src/runtime/utils/dev.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/nitro-server/src/runtime/utils/dev.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, webpack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: test-size
  • GitHub Check: code

@onmax
onmax force-pushed the fix/error-overlay-clipboard branch from b7fc136 to 9d2b392 Compare December 14, 2025 13:42
@onmax
onmax force-pushed the fix/error-overlay-clipboard branch from 9d2b392 to ea8debf Compare December 14, 2025 13:43
@onmax

onmax commented Dec 14, 2025

Copy link
Copy Markdown
Member Author

addressed comments from rabbit.

ready for merge!

@codspeed

codspeed Bot commented Dec 14, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #33873 will improve performances by 16.83%

Comparing onmax:fix/error-overlay-clipboard (ea8debf) with main (01d459e)

Summary

⚡ 1 improvement
✅ 9 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
⚡ writeTypes in the basic-types fixture 93.9 ms 80.4 ms +16.83%

@danielroe danielroe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you ❤️

@danielroe
danielroe merged commit 3cbdaef into nuxt:main Dec 19, 2025
@github-actions github-actions Bot mentioned this pull request Dec 19, 2025
@onmax
onmax deleted the fix/error-overlay-clipboard branch December 19, 2025 23:03
@github-actions github-actions Bot mentioned this pull request Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error overlay copy button doesn't work

2 participants