Skip to content

fix: support a single audience/campaign per selector in fragment manifests - #63

Merged
ramboz merged 1 commit into
v2from
fix/single-audience-campaign-manifest
Aug 12, 2026
Merged

fix: support a single audience/campaign per selector in fragment manifests#63
ramboz merged 1 commit into
v2from
fix/single-audience-campaign-manifest

Conversation

@ramboz

@ramboz ramboz commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

A fragment-level Audience Manifest (or Campaign Manifest) with a single audience/campaign per selector crashes the plugin.

parseAudienceManifest / parseCampaignManifest call audiences.forEach(...) / campaigns.forEach(...), but aggregateEntries only produces an array when a selector has multiple values — a selector with a single value leaves audience/campaign (and url) as a scalar string. String.prototype.forEach doesn't exist, so it throws audiences.forEach is not a function, which aborts loadEager and leaves the fragment un-personalized (window.hlx.audiences / .campaigns never gets set).

Every existing manifest fixture uses two audiences/campaigns per selector, so this single-value path was never exercised.

Fix

Normalize audience/campaign and url to 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 (waitForNamespace times out because the plugin threw) and pass after. Full audiences + campaigns suites 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

…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

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ramboz
ramboz merged commit 6f7b3e8 into v2 Aug 12, 2026
4 checks passed
@ramboz
ramboz deleted the fix/single-audience-campaign-manifest branch August 12, 2026 16:44
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))
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