Repository navigation
fix(nitro): clipboard copy in error overlay - #33873
Conversation
|
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
WalkthroughAdds a postMessage-based clipboard relay between iframe and parent in dev utilities. The iframe registers a DOMContentLoaded handler to send Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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. Comment |
There was a problem hiding this comment.
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.textis 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
copyErrorMessagefunction currently lacks validation for thebuttonparameter and itsdataset.errorTextproperty. 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
📒 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
b7fc136 to
9d2b392
Compare
9d2b392 to
ea8debf
Compare
|
addressed comments from rabbit. ready for merge! |
CodSpeed Performance ReportMerging #33873 will improve performances by 16.83%Comparing Summary
Benchmarks breakdown
|
Fixes #33872
Summary
copyErrorMessageto send postMessage to parentnavigator.clipboard.writeText()which works in secure contextReproduction