Skip to content

fix(shopify): update color filter handling in toFilter function - #1650

Closed
luanargolodev wants to merge 1 commit into
deco-cx:mainfrom
luanargolodev:fix/filters
Closed

fix(shopify): update color filter handling in toFilter function#1650
luanargolodev wants to merge 1 commit into
deco-cx:mainfrom
luanargolodev:fix/filters

Conversation

@luanargolodev

@luanargolodev luanargolodev commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What is this Contribution About?

Please provide a brief description of the changes or enhancements you are proposing in this pull request.

Issue Link

Please link to the relevant issue that this pull request addresses:

Loom Video

Record a quick screencast describing your changes to help the team understand and review your contribution. This will greatly assist in the review process.

Demonstration Link

Provide a link to a branch or environment where this pull request can be tested and seen in action.


Summary by cubic

Fixes color filter handling in toFilter by mapping filter.v.t.shopify.color-pattern values to taxonomyMetafield.value from value.input instead of the label. This ensures accurate filter values and URLs for color selections.

Written for commit f3e024f. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved color-pattern filter handling so color options use the correct Shopify taxonomy values.
    • Preserved existing behavior for all other filters, including selection states and filter URLs.

@github-actions

Copy link
Copy Markdown
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.160.1 update
  • 🎉 for Minor 0.161.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

toFilter now uses the taxonomy metafield value for Shopify color-pattern filter options while preserving label-based values for all other non-RANGE filters.

Changes

Color filter transformation

Layer / File(s) Summary
Color-pattern option value mapping
shopify/utils/transform.ts
The non-RANGE filter mapping parses color-pattern option input and uses taxonomyMetafield.value; other filters continue using value.label.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: yuriassuncx

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has the template headings but leaves the issue, Loom, and demonstration sections unfilled. Add the actual issue link, Loom video link, and demonstration link, and replace the placeholder contribution text with a brief summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: Shopify color filter handling in toFilter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shopify/utils/transform.ts`:
- Around line 335-337: Update the color-filter branch in the filter value
mapping to use the existing getFilterValue(value) helper, or equivalent guarded
parsing, instead of directly accessing
JSON.parse(value.input).taxonomyMetafield.value. Preserve the label fallback for
malformed JSON or missing taxonomyMetafield so toFilter continues returning a
valid filter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 132bd84a-c18b-41dc-bf60-5a1db969617f

📥 Commits

Reviewing files that changed from the base of the PR and between 292aed0 and f3e024f.

📒 Files selected for processing (1)
  • shopify/utils/transform.ts

Comment on lines +335 to +337
value: !isColorFilter
? value.label
: JSON.parse(value.input).taxonomyMetafield.value,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Avoid unguarded parsing of color-filter input.

JSON.parse(value.input).taxonomyMetafield.value throws when an option has malformed JSON or a missing taxonomyMetafield, causing toFilter—and therefore the ProductListingPage filter mapping—to fail. Reuse getFilterValue(value) or add equivalent guarded parsing with a label fallback.

Proposed fix
-          value: !isColorFilter
-            ? value.label
-            : JSON.parse(value.input).taxonomyMetafield.value,
+          value: !isColorFilter ? value.label : getFilterValue(value),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
value: !isColorFilter
? value.label
: JSON.parse(value.input).taxonomyMetafield.value,
value: !isColorFilter ? value.label : getFilterValue(value),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shopify/utils/transform.ts` around lines 335 - 337, Update the color-filter
branch in the filter value mapping to use the existing getFilterValue(value)
helper, or equivalent guarded parsing, instead of directly accessing
JSON.parse(value.input).taxonomyMetafield.value. Preserve the label fallback for
malformed JSON or missing taxonomyMetafield so toFilter continues returning a
valid filter.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="shopify/utils/transform.ts">

<violation number="1" location="shopify/utils/transform.ts:337">
P1: Unsafe `JSON.parse(value.input)` without error handling. If `value.input` contains malformed JSON — or if the parsed result has a null/undefined `taxonomyMetafield` — this line will throw a runtime exception that crashes the entire `toFilter` function, breaking the collection page for any shopify category with color-pattern filters.

Notice that the existing `getFilterValue` function in the same file (line ~370) follows a robust try/catch pattern for the exact same operation, including null-safe property traversal. This new code diverges from that established safety pattern.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

value: value.label,
value: !isColorFilter
? value.label
: JSON.parse(value.input).taxonomyMetafield.value,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Unsafe JSON.parse(value.input) without error handling. If value.input contains malformed JSON — or if the parsed result has a null/undefined taxonomyMetafield — this line will throw a runtime exception that crashes the entire toFilter function, breaking the collection page for any shopify category with color-pattern filters.

Notice that the existing getFilterValue function in the same file (line ~370) follows a robust try/catch pattern for the exact same operation, including null-safe property traversal. This new code diverges from that established safety pattern.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At shopify/utils/transform.ts, line 337:

<comment>Unsafe `JSON.parse(value.input)` without error handling. If `value.input` contains malformed JSON — or if the parsed result has a null/undefined `taxonomyMetafield` — this line will throw a runtime exception that crashes the entire `toFilter` function, breaking the collection page for any shopify category with color-pattern filters.

Notice that the existing `getFilterValue` function in the same file (line ~370) follows a robust try/catch pattern for the exact same operation, including null-safe property traversal. This new code diverges from that established safety pattern.</comment>

<file context>
@@ -330,7 +332,9 @@ export const toFilter = (filter: FilterShopify, url: URL): Filter => {
-          value: value.label,
+          value: !isColorFilter
+            ? value.label
+            : JSON.parse(value.input).taxonomyMetafield.value,
           selected: isSelectedFilter(value, url),
           url: filtersURL(filter, value, url),
</file context>

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