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

NextJs dynamic path variables do not appear in router.query on initial page load, when basePath is changed and middleware exists #52051

Closed
1 task done
tasfik007 opened this issue Jun 30, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.

Comments

@tasfik007
Copy link

Verify canary release

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

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #23-Ubuntu SMP PREEMPT_DYNAMIC Wed May 17 16:55:20 UTC 2023
    Binaries:
      Node: 16.13.0
      npm: 8.1.0
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.3.0
      eslint-config-next: 11.1.0
      react: 17.0.2
      react-dom: 17.0.2

warn  - Latest canary version not detected, detected: "12.3.0", newest: "13.4.8-canary.13".
        Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
        Read more - https://nextjs.org/docs/messages/opening-an-issue

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/tasfik007/subpath-test

To Reproduce

  1. Initialize a NextJS application
  2. Change the basePath in the .next.config.js file
  3. Add a middleware.js file

Describe the Bug

I have a NextJS application, recently I changed the basePath of my application in next.config.js file just added the basePath key with my desired path.

After doing that I noticed dynamic path variables that were passed through slugs (e.g. /something/[id].js) are not getting loaded initially in next's router.query (in this case id), but after a full page reload it appears perfectly. Surprisingly the variables were also accessible in the getServerSideProp's context.

Now this only happens if I have a middleware file (middleware.js) in my project. This issue happens even if I do nothing in the middleware.

Expected Behavior

Dynamic variables that are passed through the slugs should be loaded in router.query first time user loaded on the page.

Which browser are you using? (if relevant)

Firefox Browser - 114.0.2 (64-bit)

How are you deploying your application? (if relevant)

No response

@tasfik007 tasfik007 added the bug Issue was opened via the bug report template. label Jun 30, 2023
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. labels Jun 30, 2023
@BrunoFerreira95
Copy link

hmmm, one question in the url after run the project the path dynamic, show, in the browser, when you acesses the route ?

@tasfik007
Copy link
Author

hmmm, one question in the url after run the project the path dynamic, show, in the browser, when you acesses the route ?

yes, I can see the dynamic path variable in the route itself in the browser when I first land in.

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label Feb 17, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

3 participants