Skip to content

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

Merged
mattbodle merged 4 commits into
developmentfrom
feat/rokt-kit-terminate
Aug 24, 2026
Merged

feat: forward terminate from the kit to the Rokt launcher#122
mattbodle merged 4 commits into
developmentfrom
feat/rokt-kit-terminate

Conversation

@jamesnrokt

@jamesnrokt jamesnrokt 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>
Comment thread test/src/tests.spec.ts Outdated
The Web SDK drops its memoized launcher on terminate, so createLauncher
can mint a new instance. The next selectPlacements now re-attaches that
instance instead of calling into the terminated one.
Comment thread test/src/tests.spec.ts Outdated

@crisryantan crisryantan left a comment

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.

Let's fix the types since we are already making changes

…eate

Move the SPA recreate path onto a LauncherAttachContext / lifecycle
state module so createLauncher options and Window.Rokt stay typed.
@mattbodle
mattbodle requested a review from crisryantan August 22, 2026 01:13
Type the #terminate window/kit/launcher surface so the new tests no
longer cast through any.
@mattbodle
mattbodle merged commit 87354d4 into development Aug 24, 2026
4 of 5 checks passed
Sign up for free to 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.

3 participants