question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP 303 Redirects with anchor not respected

See original GitHub issue

Steps to Reproduce:

  • Redirect after a form submission (via HTTP 303) to a location that contains an anchor (e.g. Location: /path#anchor).

Observed Behavior:

  • The redirection occurs, but strips the anchor from the resulting page (e.g. /path instead of /path#anchor)
  • This results in any page rendering dependent upon this anchor to fail.

Expected Behavior

  • Redirect and expose the full path with the anchor in the resulting page’s address bar.

Workaround

  • Disable turbo on that particular form submission.

Wild Guess Hypothesis I suspect that the subsequent redirection fetch (from Turbo) strips the anchor tag from the underlying HTTP request (as expected), but when the page is re-hydrated, the address bar URL (pushstate) is not updated to reflect the original anchor.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:19
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
nickjjcommented, Jun 21, 2021

I’m seeing this behavior when performing any type of redirect after a successful form submission and the problem goes away if I disable Turbo. I’m also not using Rails so this is isolated to the JS library itself. I’m using beta 7 and I’m also not using frames or streams here. This is a basic full blown HTTP redirect.

Reproduceable steps:

  1. import * as Turbo from "@hotwired/turbo";

  2. Create a form where after the POST comes in, redirect to /#foo

  3. The #foo will get stripped out from the redirect

  4. Comment out the line from step 1 and do the same thing and now the anchor is kept in tact.

It’s worth pointing out params are kept in tact in either case. I’m only losing the anchor with Turbo.

4reactions
stebocommented, May 20, 2021

I can confirm that this is an issue and I find it quite an unexpected behavior and would love to use my anchors. Adding a tailing /does not solve the issue for me when doing redirects in the controller:

redirect_to '.../posts/433545#comment_221760128', status: :see_other
# gets redirected to /posts/433545

redirect_to '.../posts/433545/#comment_221760128', status: :see_other
# gets redirected to /posts/433545/

In both cases the anchor is lost. Using 301, 302, 303 makes no difference. The only solution right now is to set data-turbo=falseon the form.

Any ideas how to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirect with anchor and Turbo - Hotwire Discussion
I really need to redirect with an anchor. Based on the comments at HTTP 303 Redirects with anchor not respected · Issue #211...
Read more >
303 See Other - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 303 See Other redirect status response code indicates that the redirects don't link to the requested ...
Read more >
Why does my anchor link redirect to the same page?
This behaviour is due to your HTTP server which is either redirecting your back to / or serving up the same file for...
Read more >
URL Redirects - Squarespace Help Center
Invalid mapping: Not enough parts. This means that a redirect is missing the arrow (->) or the redirect type (301 or 302).
Read more >
How To Bulk Check Redirects - Screaming Frog
Check redirects for free by uploading a list of URLs in bulk or crawling a site. View the HTTP response code (301, 302)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found