Nextjs:加载或挂起回退不会在生产中显示

qojgxg4l  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(104)

我用nextjs v13将我的个人页面迁移到了应用程序directoy上。
我尝试先在Suspense组件的fallback prop 中添加RSC的加载器,并在app目录中的每条路由路径上添加一个loading组件。

// 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>
  );
}

也像这样

// 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>
  );
}

都在当地发展部门工作

但在Vercel部署中没有显示这些功能

我在本地使用node 18.16,在vercel部署中使用node 18.x。我还使用默认配置在vercel中部署nextjs项目。
分支代码可以在here中找到,以防任何人需要更多的详细信息

4uqofj5v

4uqofj5v1#

您没有包括如何加载数据,但是如果您使用的是新的fetch,那么它可能与nextjs正在做的内置缓存有关--默认情况下,它将无限期地缓存数据。在生产上,它看起来就像你的职位立即加载

相关问题