-
Notifications
You must be signed in to change notification settings - Fork 1
feat: skip attaching the launcher when its embedded and update tests #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: skip attaching the launcher when its embedded and update tests #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request optimizes the Rokt launcher initialization by detecting when the launcher.js is already embedded on the page and skipping redundant script tag creation. When window.Rokt.createLauncher exists, the code now calls attachLauncher() directly instead of fetching launcher.js via a new script tag, unless the launcher has already been initialized.
Changes:
- Modified initialization logic to check for embedded launcher before creating script tags
- Removed misleading console warning when Rokt is already present
- Added test coverage for embedded launcher scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Rokt-Kit.js | Updated initForwarder to check if launcher is embedded and call attachLauncher directly, eliminating redundant script loading |
| test/src/tests.js | Updated existing test to force script loading path and added new tests to verify embedded launcher behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/src/tests.js
Outdated
| it('should not call createLauncher when launcher is already initialized', async () => { | ||
| window.Rokt.currentLauncher = { initialized: true }; | ||
|
|
||
| await window.mParticle.forwarder.init( | ||
| { accountId: '123456' }, | ||
| reportService.cb, | ||
| false, | ||
| null, | ||
| {} | ||
| ); | ||
|
|
||
| window.mParticle.Rokt.createLauncherCalled.should.equal(false); | ||
| }); |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When window.Rokt.currentLauncher already exists, the code skips calling attachLauncher(), which means self.launcher is never set and self.isInitialized remains false (unless this is a re-initialization of the same forwarder instance).
Consider adding a test case that verifies the forwarder's functionality after init() is called when currentLauncher already exists. Specifically, check whether isKitReady() returns true and whether core forwarder methods like selectPlacements() and hashAttributes() work correctly.
If the forwarder should be functional in this scenario, the code may need to attach to the existing launcher instance rather than skipping initialization entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| window.mParticle.Rokt = { | ||
| domain: 'apps.rokt.com', | ||
| attachKit: async () => Promise.resolve(), | ||
| filters: savedRokt.filters, |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better test isolation and consistency, consider explicitly initializing the createLauncherCalled flag in the new mParticle.Rokt object. While this test doesn't assert on createLauncherCalled, adding it would match the pattern used in beforeEach (line 542) and prevent potential issues if future tests rely on this flag's state. Example: createLauncherCalled: false
| filters: savedRokt.filters, | |
| filters: savedRokt.filters, | |
| createLauncherCalled: false, |
| if (!window.Rokt.currentLauncher) { | ||
| attachLauncher(accountId, launcherOptions); | ||
| } else { | ||
| initRoktLauncher(window.Rokt.currentLauncher); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: How does the launcher get the accountId and the launcherOptions in this flow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this else block, reusing an existing launcher that was already created with accountId and launcherOptions by a previous initialization. The launcher object stores its configuration internally, so we just attach our forwarder instance to it via initRoktLauncher().
Below is my understanding:
-
First init:
window.Rokt.currentLauncherisundefined→attachLauncher(accountId, launcherOptions)creates a new launcher viacreateLauncher({accountId, ...launcherOptions})→ launcher stores this config internally -
Subsequent (this else block):
currentLauncheralready exists → we skip creating a new one and just callinitRoktLauncher(existingLauncher)to attach the current forwarder instance to it -
The
accountIdandlauncherOptionsshould already be baked into the existing launcher from the first init. Since mParticle workspaces have one Rokt kit configuration, all forwarder instances would be sharing the same accountId.
Summary
window.Rokt.createLauncheralready exists, directly callattachLauncher() instead of fetching launcher.js via a new script tagTesting Plan