Skip to content

UJS: Refactored core package to be platform agnostic#1524

Merged
Spencer-Smith merged 17 commits into
mainfrom
ujs/migrateReferences
Jun 26, 2026
Merged

UJS: Refactored core package to be platform agnostic#1524
Spencer-Smith merged 17 commits into
mainfrom
ujs/migrateReferences

Conversation

@Spencer-Smith

Copy link
Copy Markdown
Collaborator

Changed Packages

  • core
  • reactor-extension

Description

Moved platform-specific implementation details (ie 'window' and 'document' that are specific to browser implementation, as well as upstream dependencies that use these artifacts) to the browser's platform services. C

Related Issue

(Related to Universal JavaScript migration)

Motivation and Context

Node package for WebSDK will have failures when encountering references to browser resources.

Screenshots (if appropriate):

N/A

Documentation

(All UJS should be documented together)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have added a Changeset file with a consumer-facing description of my changes.
  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa36211

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@adobe/alloy Patch
@adobe/alloy-core Patch
adobe-alloy-monorepo Patch
@adobe/alloy-sandbox-browser Patch
reactor-extension-alloy Patch
@adobe/alloy-node Patch
@adobe/alloy-sandbox-node Patch

Not sure what this means? Click here to learn what changesets are.

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

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR continues the Universal JavaScript migration by removing direct window/document references from the core package and routing them through injected platformServices. Browser-specific globals (isPageSsl, getWindowContext, getLocationHash, getPageLocation) are moved to createBrowserGlobalsService, storage and cookie operations are delegated to their respective platform service, and the legacy visitor service is relocated to the browser legacy service.

  • Platform abstraction: cookieJar, injectStorage, and getMonitors global imports are removed from core; platformServices is constructed before the logger and threaded into every component creator.
  • Async storage migration: createRestoreStorage, createConsentHashStore.isNew/save, createLogController debug restore, and createGetAssuranceValidationTokenParams clientId persistence are all converted to async storage APIs, with the event-registry race window closed by moving save reassignment after await restore.
  • Deleted files: cookieJar.js, getMonitors.js, and the three visitorService files are removed from core and their responsibilities absorbed by the browser legacy service.

Confidence Score: 4/5

Safe to merge after addressing the two logging regressions in the beacon fallback path and the assurance token params; all other async-storage migrations are correct.

Two concrete regressions were introduced: injectSendBeaconRequest now uses console.info unconditionally instead of the SDK debug-gated logger, so production users will see SDK internals on every sendBeacon failure; and createGetAssuranceValidationTokenParams leaves storage.getItem().then() without a .catch(), creating an unhandled promise rejection risk on the non-browser backends this PR is explicitly designed to support.

packages/core/src/core/network/requestMethods/injectSendBeaconRequest.js and packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js

Important Files Changed

Filename Overview
packages/core/src/core/network/requestMethods/injectSendBeaconRequest.js Removed logger dependency and replaced logger.info with bare console.info, causing the fallback message to print unconditionally in production rather than only when debug mode is enabled.
packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js Migrated clientId persistence to async storage; the storage.getItem().then() chain is missing a .catch(), which will produce an unhandled promise rejection if a non-browser storage backend rejects.
packages/core/src/core/createLogController.js Debug persistence migrated from sync sessionStorage.getItem to an async storage.getItem promise with a !debugSetByUser guard to prevent the async restore from overwriting a synchronously-set query-string value; .catch(() => {}) is present.
packages/core/src/core/index.js Central wiring point — createPlatformServices() now called before logger construction and platformServices threaded into every component creator; cookieJar, injectStorage, and getMonitors direct references removed.
packages/core/src/components/RulesEngine/createEventRegistry.js Safe defaults added for eventRegistry/eventRegistrySize; setStorage made async and save reassignment moved after await restore to close the prior race window.
packages/core/src/components/Consent/createConsentHashStore.js isNew() and save() made async using Promise.all; callers updated to await them correctly.
packages/browser/src/services/createBrowserGlobalsService.js Added getLocationHash, getPageLocation, isPageSsl, and getWindowContext so core components no longer reference window/document directly.
packages/core/src/components/Identity/index.js Removed direct window references for isPageSsl, locationSearch, locationHash, and ECID visitor service; all replaced with platformServices equivalents.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[createExecuteCommand] -->|calls| B[createPlatformServices]
    B --> C[createBrowserNetworkService]
    B --> D[createBrowserStorageService]
    B --> E[createBrowserCookieService]
    B --> F[createBrowserGlobalsService]
    B --> G[createBrowserLegacyService]
    A -->|passes storage.session to| H[createLogController]
    H -->|async getItem| D
    A -->|passes storage.persistent to| I[createGetAssuranceValidationTokenParams]
    I -->|async getItem no catch| D
    A -->|platformServices threaded through| J[Component Creators]
    J --> K[RulesEngine createEventRegistry]
    J --> L[Consent createConsentHashStore]
    J --> M[Identity createComponent]
    C -->|sendBeacon fallback| Q[injectSendBeaconRequest console.info always-on]
    style I fill:#ffcccc
    style Q fill:#ffcccc
Loading

Reviews (4): Last reviewed commit: "Address debugSetByUser overwrite bug" | Re-trigger Greptile

Comment thread packages/core/src/components/RulesEngine/utils/storage.js
Comment thread packages/core/src/core/createLogController.js Outdated
Comment thread packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js Outdated
Comment thread .changeset/vast-jeans-walk.md
Comment thread packages/browser/src/services/createBrowserGlobalsService.js
Comment thread packages/browser/src/services/createBrowserNetworkService.js Outdated
Comment thread packages/browser/src/services/createBrowserNetworkService.js Outdated
Comment thread packages/browser/test/unit/specs/services/createBrowserNetworkService.spec.js Outdated
Comment thread packages/core/src/core/network/injectSendNetworkRequest.js Outdated
Comment thread packages/core/src/core/index.js Outdated
Comment thread packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js Outdated
Comment thread eslint.config.js
Comment thread package.json

@jonsnyder jonsnyder 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.

I'm a bit concerned that we are going to introduce a ton of regressions with this migration. One way to mitigate that risk is with automated testing at the SDK level. If we can develop a set of tests, and then run it against an old SDK version without failures, we can be more certain that this migration isn't creating problems. We could have AI create a bunch of tests, or we could do some random testing to generate a test set.

Comment thread .changeset/vast-jeans-walk.md
Comment thread packages/core/src/components/Audiences/index.js
Comment thread packages/core/src/core/createLogController.js Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread packages/core/src/core/createLogController.js Outdated
Comment thread packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js Outdated
Comment thread packages/core/src/core/network/requestMethods/injectSendBeaconRequest.js Outdated
Comment thread packages/core/package.json Outdated
Comment thread eslint.config.js Outdated

@carterworks carterworks 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.

two small things. good job on the tests

Comment thread packages/core/src/core/network/requestMethods/injectSendBeaconRequest.js Outdated
Comment thread packages/core/src/core/index.js Outdated
…v dependency; relocate DOM utils into utils/dom/
Comment thread packages/browser/src/services/createBrowserNetworkService.js Outdated
…network services; move browser-specific utilities for network to browser package
@Spencer-Smith
Spencer-Smith merged commit 3d5faef into main Jun 26, 2026
11 checks passed
@Spencer-Smith
Spencer-Smith deleted the ujs/migrateReferences branch June 26, 2026 15:27
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