-
Notifications
You must be signed in to change notification settings - Fork 82
Description
Problem
The Script Registry currently provides pre-configured integrations for popular third-party scripts, but developers adding custom scripts via useScript() lack clear guidance on best practices. The existing useScript documentation covers the API surface but doesn't address common integration patterns that the registry implicitly demonstrates.
Developers extending the registry or implementing similar patterns for proprietary scripts encounter decisions around:
- Script initialization order and dependency management
- Consent state synchronization (especially for consent-managed scripts like in Load script only with consent and unload script #458)
- Error handling and fallback behavior
- Type safety when wrapping third-party APIs
- SSR/Hydration considerations specific to IIFE patterns
Why this matters
The gap between "here's the useScript API" and "here's how production scripts are integrated" creates friction. Contributors looking to add entries to the registry (#604: Mixpanel) or developers building consent workflows (#458) have to reverse-engineer patterns from existing implementations rather than following explicit guidance.
What good looks like
A new documentation page (docs/guides/custom-script-patterns.md or similar) that walks through:
- Basic integration — Wrapping a simple IIFE with
useScript(), handling the promise chain - API wrapping — Exposing strongly-typed methods when the third-party script is loaded (similar to how
useScriptSegmentwraps Segment's analytics object) - Consent management — Coordinating script load/unload with consent state (pattern from Load script only with consent and unload script #458)
- Error handling — Graceful degradation when scripts fail or are blocked
- Registry contribution checklist — What's required to add a new entry to the script registry
Include a working example showing at least two integrations side-by-side (e.g., a simple tracking script + a complex initialization script with async dependencies).
Acceptance criteria
- Documentation page created with 5 core patterns listed above
- At least one end-to-end example for a custom script not in the registry
- Link from
useScript()API docs to the new patterns guide - (Optional) Provide a simple template/checklist for contributors adding registry entries
Contributed by Klement Gunndu