Next.js Discord

Discord Forum

Layout Wrapper causes elements to vanish

Answered
Norrbottenspets posted this in #help-forum
Open in Discord
NorrbottenspetsOP
Layout wrapper causes everything on page to vanish.


I'm working with 1 page, index.js with the following code:
export default function Home() {
  return (
    <Layout>
      <Head>
        <title>Title</title>
      </Head>
      <section className={utilStyles.headingMd}>
        <h1>test</h1>
        <h1>BlahBlahBlah</h1>
      </section>
    </Layout>
  )
}

Layout is a wrapper that I intend to use for stuff like the navbar, header, and footer:
export default function Layout({children}) {
    <div className={styles.container}>
        <div className={roboto_mono.className}>
            <Head className={styles.header}>
                <link rel='icon' href='../public/favicon.ico' />
            </Head>
        </div>
        <body className={roboto_mono.className}>{children}</body>
    </div>
}

I figure I should be able to at the very least be able to see the two h1 texts, but it's just a completely blank page. Is there any reason why nothing at all shows up?
Answered by joulev
hmm this one is interesting...
View full answer

14 Replies

NorrbottenspetsOP
Small update:
The issue is 100% something with Layout since removing the Layout element in index.js causes elements to show up again, but I can't find what in Layout is causing nothing to show even when it's reduced down to just
<body>{children}</body>
@joulev Pages router? Then dont use <body> in it
NorrbottenspetsOP
I've since removed <body> , even to where the code in layout was as below, but it seems like nothing is fixing the issue.
export default function Layout({children}) {
    <div>{children}</div>
}
then you need to give me a minimal reproduction repository
@Norrbottenspets https://github.com/NonNoetic/sunburn
move the content outside Head. only keep the title there
@joulev move the content outside `Head`. only keep the `title` there
NorrbottenspetsOP
still no content, only blank page
hmm this one is interesting...
Answer
or it's not so interesting... you never returned any layouts. you need to put a return here
@Norrbottenspets ^
NorrbottenspetsOP
lmfao no way
omg ur right
thank you for spotting that I would have been chasing my tail through the entire file system all night