fix: support a single audience/campaign per selector in fragment manifests - #63
Merged
Merged
Conversation
…fests parseAudienceManifest and parseCampaignManifest call `.forEach` on the aggregated audience/campaign + url values, but aggregateEntries only builds arrays for selectors with multiple values — a single value stays a scalar string, so `.forEach` throws "audiences.forEach is not a function", which aborts loadEager and leaves the fragment un-personalized. Normalize both to arrays with `[].concat(...)` before iterating (a no-op for the existing multi-value case). Adds fragment-level fixtures + tests for a single audience and a single campaign per selector (red before this change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 12, 2026
## [1.2.1](v1.2.0...v1.2.1) (2026-08-12) ### Bug Fixes * support a single audience/campaign per selector in fragment manifests ([#63](#63)) ([6f7b3e8](6f7b3e8))
This was referenced Aug 12, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
A fragment-level Audience Manifest (or Campaign Manifest) with a single audience/campaign per selector crashes the plugin.
parseAudienceManifest/parseCampaignManifestcallaudiences.forEach(...)/campaigns.forEach(...), butaggregateEntriesonly produces an array when a selector has multiple values — a selector with a single value leavesaudience/campaign(andurl) as a scalar string.String.prototype.forEachdoesn't exist, so it throwsaudiences.forEach is not a function, which abortsloadEagerand leaves the fragment un-personalized (window.hlx.audiences/.campaignsnever gets set).Every existing manifest fixture uses two audiences/campaigns per selector, so this single-value path was never exercised.
Fix
Normalize
audience/campaignandurlto arrays with[].concat(...)before iterating — a no-op for the existing multi-value case, correct for the single-value case.Tests
Adds fragment-level fixtures + tests for a single audience and a single campaign per selector. They fail red before this change (
waitForNamespacetimes out because the plugin threw) and pass after. Fullaudiences+campaignssuites green (46 passed), lint clean.Found while building a "bring your own decision engine" personalization integration, where each slot's manifest carries exactly one (remote) audience — a common shape for per-slot personalization, so it's worth handling out of the box.
🤖 Generated with Claude Code