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

Issue Mismatch ssr with dev__ssr for route with TrailingSlash #31996

Closed
simonjoom opened this issue Jun 19, 2021 · 2 comments
Closed

Issue Mismatch ssr with dev__ssr for route with TrailingSlash #31996

simonjoom opened this issue Jun 19, 2021 · 2 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@simonjoom
Copy link

simonjoom commented Jun 19, 2021

Mismatch ssr caused by location.pathname

I found an issue for route ending with a TrailingSlash
by example:
localhost/myroute/

if the route in .cache/match-paths.json contain without TrailingSlash
path: /myroute,

as a result location.pathname from Server is different than window.location.pathname from client
it's create SSR mismatch

solution to patch in src/utils/start-server.js ->

const renderResponse = await renderDevHTML({
path: pathObj.path,
page: pathObj,
skipSsr: req.query[`skip-ssr`] || false,
store,
htmlComponentRendererPath: `${program.directory}/public/render-page.js`,
directory: program.directory,
})

need to correct the path
replace pathObj.path to the original path req.path

    const renderResponse = await renderDevHTML({
      path: decodeURI(req.path), // patch
      page: pathObj,
      skipSsr: req.query[`skip-ssr`] || false,
      store,
      htmlComponentRendererPath: `${program.directory}/public/render-page.js`,
      directory: program.directory
    });

i did updated in reachroute the code below and it gave me this issue. (yes it s a snippet of old gatsby-link but it's work)
aria-current with test location.pathname === prefixedTo give true for client and false for Server due to the lack of "/" in the pathname

let Link = forwardRef(({ innerRef, ...props }, ref) => (
  <Location>
    {({ location, navigate }) => {
      let { to, state, replace, getProps = k, ...anchorProps } = props;
      // let href = resolve(to, baseuri);
      const prefixedTo = rewriteLinkPath(to, location.pathname)

      let isCurrent = location.pathname === prefixedTo;
      let isPartiallyCurrent = startsWith(location.pathname, prefixedTo);
      //ref={ref||innerRef}
      return (
        <a
          ref={innerRef}
          aria-current={isCurrent ? "page" : prefixedTo}
          {...anchorProps}
          {...getProps({ isCurrent, isPartiallyCurrent, prefixedTo, location })}
          href={prefixedTo}
          onClick={event => {
            if (anchorProps.onClick) anchorProps.onClick(event);
            if (shouldNavigate(event)) {
              event.preventDefault();
              navigate(prefixedTo, { state, replace });
            }
          }}
        />
      );
    }}
  </Location>
));

@simonjoom simonjoom added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 19, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 19, 2021
@simonjoom simonjoom changed the title Small issue ssr Small issue Mismatch ssr Jun 19, 2021
@simonjoom simonjoom changed the title Small issue Mismatch ssr Small issue Mismatch ssr with dev__ssr Jun 19, 2021
@simonjoom simonjoom changed the title Small issue Mismatch ssr with dev__ssr Issue Mismatch ssr with dev__ssr testing location.pathname with TrailingSlash Jun 19, 2021
@simonjoom
Copy link
Author

simonjoom commented Jun 19, 2021

one update on this patch
better to create an other param , else matchpath feature is broken

    const renderResponse = await renderDevHTML({
      path: pathObj.path,
      pathorigin: decodeURI(req.path), // patch
      page: pathObj,
      skipSsr: req.query[`skip-ssr`] || false,
      store,
      htmlComponentRendererPath: `${program.directory}/public/render-page.js`,
      directory: program.directory
    });

need to add param in all renderDevHTML access

like here

export default (pagePath, isClientOnlyPage, publicDir, error, callback) => {

to

export default (pagePath,pathorigin, isClientOnlyPage, publicDir, error, callback) => {

and

<ServerLocation url={`${__BASE_PATH__}${pagePath}`}>

change to

<ServerLocation url={`${__BASE_PATH__}${pathorigin}`}>

@simonjoom simonjoom changed the title Issue Mismatch ssr with dev__ssr testing location.pathname with TrailingSlash Issue Mismatch ssr with dev__ssr for route with TrailingSlash Jun 19, 2021
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 21, 2021
@LekoArts
Copy link
Contributor

Hi, thanks for the issue!

I see that your issue is about a specific experiment/flag we currently have. We collect any feedback (bug reports, feature requests, questions, etc.) inside a respective discussion in the Umbrella Discussions category.

Please direct your feedback here: #28138

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants