Skip to content

Decouple the prebid tsjs shim from the bundled Prebid.js#967

Open
aram356 wants to merge 1 commit into
mainfrom
decouple-prebid-shim
Open

Decouple the prebid tsjs shim from the bundled Prebid.js#967
aram356 wants to merge 1 commit into
mainfrom
decouple-prebid-shim

Conversation

@aram356

@aram356 aram356 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

The prebid tsjs shim (the trustedServer adapter, requestBids wrapper, and Prebid config glue) was compiled into the external Prebid bundle: build-prebid-external.mjs used the shim as its entry point and imported prebid.js plus internal modules directly. Any shim change therefore required rebuilding and re-uploading the external bundle and repointing external_bundle_sha256/external_bundle_sri — server deploys alone could never change client behavior.

This PR separates the two artifacts:

  • External bundle → pure Prebid.js. The generated entry imports Prebid core, the consent modules (TCF/GPP/USP), userId, and the selected --adapters / --user-id-modules — no shim code. It stamps a manifest on window.__tsjs_prebid_bundle ({adapters, userIdModules}) and intentionally does not call processQueue(); the shim keeps driving queue processing after it installs the adapter, preserving the existing ordering semantics.
  • Shim → server-served deferred tsjs module. build-all.mjs no longer excludes prebid, and the Rust registration switches .without_js().with_deferred_js(), so the shim ships as tsjs-prebid via the /static/tsjs= route. It uses the window.pbjs global (the head-injected stub object that Prebid.js mutates in place) with a type-only import type for typing, and fails loudly if the external bundle did not load (no registerBidAdapter on the global).
  • Public APIs only. adapterManager.getBidAdapter (an internal import) is replaced by validating client_side_bidders against the stamped manifest; the previously bundled consent/userId module imports move into the external bundle entry.

Why

Shim fixes should reach production with a normal server deploy. With this split, the external bundle only changes when the Prebid.js version or the adapter/user-ID selection changes.

Verification

  • cargo fmt --all -- --check
  • All six clippy targets (fastly, axum, cloudflare native+wasm, spin native+wasm) with -D warnings
  • cargo test for core + fastly (1658 + 109), axum, cloudflare, spin, and the parity integration suite (13)
  • npx vitest run (412 tests) and npm run format
  • Built both artifacts: tsjs-prebid.js shim (~23 KB, no Prebid core markers) and the pure external bundle (reproducible content hash across builds)
  • End-to-end against a production publisher page through the local dev proxy: external bundle populates window.pbjs (v10.26.0) and stamps the manifest, the deferred shim registers the trustedServer adapter and wraps requestBids, server-side /auction and client-side bidders both return bids, and hb_* targeting reaches every GPT slot with zero Prebid console errors

Deployment note

The currently deployed external bundle contains the old baked-in shim, so this change and a regenerated pure bundle should roll out together: upload the new bundle, update external_bundle_sha256/external_bundle_sri, and deploy the server. Running the new server against the old bundle would install the adapter twice.

Old-architecture guard tests (asserting the shim must not be served as embedded tsjs) are inverted to assert the new behavior.

The external bundle is now pure Prebid.js (core, consent and user ID
modules, client-side bid adapters) and stamps a manifest on
window.__tsjs_prebid_bundle. The shim ships as a server-served deferred
tsjs module that installs the trustedServer adapter onto the window.pbjs
global via public APIs only, so shim fixes deploy with the server instead
of requiring an external bundle re-upload.
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.

1 participant