docs: add custom script integration patterns guide#637
docs: add custom script integration patterns guide#637KlementMultiverse wants to merge 2 commits intonuxt:mainfrom
Conversation
Adds a new guide covering 5 common patterns for building custom script integrations with useScript(): 1. Basic integration - wrapping IIFE scripts 2. API wrapping - strongly-typed method exposure 3. Consent management - coordinating with useScriptTriggerConsent() 4. Error handling - graceful degradation for blocked/failed scripts 5. Registry contribution checklist - file structure and steps Also adds a "See Also" section to the useScript() API docs linking to the new guide. Closes nuxt#636
|
Someone is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new documentation page "Custom Script Patterns" was added at docs/content/docs/1.guides/2.custom-script-patterns.md describing patterns for integrating and wrapping third‑party scripts with useScript() (Basic Integration, API Wrapping, Consent Management, Error Handling, Registry Contribution), including TypeScript and Vue examples, proxy behavior, SSR notes, and a Registry Contribution Checklist. The useScript.md document (docs/content/docs/3.api/1.use-script.md) received a "See Also" section linking to Custom Script Patterns, Key Concepts, and Registry Scripts. No code or public API declarations were changed. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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.
🧹 Nitpick comments (1)
docs/content/docs/1.guides/2.custom-script-patterns.md (1)
91-109: Simplify the example to avoid redundant destructuring.The example destructures
onMessageon line 93 but never uses it, then callsuseMyChat()again on line 96 to getonLoaded. TheonMessageused inside the callback (line 98) comes from the callback parameter, not line 93.♻️ Proposed simplification
<script setup lang="ts"> -const { open, onMessage } = useMyChat('your-token') +const { open, onLoaded } = useMyChat('your-token') // Subscribe to messages after the script loads -const { onLoaded } = useMyChat('your-token') onLoaded(({ onMessage }) => { onMessage((msg) => { console.log(`New message from ${msg.from}: ${msg.text}`) }) }) </script>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/content/docs/1.guides/2.custom-script-patterns.md` around lines 91 - 109, The example redundantly calls useMyChat twice and destructures onMessage which is never used; simplify by calling useMyChat('your-token') once (capturing open and onLoaded), remove the unused onMessage destructuring, and move the subscription to messages inside the onLoaded callback via the provided onMessage parameter so the code only uses open and onLoaded from useMyChat.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/content/docs/1.guides/2.custom-script-patterns.md`:
- Around line 91-109: The example redundantly calls useMyChat twice and
destructures onMessage which is never used; simplify by calling
useMyChat('your-token') once (capturing open and onLoaded), remove the unused
onMessage destructuring, and move the subscription to messages inside the
onLoaded callback via the provided onMessage parameter so the code only uses
open and onLoaded from useMyChat.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aeaa42af-59ce-4733-a2aa-575cff7cbb82
📒 Files selected for processing (2)
docs/content/docs/1.guides/2.custom-script-patterns.mddocs/content/docs/3.api/1.use-script.md
Consolidate two useMyChat() calls into one and remove the unused onMessage destructure. The onMessage parameter comes from the onLoaded callback, not the outer scope. Addresses CodeRabbit nitpick: redundant destructuring on line 93.
Summary
Adds a new documentation guide at
docs/content/docs/1.guides/2.custom-script-patterns.mdcovering 5 common patterns for building custom script integrations withuseScript():useScript(), handling the promise chain and proxied functionsuseScriptSegment)useScriptTriggerConsent()Also adds a See Also section to
docs/content/docs/3.api/1.use-script.mdlinking to the new patterns guide.Motivation
Addresses #636. Developers building custom integrations or contributing to the registry currently have to reverse-engineer patterns from existing implementations. This guide bridges the gap between the
useScript()API reference and production integration patterns.Changes
docs/content/docs/1.guides/2.custom-script-patterns.md(267 lines)docs/content/docs/3.api/1.use-script.md— added See Also section at the bottomThanks @harlan-zw for the invitation to contribute this!