Skip to content

fix(react-router): let the browser handle clicks on <Link download> - #15815

Merged
brophdawg11 merged 4 commits into
remix-run:mainfrom
burrows99:fix/link-download-attribute
Nov 23, 2026
Merged

brophdawg11 merged 4 commits into
remix-run:mainfrom
burrows99:fix/link-download-attribute

Conversation

@burrows99

Copy link
Copy Markdown
Contributor

<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 with useLinkClickHandler.

shouldProcessLinkClick already leaves clicks to the browser for non-left buttons, modifier keys and target="_blank". This adds the same check for an element with a download attribute:

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, so download, download="name.csv" and custom links are covered, and download={false} (which React does not render) still navigates as before. Links without download are 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]
Loading

Narrated recording, before then after (sound on):

evidence.mp4

The recording is the Framework Mode playground (playground/framework, react-router dev) with a public/report.csv and two links added locally (not part of this PR): <Link to="/report.csv" download> and <Link to="/report.csv" download="sales-2026.csv">. Before uses react-router built from main, 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 as sales-2026.csv, the page stays on /.
  • Keyboard: Tab to the link and Enter: the file is downloaded, the page stays on /.
  • The Product and Home links still navigate client side (same document, no reload).

By tests only:

  • download={false} still navigates client side.
  • A custom link built with useLinkClickHandler and download leaves 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 with download does not prevent default.

On main (fix reverted):

Tests:       2 failed, 17 passed, 19 total

On this branch:

pnpm test packages/react-router/__tests__/dom/   # Tests: 864 passed (34 suites)
npx tsc --noEmit -p packages/react-router         # no errors
npx eslint / prettier --check on the changed files # clean

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

@brophdawg11 brophdawg11 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.

The download guard preserves native download clicks and custom hook navigation. The Jest suite covers click handling, and the focused Chromium fixture verifies navigation from a form with a control named matches. I reviewed this revision and the focused local checks passed.

Authored by an AI agent on behalf of @brophdawg11

@brophdawg11
brophdawg11 merged commit 59b2435 into remix-run:main Nov 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants