Skip to content

Parse a captured srcset with the shared comma-safe splitter - #4785

Closed
aagam-shah wants to merge 1 commit into
feat/site-artifact-import-clifrom
fix/dla-wix-srcset-localization
Closed

Parse a captured srcset with the shared comma-safe splitter#4785
aagam-shah wants to merge 1 commit into
feat/site-artifact-import-clifrom
fix/dla-wix-srcset-localization

Conversation

@aagam-shah

Copy link
Copy Markdown
Contributor

Stacked on feat/site-artifact-import-cli, where capture-export.ts lives.

What breaks

An image-service URL can carry its transform in the path, commas and all: /v1/fill/w_58,h_57,al_c,q_85,enc_avif,quality_auto/file.png. When a page uses those as relative srcset candidates, the export drops every candidate but the first and logs the transform parameters (/h_57, /al_c, /q_85, /enc_avif) as uncaptured same-origin dependencies.

Found while capturing https://aagam94.wixsite.com/mysite with the deterministic capture engine.

Cause

retainedMediaReferencesByFamily falls back to srcset.split(',') when no candidate is an absolute URL, so it reads the transform parameters as candidate URLs. Those real candidates then get no local replacement, and the dangling-reference pass removes them.

Fix

Use srcsetReferences(), the splitter the other two srcset readers in this file already share.

How to test

npx vitest run src/lib/capture-export.test.ts in packages/data-liberation-agent. The new test fails before the change and passes after. Committed dist/ bundles were rebuilt.

🤖 Generated with Claude Code

@aagam-shah

Copy link
Copy Markdown
Contributor Author

The red Data Liberation check is not from this change. It is already red on the base branch and on the other PR stacked on it: a pristine checkout of feat/site-artifact-import-cli rebuilds dist/ to different bytes, so the committed bundles there are stale on their own. I rebuilt and committed the bundles for the files this change touches.

An image-service URL can carry its transform in the path, commas and all
(`/v1/fill/w_58,h_57,al_c,q_85,enc_avif,quality_auto/file.png`).
retainedMediaReferencesByFamily still split such a srcset on every comma
when no candidate was absolute, so it read the transform parameters as
URLs instead of the candidates. Those candidates then had no local
replacement: the export dropped them from the srcset and logged the
fragments as uncaptured dependencies.

Use srcsetReferences(), the splitter the other two srcset readers in this
file already share.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wn8SVBiej94XzzDiXqtWyg
@aagam-shah
aagam-shah force-pushed the fix/dla-wix-srcset-localization branch from dd23234 to cdd4723 Compare September 8, 2026 06:47
@aagam-shah

Copy link
Copy Markdown
Contributor Author

Rebased onto the current tip of feat/site-artifact-import-cli (227773f0). The branch was 10 commits behind and the PR had gone conflicting. Two things moved:

  • dist/cli.bundle.mjs is gone from the diff. The base deleted it and the bundler no longer emits it, so I took that deletion and rebuilt only capture-engine.bundle.mjs and mcp-server.bundle.mjs. A pristine rebuild of the base is byte-identical here, so the bundle diff is only this change: one call site to the naive splitter drops out of each bundle.
  • Reformatted one line of the new test to keep prettier quiet. No behaviour change.

The source fix itself merged clean — it is in retainedMediaReferencesByFamily around line 831, and the base's edits to this file are down in exportWebsiteCapture around line 1706.

Re-checked the defect on the new base: still reproduces. Without the fix the test gets "/media/asset.png 1x" instead of "/media/asset.png 1x, /media/asset.png 2x" — the 2x candidate is still dropped. Package suite is 899 passing, tsc --noEmit is clean, and eslint reports the same 13 pre-existing errors as the base, so nothing new.

@aagam-shah
aagam-shah requested review from chubes4 and a balanced review from Copilot September 8, 2026 07:38

Copilot AI 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.

🟢 Approval recommended

The focused fix is consistent with existing parsing paths and has targeted regression coverage.

Pull request overview

Uses the existing comma-safe parser to correctly localize relative srcset URLs containing commas.

Changes:

  • Reuses srcsetReferences() for retained media detection.
  • Adds regression coverage for transformed image URLs.
File summaries
File Description
capture-export.ts Uses the shared srcset parser.
capture-export.test.ts Tests comma-containing relative candidates.
Review details
  • Files reviewed: 2/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chubes4

chubes4 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @aagam-shah. Your srcset fix and regression test have been ported upstream and merged in Automattic/data-liberation-agent#171, then included in the refreshed vendor in #3952. I verified the implementation and test against your original contribution. The fix is now present in this PR’s base branch; #3952 itself remains draft and has not landed in Studio trunk.

I failed to preserve your author/co-author attribution on the upstream port before merging it. That was my mistake. I have corrected the upstream PR description to credit you explicitly and link this PR and your original commit, including its original AI-assistance provenance. This does not change the already-merged DLA commit’s author metadata. Your original commit and co-author trailer remain in #3952’s history.

I am closing this stacked PR as superseded by its refreshed base, not as a claim that Studio trunk has shipped the fix.

AI assistance: GPT-6 Astra via OpenCode verified source/test equivalence and prepared this attribution and integration update. The earlier upstream port was performed with GPT-5.6 Terra via OpenCode.

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