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

When using a dynamic api (cookies, headers,..) inside a server action then later call this function inside ANOTHER server action building the app fails without telling you why! #74531

Closed
elbasel42 opened this issue Jan 5, 2025 · 1 comment
Labels
bug Issue was opened via the bug report template. Documentation Related to Next.js' official documentation. dynamicIO Related to dynamicIO. Instrumentation Related to Next.js Instrumentation. Linting Related to `next lint` or ESLint with Next.js. Module Resolution Module resolution (CJS / ESM, module resolving). Output (export/standalone) Related to the the output option in `next.config.js`. Runtime Related to Node.js or Edge Runtime with Next.js. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@elbasel42
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/nameless-cookies-go8s7s

To Reproduce

// actions.ts
"use server"
async func getUserId() => cookies().userId // use of the dynamic api cookies();

async func getUserInfo() => {
   const userId = getUser();
   const cards = db.getUserCards(userId))
}
// page.tsx
async func HomePage => {
   // Here `getUserInfo` will invoke `getUserId` internally which itself uses the dynamic cookies() api
   // This should make next use `export const dynamic = 'force-dynamic'` for this page so you don't have to explicitly set it.
   // BUT this results in weird behavior which makes the page pre-render at build time however it shouldn't  (because it relies on a dynamc api and data won't be available at build time) it STILL builds and pre-render the page somehow!!! 
   // But at one point it also gives build errors that are not very clear and don't show the reason of why the build has failed
   // However After explicitly using `export dynamic = 'force-dynmaic`  on the page  the build error is gone and the build completes fine but doesn't statically pre-prender the page.
    const userInfo  = await getUserInfo()
}




### Current vs. Expected behavior

Current Behavior: 
Doesn't warn you that if you use a dynamic api like cookies() inside a server action on a page that doesn't explicitly set `export const dynamic='force-dynamic'` will cause a silent build error / cause weird behavior and says in the documentation that these pages will implicitly have the `force-dynamic` route config.

Expected:
Warning at build / run / typescript level  

### Provide environment information

```bash
Node.js v22.12.0

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 16:04:27 +0000
  Available memory (MB): 15684
  Available CPU cores: 16
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.8.0
Relevant Packages:
  next: 15.1.3 // Latest available version is detected (15.1.3).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: N/A
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Developer Experience, Documentation, dynamicIO, Instrumentation, Linting, Module Resolution, Output (export/standalone), Runtime, Upstream

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

No response

@elbasel42 elbasel42 added the bug Issue was opened via the bug report template. label Jan 5, 2025
@github-actions github-actions bot added Developer Experience Documentation Related to Next.js' official documentation. dynamicIO Related to dynamicIO. Instrumentation Related to Next.js Instrumentation. Linting Related to `next lint` or ESLint with Next.js. Module Resolution Module resolution (CJS / ESM, module resolving). Output (export/standalone) Related to the the output option in `next.config.js`. Runtime Related to Node.js or Edge Runtime with Next.js. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). labels Jan 5, 2025
@ztanner
Copy link
Member

ztanner commented Jan 9, 2025

Hi,

The provided reproduction appears to be an empty codesandbox template. We're unable to investigate your report without a minimal reproduction.

@ztanner ztanner closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 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. Documentation Related to Next.js' official documentation. dynamicIO Related to dynamicIO. Instrumentation Related to Next.js Instrumentation. Linting Related to `next lint` or ESLint with Next.js. Module Resolution Module resolution (CJS / ESM, module resolving). Output (export/standalone) Related to the the output option in `next.config.js`. Runtime Related to Node.js or Edge Runtime with Next.js. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

No branches or pull requests

2 participants