Skip to content

Two-phase offline WAM chain build: clone plugins before the setContext swap #542

Description

@naomiaro

Follow-up from #536's final review (Important #2).

renderToneOffline swaps Tone's global context (setContext(offlineContext)) for the whole offline graph build. Since #536 the build awaits real async work per WAM entry (ensureWamHost worklet load + cloneInstanceInto), so the window where app code creating Tone nodes (track add, effect-chain mutation, recording arm) lands on the offline context grew from ~1 microtask (upstream Tone.Offline) to 100ms–1s. Exports themselves are serialized (module-level queue in renderToneOffline), and the docs carry a don't-mutate-mid-export caveat, but the structural fix is:

Two-phase buildOfflineChain: clone all WAM entries against the raw OfflineAudioContext before the setContext swap — ensureWamHost/cloneInstanceInto take the context explicitly and don't need the global swap; only the synchronous Tone-node creation does. That shrinks the swapped window back to roughly upstream's exposure.

Refs: packages/browser/src/utils/renderToneOffline.ts, packages/browser/src/effects/offlineChain.ts, packages/browser/src/hooks/useExportWav.ts (renderOffline).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions