Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<Link download>renders<a download>, but its click handler still prevents the default and navigates with client-side routing, so the browser never downloads the file. With a static file such as<Link to="/report.csv" download>, the router navigates to/report.csv, no route matches, and the page shows the 404 boundary. The same happens to a custom link built withuseLinkClickHandler.shouldProcessLinkClickalready leaves clicks to the browser for non-left buttons, modifier keys andtarget="_blank". This adds the same check for an element with adownloadattribute:https://github.com/remix-run/react-router/blob/9916920a/packages/react-router/lib/dom/dom.ts#L34-L43
It reads the attribute from
event.currentTarget, sodownload,download="name.csv"and custom links are covered, anddownload={false}(which React does not render) still navigates as before. Links withoutdownloadare unchanged.flowchart TD A[User clicks a Link with download] --> B{Click handler} B -->|Before| C[Client side navigation to a 404 page] B -->|After| D[Browser downloads the file]Narrated recording, before then after (sound on):
evidence.mp4
The recording is the Framework Mode playground (
playground/framework,react-router dev) with apublic/report.csvand two links added locally (not part of this PR):<Link to="/report.csv" download>and<Link to="/report.csv" download="sales-2026.csv">. Before usesreact-routerbuilt frommain, after uses this branch.Edge cases and unchanged behaviour checked
In the running app, on this branch:
download="sales-2026.csv": the file is saved assales-2026.csv, the page stays on/./.ProductandHomelinks still navigate client side (same document, no reload).By tests only:
download={false}still navigates client side.useLinkClickHandleranddownloadleaves the click to the browser.Tests
link-click-test.tsx:<Link download>does not prevent default and stays on the page;<Link download={false}>still navigates.useLinkClickHandler-test.tsx: a custom link withdownloaddoes not prevent default.On
main(fix reverted):On this branch:
Integration tests were not run.
AI assistance (Claude Code) was used to find the bug, write the change and tests, and record the video.
🤖 Generated with Claude Code