fix: targeting keys errors in browser and product pages #685
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.
Summary
Fixes JavaScript errors in the targeting browser and product pages when loading targeting keys and values.
Problem 1: TypeError in targeting browser
The
loadTargetingData()function was replacing the entiretargetingDataobject with the API response:The API response only includes
customKeys,audiences,labels, andlast_sync- it doesn't includecustomValues. This meant that when a user clicked on a targeting key, the code tried to accesstargetingData.customValues[keyId], which was undefined, causing:Problem 2: 401 errors on product pages
The targeting selector widget on product add/edit pages was making API calls without the
{{ script_name }}prefix, causing 401 unauthorized errors in subdomain-based tenant routing. The dropdown would show "-- Select a key --" but wouldn't load any targeting keys.Solutions
Fix 1: Preserve customValues cache (targeting browser)
Changed to merge the API data into existing targetingData properties instead of replacing the whole object:
This preserves the
customValuesproperty, which acts as a cache and gets populated on-demand when users click on targeting keys.Fix 2: Add script_name prefix (product pages)
Added
{{ script_name }}prefix to API endpoints in targeting_selector_simple.html:This matches the pattern used in targeting_browser.html and fixes the 401 routing errors.
Test plan
🤖 Generated with Claude Code