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

next/router fails to fetch data (getServerSideProps) when dynamic route contains an @ (at) symbol #39271

Closed
1 task done
visnup opened this issue Aug 2, 2022 · 5 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@visnup
Copy link
Contributor

visnup commented Aug 2, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:22 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T6000
Binaries:
  Node: 16.16.0
  npm: 8.11.0
  Yarn: 1.22.19
  pnpm: 7.8.0
Relevant packages:
  next: 12.2.4-canary.9
  eslint-config-next: 12.2.3
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Safari 15.6 (17613.3.9.1.5), Chrome 104.0.5112.79 (Official Build) (arm64)

How are you deploying your application? (if relevant)

next start, Vercel

Describe the Bug

When using router.replace(router.asPath) to "reload" a page, data fetching/getServerSideProps isn't called for a dynamic route containing an @ (at symbol) and in production.

In development, it works.
If the dynamic route doesn't contain an @, it works.
If the route isn't dynamic (and instead in a file like @foo.tsx), it works.
<12.1.7-canary.36 works (aka bug was introduced in =12.1.7-canary.36).

Expected Behavior

data fetching/getServerSideProps should still be called. In all other cases, it continues to be called, just not this very specific case.

Link to reproduction

https://codesandbox.io/s/router-at-0vx48i-0vx48i?file=/pages/%5Bslug%5D.tsx

To Reproduce

The above code sandbox is deployed at https://csb-0vx48i.vercel.app/@slug

  1. Create a page at pages/[slug].js:
import Link from "next/link";
import { useRouter } from "next/router";

export function getServerSideProps() {
  return { props: { value: Math.random() } };
}

export default function Slug({ value }) {
  const router = useRouter();
  return (
    <div>
      <p>
        Clicking on the link or button below should call `getServerSideProps`
        and load a new random value.
      </p>
      <p>
        <Link href="/@slug">
          <a>Link {value}</a>
        </Link>
      </p>
      <p>
        <button onClick={() => router.replace(router.asPath)}>
          Replace {value}
        </button>
      </p>
    </div>
  );
}
  1. next build; next start
  2. Navigate to https://localhost:3000/@foo
  3. Click on the link or button one or two times: a new random value will not be generated
@visnup visnup added the bug Issue was opened via the bug report template. label Aug 2, 2022
@visnup
Copy link
Contributor Author

visnup commented Aug 3, 2022

This also fails if the path contains a , (comma). Both @ and , are characters that get re-encoded as %40 and %2c when passed through route.push({ query }).

@visnup
Copy link
Contributor Author

visnup commented Aug 10, 2022

Has anyone had a chance to look at this?

@visnup
Copy link
Contributor Author

visnup commented Aug 12, 2022

Duplicates #38581

@ijjk
Copy link
Member

ijjk commented Aug 12, 2022

Closing as a duplicate per above

@ijjk ijjk closed this as completed Aug 12, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants