Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-router Navigation Blocking: mistakenly blocks downloadable url #3203

Open
ManoelPradoMark22 opened this issue Jan 21, 2025 · 0 comments

Comments

@ManoelPradoMark22
Copy link

ManoelPradoMark22 commented Jan 21, 2025

Which project does this relate to?

Router

Describe the bug

The react-router Blocking identifies the File download from a downloadable url as a tentative of leaving the page.

Your Example Website or App

Live DEMO: https://manoelpradomark22.github.io/react-router-blocker-bug/editor-1

If wants the code: https://github.com/ManoelPradoMark22/react-router-blocker-bug (see the README)

P.S.: I based on this react-router example: https://tanstack.com/router/latest/docs/framework/react/examples/navigation-blocking

Steps to Reproduce the Bug or Issue

  1. go to: https://manoelpradomark22.github.io/react-router-blocker-bug/editor-1 (Editor 1 tab)
    2 . write something in Editor 1 input
  2. click in "DOWNLOAD CSV"
  3. note that the shouldBlockFn is triggered - and the only way to download the CSV is clicking in "Leave", which is not at all intuitive for the user

Image

const handleDownload = (url: string) => { const link = document.createElement("a"); link.href = url; document.body.appendChild(link); link.click(); document.body.removeChild(link); };
Note: the downloadable url example: https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv

I dont know why but when we use a directly downloadable url in the handleDownload function this triggers the shouldBlockFn, and the only way to download is clicking in Leave in window confirmation....
....Looks like the Blocker from react-router identifies the download as a shouldBlock action...

I know this is a very specific issued, but im trying to solve this but i didnt got this yet...

Expected behavior

When we fill the Editor 1 Input and click in Download CSV the react-router should NOT trigger the shouldBlockFn.

Screenshots or Videos

No response

Platform

  • OS: Wndows 11
  • Browser: Chrome
  • Version: 131.0.6778.266

Additional context

No response

@ManoelPradoMark22 ManoelPradoMark22 changed the title react-router Navigation Blocker blocks downloadable url react-router Navigation Blocking: mistakenly blocks downloadable url Jan 21, 2025
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

No branches or pull requests

1 participant