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

Server-side redirect from turbo stream to file download fails in Turbo 8 #1253

Open
asilano opened this issue May 2, 2024 · 0 comments
Open

Comments

@asilano
Copy link

asilano commented May 2, 2024

Steps to reproduce

Have HTML containing:

<a href="/maybe_a_file" data-turbo-stream="true">Download</a>

Backed by server code:

def maybe_a_file
  if error?
    # File doesn't exist - render a turbo-stream to display an error message
    return render "error_message"
  end

  redirect_to "/actual_file.txt"
end

Click the link (when error? returns false)

Expected behaviour

The redirect is followed, and the browser downloads and saves actual_file.txt

Actual behaviour

The redirect is followed, the browser requests actual_file.txt, and the server responds 200 OK with the contents of the file; but the file is not saved by the browser

Cause

Via git bisect, determined to be caused by #968 (thanks to @pythonandchips for digging)

Workaround

Instead of server-side redirecting to the file, return a turbo-stream action to visit the actual file URL in JS (both Turbo.visit and window.location.assign work fine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant