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

Error 500 Internal Server Error - products/[handle] #391

Closed
jiaweing opened this issue Nov 3, 2024 · 5 comments
Closed

Error 500 Internal Server Error - products/[handle] #391

jiaweing opened this issue Nov 3, 2024 · 5 comments

Comments

@jiaweing
Copy link

jiaweing commented Nov 3, 2024

I had an issue with the production build causing error 500 when I visit any product page.
This error does not appear in development mode.

I had to remove this function from src/app/[countryCode]/(main)/products/[handle]/page.tsx for it to work.

export async function generateStaticParams() {
  const countryCodes = await listRegions().then(
    (regions) =>
      regions
        ?.map((r) => r.countries?.map((c) => c.iso_2))
        .flat()
        .filter(Boolean) as string[]
  )
  if (!countryCodes) {
    return null
  }
  const products = await Promise.all(
    countryCodes.map((countryCode) => {
      return getProductsList({ countryCode })
    })
  ).then((responses) =>
    responses.map(({ response }) => response.products).flat()
  )
  const staticParams = countryCodes
    ?.map((countryCode) =>
      products.map((product) => ({
        countryCode,
        handle: product.handle,
      }))
    )
    .flat()
  return staticParams
}

Not sure if this is just an edge case but hope it helps someone here.

@felixguerrero12
Copy link

You need to make sure all your products has the slug listed on the product.

@ouestlabs
Copy link

ouestlabs commented Nov 11, 2024

Issue #396
PR #399

Add the following configuration to /src/app/[countryCode]/(main)/products/[handle]/page.tsx:

// ... existing imports ...

// Add this line at the top of the file
export const dynamic = "force-dynamic"

// ... rest of the file remains unchanged ...

@chillpilllike
Copy link

Thanks a simple line of code fixed the issue, what about the code offered in:

#393

It was pushed to the repo update. should we stick to the old and add
export const dynamic = "force-dynamic"
or use the code 393

@ouestlabs
Copy link

Thanks a simple line of code fixed the issue, what about the code offered in:

#393

It was pushed to the repo update. should we stick to the old and add export const dynamic = "force-dynamic" or use the code 393

Yo can use both the fix in #393 work well.

force-dynamic forces the page to be dynamically rendered on every request, disables static optimization and caching, makes sure the page is server-side rendered (SSR) on each request

@ouestlabs
Copy link

ouestlabs commented Nov 16, 2024

Dynamic Pages Not Accessible After Build (Collections/Categories/Products)

Related Issues

Description

After building the store, newly added content (collections, categories, and products) in the Medusa admin are not accessible, resulting in DYNAMIC_SERVER_USAGE errors in production.

Current Behavior

  • Accessing new collections/categories/products added after build results in error:
[Error: An error occurred in the Server Components render.]
{ digest: 'DYNAMIC_SERVER_USAGE' }

Root Cause

The pages are using generateStaticParams for static generation, which creates pages only for content that exists during build time. New content added after build cannot be accessed.

Quick Solution

Add export const dynamic = 'force-dynamic' to the following files:

  1. containers/store/src/app/[countryCode]/(main)/collections/[handle]/page.tsx
  2. containers/store/src/app/[countryCode]/(main)/categories/[...category]/page.tsx
  3. containers/store/src/app/[countryCode]/(main)/products/[handle]/page.tsx

This solution aligns with the fix provided in issue #391 and extends it to collections and categories pages.

Implementation

// Add to the top of each file:
export const dynamic = 'force-dynamic'

// Comment out or remove generateStaticParams() in each file

Trade-offs

  • Pros:
    • All content will be accessible regardless of when it's added
    • Consistent behavior across products, collections, and categories
    • Simple implementation
  • Cons:
    • Slightly slower initial page load compared to static generation
    • No caching benefits from static generation

Notes

resolves the issue for these pages as well. This happens when adding new collections/categories after the build.

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

5 participants