-
Notifications
You must be signed in to change notification settings - Fork 192
🐛 [Shopify] Defer plugin init until a checkout page view, fixing double session IDs #4981
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
Merged
lierniel
merged 13 commits into
main
from
stephan.koshcheev/RUM-18173/shopify-fix-double-session-ids
Sep 2, 2026
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f4b3817
♻️ Replace Shopify Custom Pixel init-patching with a RumPlugin-based …
lierniel 3b31f07
✨ Support async and abortable onInit in RUM plugins
lierniel 4d662d6
✨ Defer Shopify plugin init until the first checkout page view
lierniel 15aec3b
🚨 Silence floating-promise lint errors from the async onInit signature
lierniel f58b3de
♻️ Replace callPluginsMethod with runOnInitPlugins and callPluginsOnR…
lierniel d6fd85d
📝 Explain the isBindingsInstalled guard in shopifyPlugin
lierniel 6685c88
✨ Add embeddedPlugins option to expose plugin factories on the public…
lierniel 7b60dac
♻️ Address review feedback on plugin init lifecycle
lierniel bf1c424
♻️ Remove the generic onInit timeout from callPluginsOnInit
lierniel 5402c17
♻️ Move the onInit timeout from the generic mechanism to shopifyPlugin
lierniel 2a7501f
🐛 Fix unhandled timeout rejection leaking from shopifyPlugin spec
lierniel 856a44a
♻️ Address review feedback on plugin init and Shopify plugin tests
lierniel 9cfaccb
🐛 Move mockShopifyAnalytics test helper out of src to fix package build
lierniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { isThenable, waitForThenable, TIMEOUT_ERROR_MESSAGE } from './thenable' | ||
| import { noop } from './utils/functionUtils' | ||
|
|
||
| describe('isThenable', () => { | ||
| it('returns true for a Promise', () => { | ||
| expect(isThenable(Promise.resolve())).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for a plain object with a then function', () => { | ||
| expect(isThenable({ then: noop })).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false for a plain object without a then function', () => { | ||
| expect(isThenable({})).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false for null and undefined', () => { | ||
| expect(isThenable(null)).toBe(false) | ||
| expect(isThenable(undefined)).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false for primitives', () => { | ||
| expect(isThenable(42)).toBe(false) | ||
| expect(isThenable('foo')).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('waitForThenable', () => { | ||
| it('resolves with the thenable value when it settles before the timeout', async () => { | ||
| const result = await waitForThenable(Promise.resolve('value'), 1000) | ||
| expect(result).toBe('value') | ||
| }) | ||
|
|
||
| it('rejects with the thenable rejection reason when it settles before the timeout', async () => { | ||
| await expectAsync(waitForThenable(Promise.reject(new Error('boom')), 1000)).toBeRejectedWithError('boom') | ||
| }) | ||
|
|
||
| it('rejects with a timeout error when the thenable does not settle in time', async () => { | ||
| const neverSettles = new Promise(noop) | ||
| await expectAsync(waitForThenable(neverSettles, 0)).toBeRejectedWithError(TIMEOUT_ERROR_MESSAGE) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { TimeoutId } from './timer' | ||
| import { setTimeout, clearTimeout } from './timer' | ||
|
|
||
| export function isThenable<T>(value: unknown): value is PromiseLike<T> { | ||
| return !!value && typeof (value as { then?: unknown }).then === 'function' | ||
| } | ||
|
|
||
| export const TIMEOUT_ERROR_MESSAGE = 'Timeout' | ||
| export function isTimeoutError(error: unknown): error is Error { | ||
| return error instanceof Error && error.message === TIMEOUT_ERROR_MESSAGE | ||
| } | ||
|
|
||
| /** | ||
| * Resolves or rejects with `thenable`, or rejects with a `TIMEOUT_ERROR_MESSAGE` error if it | ||
| * doesn't settle within `timeout` ms. | ||
| */ | ||
| export function waitForThenable<T>(thenable: PromiseLike<T>, timeout = 3000): Promise<T> { | ||
| let timeoutId: TimeoutId | ||
| const timeoutPromise = new Promise<never>((_, reject) => { | ||
| timeoutId = setTimeout(() => reject(new Error(TIMEOUT_ERROR_MESSAGE)), timeout) | ||
| }) | ||
| return Promise.race([thenable, timeoutPromise]).finally(() => clearTimeout(timeoutId)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.