Next.js Discord

Discord Forum

Layout fetch keeps fetching

Unanswered
Champagne D’Argent posted this in #help-forum
Open in Discord
Avatar
Champagne D’ArgentOP
I have this layout component:

export default async function RootLayout({ children }: RootLayoutProps) {
  const { spaces } = await getSpaces();


If something changes in my Layout for example if I open a menu or something it keeps trying to fetch the data and the loading component appears, is there a way to improve this or am I doing something wrong?

getSpaces

Does following:

export const getSpaces = async () => {
  const { session } = await getUserAuth();
  const s = await db.select().from(spaces).where(eq(spaces.userId, session?.user.id!));

  return { spaces: s };
};

4 Replies

Avatar
B33fb0n3
You shouldn’t fetch inside your layout. The layout is only for „layouting“ stuff. So fetch inside your pages. I think your problem is part of this principle 🙂 @Champagne D’Argent
Avatar
B33fb0n3
@Champagne D’Argent solved?
Avatar
B33fb0n3
@Champagne D’Argent ?
Avatar
Champagne D’ArgentOP
@B33fb0n3 Never fetch in layout components? I think I fixed it because a component used async, which I removed, going to check it later again.