Repository navigation
fix(event): save inline rx.download data through a blob url - #7853
Conversation
iOS WebKit (every iOS browser and installed PWAs) ignores the download attribute of data: urls and only shows the file as text. The _download event turns a data: url into a blob: url and attaches the link to the document before clicking it.
b4b8c75 to
f335b00
Compare
[Medium impact] The PR appears safe to merge; the previous file-type issue is fixed. Summary
The previous file-type finding is fixed. No new actionable issues were found in the changes since the last review. Tests were inspected, not run. Reviews (10) · Last reviewed commit: "Default a data: url without a media type..." · Reviewed by Greptile |
Merging this PR will degrade performance by 6.38%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
A connect-src policy that does not allow data: urls blocks fetching one, so the _download event decodes the base64 or percent-encoded data itself before building the blob: url.
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…load like fetch A data: url handed to rx.download through a Var is passed on unchanged and may carry a fragment or percent-encode its base64 body. Drop the fragment and percent-decode the body before base64-decoding it, as the data url processor does.
|
@codspeedbot fix this regression |
|
The CodSpeed regression in test_route_matching[100] (−5.9%) is unrelated to this change: the PR only touches state.js, an integration test and a news fragment, none of which run in that benchmark. It matches the flaky ±5.5–5.9% swings of route_matching that #7878 describes, which come from the benchmark measuring a few lru_cache hits |
- A download without a filename gets "download" plus the type's extension, not the blob url's uuid. - Percent escapes decode with unescape instead of a callback per escape: a 1 MB CSV var decodes in 10 ms instead of 83 ms. - A data: url without a comma stays as it is instead of saving its own text. - The decoder moves to dataUrlToBlob, out of applyEvent.
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
A data: url such as "data:,hello" or "data:;base64,..." has no media type, and fetch decodes it as text/plain;charset=US-ASCII. dataUrlToBlob produced a Blob with an empty type instead, so a download without a filename lost its .txt extension. Apply the same default, and prefix text/plain when the url supplies only parameters such as a charset. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ESN8DiGC3xZjMWMjXyvzqa
main's #7853 adds dataUrlToBlob to state.js, which every stateful app ships: el_stateful js_gzip is 155,207 B against a 155,000 B limit that had 12 B of headroom. The limit becomes the measured value plus 5 %, like the other size budgets. Claude-Session: https://claude.ai/code/session_014AwvTPMyGMj9KHaq66r64v
iOS WebKit (Safari, every other iOS browser and installed PWAs) ignores the
downloadattribute ofdata:urls and only displays the file instead of saving it.rx.download(data=...)always produces adata:url, so it never saves a file on iOS.The
_downloadevent now turns adata:url into ablob:url before clicking the link, and attaches the link to the document first. It decodes the data itself, because aconnect-srcpolicy can block fetching adata:url. A download without afilenameis still nameddownloadwith the extension of its type. Regular urls are downloaded from the same url with the same name.Tests: a Playwright test downloads inline text from a frontend event,
data:urls from state, bytes from a backend event, and data without a filename. It asserts the blob url, file name and exact content, under aconnect-srcpolicy that blocks fetchingdata:urls. It fails without the fix.