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

[Bug]: Link to="//" no longer works #10005

Closed
mariorcosta opened this issue Jan 30, 2023 · 10 comments
Closed

[Bug]: Link to="//" no longer works #10005

mariorcosta opened this issue Jan 30, 2023 · 10 comments
Assignees
Labels

Comments

@mariorcosta
Copy link

mariorcosta commented Jan 30, 2023

What version of React Router are you using?

6.8.0

Steps to Reproduce

when linking to home using "//" to have the url ending with / no longer works with the newly minor version

Expected Behavior

redirect to the home page

Actual Behavior

Uncaught TypeError: Failed to construct 'URL': Invalid URL

@timdorr
Copy link
Member

timdorr commented Jan 30, 2023

#9994 might have an impact here? If not, it could be expanded to cover this case.

@brophdawg11
Copy link
Contributor

Hm - either of the implementations is going to detect // as a protocol-less URL and treat it as an absolute URL. @mariorcosta You're saying previously you used <Link to="//"> to force a trailing slash on your destination URL when linking back to the root route?

@mariorcosta
Copy link
Author

@brophdawg11 the goal was to ensure that the home URL ended with a '/' such as 'something.com/something/', but this is no longer necessary as it was only a temporary solution to a different issue.

However, there may still be some people who are impacted by this change.

@lkwr
Copy link
Contributor

lkwr commented Jan 31, 2023

What about changing the regex in #9994 to something like this:

/^(?:[a-z][a-z0-9+.-]*:|\/\/)./i

With an additional dot at the end. This ensure that at least one character is needed after the protocol (in this case the path of the uri).

https:// will no longer works but https://a(...) will do.
Same for //, which no longer works but //b(...) will do.

Are there protocols or use cases which can have an empty path in the uri? If yes, then this regex would not support it.

@MadaShindeInai
Copy link

MadaShindeInai commented Jan 31, 2023

Actually we can see this issue with '//' and '///' if we will try to visit https://remix.run// or https://remix.run///

In my app running locally I face different behaviour for '//' and '///' . ("react-router-dom": "^6.4.2",)

For '//' (UI shows blank screen) :
In browser:

Screenshot 2023-01-31 at 20 12 58

In VSCode terminal:
Screenshot 2023-01-31 at 20 34 17

For '///' (UI shows fallback declared in RouterProvider):

In browser:

Screenshot 2023-01-31 at 20 15 17

In deployed version for '//' I have the same behaviour as for '///'.
P.S. updated version to "react-router-dom": "^6.8.0", and see the same behaviour.

@brophdawg11
Copy link
Contributor

Hm, we may be getting some wires crossed here. The https://remix.run// issue is a known issue the Remix adapter layers (captured in remix-run/remix#4422, fixed in remix-run/remix#5336). That fix should go out in the next release.

I (maybe incorrectly) assumed this was a react-router-dom <Link> issue since it was opened here.

If there is a separate Link issue please provide a reproduction, otherwise I'll close this out once the linked Remix PR is released 👍

@brophdawg11
Copy link
Contributor

I'm going to close this out now that remix 1.13.0 is released with the linked fix for properly loading with a trailing double slash such as https://something.com//. If there are remaining issues please provide a reproduction and we can re-open this issue.

@MadaShindeInai
Copy link

MadaShindeInai commented Feb 15, 2023

@brophdawg11 i've updated RR to [email protected]. Problem with // still exists. AFAIK RR and Remix now is the same. Should i wait for extra fix for RR, or it should be already fixed?
https://reactrouter.com//

@MadaShindeInai
Copy link

@brophdawg11 Hello! Any news about that issue?

@brophdawg11
Copy link
Contributor

React Router and Remix are mostly the same but not entirely. Remix has en entire compiler and server-adapter layer on top of React Router. This thread, based on the examples provided, is referring to a bug that existed in the Remix server-adapter code and was fixed in Remix 1.13.0. https://reactrouter.com has not been updated to Remix 1.13.0 so it still exhibits the issue.

If there is an issue with http://{origin}// in React Router apps, please provide a reproduction and we can dig into it. At a quick glance it seems to work fine for me using examples/basic/ on the latest version of react-router-dom:

Screenshot 2023-02-24 at 9 26 01 AM

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

No branches or pull requests

5 participants