Nextjs: loading or suspense fallback doesn't show up in production
P粉685757239
P粉685757239 2024-03-27 18:50:05
0
1
387

I have migrated my personal pages to the application directory using nextjs v13.

I tried first adding the RSC loader in the fallback attribute of the Suspense component and adding the # in the path of each route located in the app directory ##loading Components.

// src/app/posts/loading.tsx
import { Container } from '~/components/organisms/container';

export default function Loading() {
  return (
    <Container>
      {/* Add a big loading string with tailind */}
      <span className="text-6xl font-bold text-center text-red-500">Loading...</span>
    </Container>
  );
}

There is also this

// src/app/posts/page.tsx
export default async function PostsPage() {
  return (
    <Container>
      <PageHeader
        title='Posts'
        description="I love to write about things I'm learning. 
            Blogging is a great way to improve and share knowledge.
            And who knows, maybe one day it might help me to write a book!"
      />
      <Suspense
        fallback={
          <Container>
            {/* Add a big loading string with tailind */}
            <span className='text-6xl font-bold text-center text-red-500'>
              Loading...
            </span>
          </Container>
        }
      >
        {/* @ts-expect-error Server Component */}
        <Posts />
      </Suspense>
    </Container>
  );
}

Both are committed to local development

But they don't show up in my vercel deployment

    Wrap RSC with
  • Suspense: this URL
  • Using
  • loading.tsx File: this URL
I am using node

18.16 locally and node 18.x in my vercel deployment. I also deployed the nextjs project in vercel using default configuration.

If anyone needs more details, the branch code can be found here

P粉685757239
P粉685757239

reply all(1)
P粉937769356

You didn't include how to load the data, but if you use the new fetch then it may be related to the built-in caching nextjs is doing -- it will cache the data indefinitely by default Down. In production, your post will look like it loaded immediately

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template