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

Dynamic params in edge API routes #48263

Closed
1 task done
vitalikda opened this issue Apr 11, 2023 · 7 comments · Fixed by #48370
Closed
1 task done

Dynamic params in edge API routes #48263

vitalikda opened this issue Apr 11, 2023 · 7 comments · Fixed by #48370
Labels
bug Issue was opened via the bug report template.

Comments

@vitalikda
Copy link

vitalikda commented Apr 11, 2023

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 22.4.0: Mon Mar  6 21:01:02 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8112
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 8.1.1
    Relevant packages:
      next: 13.3.0
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

warn  - Latest canary version not detected, detected: "13.3.0", newest: "13.3.1-canary.4".
        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)

No response

Link to the code that reproduces this issue

https://github.com/vitalikda/edge-api-route-dynamic-params

To Reproduce

Create edge api route with dynamic param and try to access it in production

Describe the Bug

When you try to access dynamic params from url, it’s prepend with nextParam string in production, so you can’t access the param

Example

Edge Api route: https://github.com/vitalikda/edge-api-route-dynamic-params/blob/main/src/pages/api/%5Bid%5D/index.ts

  • in dev mode req.nextUrl.searchParams.get('id') returns ID
  • in prod: req.nextUrl.searchParams.get('id') returns null

Looking at the next url, there is prefix nextParam - ?nextParamid=hello-world

Here is repo: https://github.com/vitalikda/edge-api-route-dynamic-params
Here is preview: https://edge-api-route-dynamic-params.vercel.app/

Expected Behavior

Url search param should be accessible as in nodejs runtime

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@vitalikda vitalikda added the bug Issue was opened via the bug report template. label Apr 11, 2023
@vitalikda
Copy link
Author

I have updated next to the latest canary version - same result

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:01:02 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8112
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 8.1.1
    Relevant packages:
      next: 13.3.1-canary.4
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

@johnpgr
Copy link

johnpgr commented Apr 13, 2023

I am having this same issue on edge runtime with dynamic segments, accessing params props on the page, throws type error.

TypeError: Cannot read properties of undefined (reading 'orderId')
    at (node_modules/.pnpm/next@13.3.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/esm/server/app-render/app-render.js:175:0)

ijjk added a commit that referenced this issue Apr 14, 2023
Ensures we have coverage for edge API routes in pages so we don't
regress.

Closes: #48263
@pdparchitect
Copy link

pdparchitect commented Apr 21, 2023

Folks you have introduced a breaking change in 13.3 with zero documentation. It breaks assumptions and there is hardly anything in your CI to prevent breaking the build.

To add more colour to the above.

Considering that your edge functions API is hardly that stable and there is no way to access the query accept parsing the actual URL (part of your docs) changing the query parameters by prefixing is going to break things!

@garciajg
Copy link

Any news on this issue?

@timneutkens
Copy link
Member

This was fixed on next@canary. New stable going out today/tomorrow 👍

@vitalikda
Copy link
Author

Fixed! Updated example repo 👌

@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 Jun 30, 2023
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

Successfully merging a pull request may close this issue.

6 participants
@pdparchitect @timneutkens @garciajg @vitalikda @johnpgr and others