Skip to content

Script Registry: Add comprehensive documentation for custom script integration patterns #636

@KlementMultiverse

Description

@KlementMultiverse

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:

  1. Basic integration — Wrapping a simple IIFE with useScript(), handling the promise chain
  2. API wrapping — Exposing strongly-typed methods when the third-party script is loaded (similar to how useScriptSegment wraps Segment's analytics object)
  3. Consent management — Coordinating script load/unload with consent state (pattern from Load script only with consent and unload script #458)
  4. Error handling — Graceful degradation when scripts fail or are blocked
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions