Stop mangling Wix image URLs in the media rewrite - #4784
Conversation
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
📊 Performance Test ResultsComparing 2b9000c vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
There was a problem hiding this comment.
🟢 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.
|
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. |
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/mysitewith the deterministic capture engine: manysrcandsrcsetvalues came out as broken local paths.Cause
rewriteMediaUrlsdoes 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 — adata-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.tsinpackages/data-liberation-agent. The new test fails before the change and passes after. Committeddist/bundles were rebuilt.🤖 Generated with Claude Code