Skip to content

Stop mangling Wix image URLs in the media rewrite - #4784

Open
aagam-shah wants to merge 1 commit into
trunkfrom
fix/wix-transform-url-mangle
Open

Stop mangling Wix image URLs in the media rewrite#4784
aagam-shah wants to merge 1 commit into
trunkfrom
fix/wix-transform-url-mangle

Conversation

@aagam-shah

Copy link
Copy Markdown
Contributor

What breaks

Wix serves images as <file url>/v1/fill/<transform>/<name>. When the media rewrite knows the base file URL, it also replaced that URL inside every longer transform URL. The result is <local path>/v1/fill/w_58,h_57,.../file.png — a local path that resolves to nothing.

Found while capturing https://aagam94.wixsite.com/mysite with the deterministic capture engine: many src and srcset values came out as broken local paths.

Cause

rewriteMediaUrls does a plain substring replace per mapped URL. A mapped base URL is a strict prefix of every transform URL of the same image. Longest-first ordering only helps for transform URLs the candidate scan reaches (<img src>, srcset, JSON "src"/"url"). On any other surface — a data- attribute, a <video poster>, a <source src> — the base entry still matched the prefix and left the transform tail behind.

Fix

Refuse the substitution when the match is followed by /. That means a longer path, so it names a different resource. Keeping the remote URL there is correct; a mangled local path is a 404.

How to test

npx vitest run src/lib/streaming/media-url-rewrite.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

Wix serves images as `<file url>/v1/fill/<transform>/<name>`, so a mapped
base URL is a strict prefix of every transform URL of the same image. The
media rewrite substituted it anywhere it matched, turning a transform URL
into `<local path>/v1/fill/.../name.png` — a local path that resolves to
nothing. Longest-first ordering only covers transform URLs the candidate
scan reaches; anywhere else (a `data-` attribute, a `<video poster>`, a
`<source src>`) the base entry still mangled them.

Refuse the substitution when the match is followed by `/`. That is a
longer path, so it names a different resource: leaving the remote URL is
correct, while a mangled local path is a 404.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wn8SVBiej94XzzDiXqtWyg
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 2b9000c vs trunk

app-size

Metric trunk 2b9000c Diff Change
App Size (Mac) 1446.88 MB 1446.86 MB 0.02 MB ⚪ 0.0%

site-editor

Metric trunk 2b9000c Diff Change
load 1163 ms 1210 ms +47 ms ⚪ 0.0%

site-startup

Metric trunk 2b9000c Diff Change
siteCreation 7502 ms 7528 ms +26 ms ⚪ 0.0%
siteStartup 2877 ms 2890 ms +13 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

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 boundary check resolves the reported URL mangling and is covered by an appropriate regression test.

Pull request overview

Prevents Wix transform URLs from being partially rewritten into invalid local paths.

Changes:

  • Adds a slash boundary guard to media URL replacement.
  • Adds regression coverage for unrecognized HTML surfaces.
  • Rebuilds committed distribution bundles.
File summaries
File Description
src/lib/streaming/media-url-rewrite.ts Prevents prefix-only URL replacement.
src/lib/streaming/media-url-rewrite.test.ts Tests Wix transform preservation.
dist/scripts/chunk-FILKGPFX.mjs Updates bundled implementation.
dist/scripts/carry-reconstruct-drive.mjs References the rebuilt chunk.
dist/mcp-server.bundle.mjs Updates the shipped MCP bundle.
Review details
  • Files reviewed: 2/5 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.

@aagam-shah
aagam-shah requested a review from chubes4 September 8, 2026 06:35
@chubes4

chubes4 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @aagam-shah. Your fix and regression test have been ported upstream and merged in Automattic/data-liberation-agent#170, and are included in the refreshed vendor in #3952. I verified the transform-path guard and regression against your original commit.

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 explicitly credit you, link this PR and your original commit, and retain the original AI-assistance provenance. The merged DLA commit metadata is unchanged; I am not claiming the description repair restores Git authorship.

Your original commit remains in #3952’s history. This fix is not yet in Studio trunk, because #3952 remains draft. I am leaving this direct-to-trunk PR open rather than incorrectly treating upstream publication as Studio delivery.

AI assistance: GPT-6 Astra via OpenCode verified the 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.

4 participants