remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
30.17k stars 2.56k forks source link

[SingleFetch][basename] root data endpoint is outside basename #10212

Open freeman opened 2 weeks ago

freeman commented 2 weeks ago

Reproduction

You can see the issue on this code sandbox: https://codesandbox.io/p/devbox/zwd9rl

If you hit the "Increment" button you will get an error that is due to vite rejecting the request to /foo.data as it is outside the vite base (== remix basename) which is "/foo/".

I think this was introduced involuntarily by #9792 as it tries to prevent the /.data url format.

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (2) x64 AMD EPYC
    Memory: 919.50 MB / 4.01 GB
    Container: Yes
    Shell: Unknown
  Binaries:
    Node: 20.9.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
  npmPackages:
    @remix-run/css-bundle: ^2.14.0 => 2.14.0 
    @remix-run/dev: ^2.14.0 => 2.14.0 
    @remix-run/node: ^2.14.0 => 2.14.0 
    @remix-run/react: ^2.14.0 => 2.14.0 
    vite: ^5.4.11 => 5.4.11 

Used Package Manager

pnpm

Expected Behavior

I would expect requests for the root/_index data loader when a basename (/foo/ for example) is present to honor it and use either :

Actual Behavior

When a basename is configured root/index loader data url goes outside of the basename.

freeman commented 2 weeks ago

I think this impact React Router v7 as well though I have not verified it there.

ssaegrov commented 1 week ago

We encounter the same problem when trying to enable single fetch in our application with basename in the config.

On the first render the root route renders perfectly and we can navigate to other routes in the application and everything seems to work fine. Whenever we click a link which points to root it fails.

<NavLink to={"/"}>
  Root path
</NavLink>

Unable to decode turbo-stream response from URL: http://localhost:3000/foo.data

freeman commented 1 week ago

Someone posted the same issue on RR and kindly provided a patch for remix that works great in my tests: https://github.com/remix-run/react-router/issues/12295