React-router: StaticRouter renders incorrect links when using server-side rendering

Created on 10 Feb 2017  路  2Comments  路  Source: ReactTraining/react-router

Version

4.0.0-beta.5

Test Case

I've created a demo Express app that lets you reproduce the bug:

https://github.com/pahund/universal-react-router4

Run the application using:

npm install && npm run build && npm start

Then point your browser to http://localhost:3000/

The application shows a list of Gists fetched from the GitHub API, similar to the app shown by Ryan in the react-router 4 introduction video.

Expected Behavior

The browser's JavaScript console shows the following warning:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) actid="3">BrowserRouter; Link elements for the Gists in the side bar render anchor tags with the correct URLs, e.g. _/g/f6230f5eed364763354be7b67e4aa6b7_

  • in the server, I'm using StaticRouter; Link elements for the Gists in the side bar render anchor tags with incorrect URLs, they have an additional slash prepended: _//g/f6230f5eed364763354be7b67e4aa6b7_
  • This causes the warning from React that the markup rendered on the server differs from that from the client.

    When you comment out the client-side rendering of the layout (lines 15-19 in src/client/index.js), you get only the server-side rendered page. When you click on any of the Gist links, you'll see that they are broken due to the prepended slash.

    Actual Behavior

    The Link element should render the correct URL when using StaticRouter for server-side rendering, without prepending a slash.

    Most helpful comment

    Fixed in #4484

    All 2 comments

    Fixed in #4484

    Confirmed, it works with the latest version of the v4 branch

    Was this page helpful?
    0 / 5 - 0 ratings