Skip to content

feat: forward terminate from the kit to the Rokt launcher - #122

Open
jamesnrokt wants to merge 1 commit into
developmentfrom
feat/rokt-kit-terminate
Open

feat: forward terminate from the kit to the Rokt launcher#122
jamesnrokt wants to merge 1 commit into
developmentfrom
feat/rokt-kit-terminate

Conversation

@jamesnrokt

@jamesnroktjamesnrokt commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds RoktKit.terminate(), which forwards to launcher.terminate() on the Rokt Web SDK.

This is the kit half of a supported teardown path for window.mParticle.Rokt.terminate(). The core SDK half is in mParticle/mparticle-web-sdk#1328; that PR's RoktManager.terminate() delegates to this method. This PR should merge and release first — the manager guards the call with isFunction, so until a kit carrying this change is on the page, mParticle.Rokt.terminate() logs that the attached kit version does not support it.

Partners currently tear down placements with the undocumented window.Rokt.currentLauncher?.terminate(). This makes the same call reachable through the documented interface.

Behaviour

  • Ready: returns launcher.terminate() directly, so callers can await the teardown. The launcher's own terminate races an internal 500ms timeout and never rejects.
  • Not ready: logs Rokt Kit: Not initialized and resolves. Teardown is idempotent — with no launcher there is nothing to tear down.

The launcher reference is deliberately left in place

terminate() does not null out this.launcher or window.Rokt.currentLauncher. The Rokt Web SDK memoizes a single launcher per page (createLauncher returns the cached promise once fulfilled), so clearing our references could not buy the caller a fresh launcher — it would only flip isKitReady() to false and leave every later selectPlacements call queued forever with no drain path.

Leaving state untouched makes this exactly equivalent to the window.Rokt.currentLauncher.terminate() call partners already make, just reachable through a supported API. There is a test pinning this.

Testing Plan

npm run lint, npm run build, npm run test all pass — 313/313 Vitest tests, including 6 new #terminate cases covering:

  • launcher.terminate is called when fully initialized
  • the launcher's promise is returned and awaitable
  • resolves as a no-op, without touching the launcher, when uninitialized
  • resolves as a no-op when initialized but the launcher is missing
  • launcher references survive teardown so the kit stays ready
  • end-to-end through init() + attachKit in test mode

All 6 fail against main without the source change.

Suggested manual check

On a page with a rendered placement, await window.Rokt.currentLauncher.terminate() and await window.mParticle.Rokt.terminate() (once mParticle/mparticle-web-sdk#1328 is also deployed) should be indistinguishable.

🤖 Generated with Claude Code

Backs the new `window.mParticle.Rokt.terminate()` entry point in the core
SDK (mParticle/mparticle-web-sdk). The manager delegates to the kit, which
forwards to the launcher, giving partners a supported teardown path in place
of the undocumented `window.Rokt.currentLauncher?.terminate()`.
The launcher reference is deliberately left in place. The Rokt Web SDK
memoizes a single launcher per page, so clearing it could not buy the caller
a fresh one — it would only flip the kit to not-ready and leave later calls
queued forever.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
});

// The Rokt Web SDK memoizes one launcher per page, so terminate must not
// clear the kit's launcher references — doing so would flip the kit to

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically createLauncher can be called again after terminate, usually for SPAs.
Can this create another launcher instance in that flow and continue? (given the launcher reference is maintained)
Create a test to capture this scenario

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jamesnrokt@mattbodle