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

Unclear documentation around precompute #73

Open
mastoj opened this issue Feb 22, 2025 · 3 comments
Open

Unclear documentation around precompute #73

mastoj opened this issue Feb 22, 2025 · 3 comments

Comments

@mastoj
Copy link

mastoj commented Feb 22, 2025

I started experimenting with flags for real in preparation migrating our production site to it instead of using our own solution. I did find some issues around precompute.

I'm testing with canary since I also want to run with dynamicIO, so it might be that is what causing the issue.

The code for the sample is here: https://github.com/mastoj/flags-experiment

I have a very simple middleware where I calculate the code: https://github.com/mastoj/flags-experiment/blob/3f3569987306ce6c2f7ddf31441a35820ae2bf10/middleware.ts#L15-L20

and a very simple page: https://github.com/mastoj/flags-experiment/blob/main/app/%5Bcode%5D/%5Bslug%5D/page.tsx

The issue I get when building is:

Collecting page data ..[Error: A required root parameter (code) was not provided in generateStaticParams for /[code], please provide at least one value.]

Build error occurred
[Error: Failed to collect page data for /[code]] { type: 'Error' }

I actually thought that I could use

export async function generateStaticParams() {
  return [];
}

but for some reason { code: } is required... but that would also mean creating something static. I do want it SSR and cached, but not during build time.

Is I doing something wrong with flags or have I misunderstood something with dynamicIO?

To reproduce you should be able to pull down the code and the:

pnpm install
pnpm run build
@mastoj
Copy link
Author

mastoj commented Feb 23, 2025

I'm do think my issue is more related to dynamicIO than it is to flags, but not 100% sure.

@dferber90
Copy link
Collaborator

I tried looking into this, but I'm not sure how to reproduce the problem you are seeing.

Can you describe the steps? Here is what I did

  1. create FLAGS_SECRET in .env using node -e "console.log(crypto.randomBytes(32).toString('base64url'))"
  2. enable dynamicIO in next.config.js
  3. remove .well-known/vercel/flags as I don't have the EDGE_CONFIG set up
  4. adapt dummy-adapter.ts to always return false as we don't have the EDGE_CONFIG
  5. run pnpm dev and visit http://localhost:3000/foo, this works
  6. run pnpm build and get an error message
Error occurred prerendering page "/[code]". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/[code]" has a `generateMetadata` that depends on Request data (`cookies()`, etc...) or external data (`fetch(...)`, etc...) but the rest of the route was static or only used cached data (`"use cache"`). If you expected this route to be prerenderable update your `generateMetadata` to not use Request data and only use cached external data. Otherwise, add `await connection()` somewhere within this route to indicate explicitly it should not be prerendered.
Export encountered an error on /[code]/page: /[code], exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null

This is a different error than you described. It's interesting as there is no generateMetadata.

@mastoj
Copy link
Author

mastoj commented Feb 24, 2025

@dferber90 , it looks like you get that error when the layout.tsx is in the level above "/[code]", if you have layout in code folder you do get the error I mentioned: https://github.com/mastoj/flags-experiment/tree/missing-code (created specific branch for it)

After moving things around and adding the "use cache" directive to all places I think it needs to be added I still get an error, but now it is USE_CACHE_TIMEOUT: https://github.com/mastoj/flags-experiment/tree/cache-timeout

You should be able to pull down the branches and do install then pnpm run build.

This is not critical since it seems to be working fine if you don't use dynamicIO and this is most likely an issue with that... at the same time, it is always nice if one could end up in the pit of success also for things that are coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants