Skip to content

add queue to commercial for external initialisation#2402

Merged
dskamiotis merged 11 commits intomainfrom
ds/add-queue-to-commercial
Feb 16, 2026
Merged

add queue to commercial for external initialisation#2402
dskamiotis merged 11 commits intomainfrom
ds/add-queue-to-commercial

Conversation

@dskamiotis
Copy link
Contributor

@dskamiotis dskamiotis commented Feb 6, 2026

What does this change?

Adds window.guardian.commercial.queue - a global queue that external code can use to run functions after commercial initialisation.

Implementation: Uses a factory function to create a queue object with explicit push() and flush() methods. Chosen over a Proxy-based approach for better readability, easier debugging, and clearer intent.

How it works (3 phases):

  1. Setup: Queue created early in commercial.ts before async modules load
  2. Buffering: Functions pushed pre-init are buffered (not executed)
  3. Flush: After all modules load, flush() executes buffered functions in order

Why?

External code sometimes needs to run after commercial initializes (e.g., code that depends on ads being defined). Currently no clean way to do this without polling or timing hacks.

This pattern mirrors googletag.cmd and provides a reliable "run when ready" mechanism.

Alternative considered: Proxy-based queue that intercepts array methods. Rejected for complexity and reduced clarity.

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2026

⚠️ No Changeset found

Latest commit: 6c13a39

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Size Change: +235 B (+0.1%)

Total Size: 243 kB

Filename Size Change
bundle/dist/prod/artifacts/commercial/********************/graun.598.commercial.js 127 kB +57 B (+0.05%)
bundle/dist/prod/artifacts/commercial/********************/graun.standalone.commercial.js 19.3 kB +140 B (+0.73%)
ℹ️ View Unchanged
Filename Size Change
bundle/dist/prod/artifacts/commercial/********************/graun.3.commercial.js 14.4 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.148.commercial.js 4.36 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.317.commercial.js 617 B 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.574.commercial.js 20.4 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.756.commercial.js 5.23 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.769.commercial.js 13.5 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.ad-free.commercial.js 4.49 kB +21 B (+0.47%)
bundle/dist/prod/artifacts/commercial/********************/graun.consented-advertising.commercial.js 29.4 kB +17 B (+0.06%)
bundle/dist/prod/artifacts/commercial/********************/graun.consentless-advertising.commercial.js 1.8 kB 0 B
bundle/dist/prod/artifacts/commercial/********************/graun.Prebid.js.commercial.js 2.51 kB 0 B

compressed-size-action

@dskamiotis dskamiotis added the feature Departmental tracking: work on a new feature label Feb 6, 2026
@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch from 71985b1 to af1278b Compare February 6, 2026 10:40
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch 6 times, most recently from 0014f0f to 5698642 Compare February 9, 2026 15:58
@dskamiotis dskamiotis marked this pull request as ready for review February 9, 2026 15:58
@dskamiotis dskamiotis requested a review from a team as a code owner February 9, 2026 15:58
@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch 2 times, most recently from 4bfb19f to 7cb1f33 Compare February 13, 2026 14:01
@dskamiotis dskamiotis requested review from a team, Jakeii and on-ye February 13, 2026 14:01
@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch from 946e85a to 6343009 Compare February 13, 2026 17:55
@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch from 6343009 to 161da07 Compare February 13, 2026 18:00
@dskamiotis dskamiotis force-pushed the ds/add-queue-to-commercial branch from 161da07 to 70bb55c Compare February 13, 2026 20:18
Copy link
Contributor

@on-ye on-ye left a comment

Choose a reason for hiding this comment

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

Minor comment, but looks good

@dskamiotis dskamiotis merged commit ebc6694 into main Feb 16, 2026
15 checks passed
@dskamiotis dskamiotis deleted the ds/add-queue-to-commercial branch February 16, 2026 14:16
@gu-prout
Copy link

gu-prout bot commented Feb 16, 2026

Seen on PROD (merged by @dskamiotis 2 minutes ago) Please check your changes!

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

Labels

feature Departmental tracking: work on a new feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants