Next.js Discord

Discord Forum

not-found.js returning some warnings

Answered
Elite posted this in #help-forum
Open in Discord
So for my "transactions", if my database doesn't recall an ID, i prompt a noteFound()

export default async function TransactionDisplayPage({ params }) {
    let data = await fetchID(params.id);

    if (data === null) { // no transaction found
        notFound();
        // return (<h1>404</h1>)
    }
...


Here is my not-found.js:
import Link from 'next/link'
 
export default function NotFound() {
    return (
        <div style={{
            position: 'absolute',
            left: '50%',
            top: '50%',
            transform: 'translate(-50%, -50%)',
            color: 'red'
        }}>
            <h1>404 Not Found! | <Link href="/" style={{color: 'red', textDecoration: 'underline'}}><strong>Go Back Home</strong></Link></h1> 
        </div>
      );
}


when I go to a random url, I get these warnings:
app-index.js:35 Warning: validateDOMNesting(...): <html> cannot appear as a child of <body>.
    at html

---
Warning: You are mounting a new html component when a previous one has not first unmounted. It is an error to render more than one html component at a time and attributes and children of these components will likely fail in unpredictable ways. Please only render a single instance of <html> and if you need to mount a new one, ensure any previous ones have unmounted first.

---
and same with new head and new body comp
Answered by Arinji
you cant have 2 html tags
View full answer

71 Replies

show your nearest layout.tsx please
wait are you on vscode?
@Elite
@Arinji wait are you on vscode?
yes
@Arinji show your nearest layout.tsx please
// import Navbar from '@components/General/navbar.jsx';
// import Footer from '@components/General/Footer.jsx';
export const metadata = {
  title: 'PayBridge Technologies - Transaction'
}

export default function TransactionLayout({ children }) {
  return (
    <html lang="en">
      <head/>
        <body>
          {/* <Navbar/> */}
          {children}
          {/* <Footer/> */}
        </body>
    </html>
  )
}

in the route
@Elite yes
ok do a vscode search for <html> and show the results
you cant have 2 html tags
Answer
cause the layout.js is ALWAYS going to be on the site
so should i remove them in the internal layout
having another layout with html will make the page have 2
like the route layout
alr
export default function TransactionDataLayout({ children }) {
    return (
        <head/>
        <body>
          {children}
        </body>
    )
}
what should i do to this
jsx
its redlined
your file extensions need to be jsx
not js
even for error and notfound?
all react components :D
bascially everything but backend
alr
js dosent have html tags
jsx has html tags
still red
@Elite still red
show your entire file
all my layouts are red except the root
i mean the file, not fileStructure
export const metadata = {
  title: 'Application'
}
export default function ApplicationLayout({ children }) {
  return (
      <head/>
        <body>
          {children}
        </body>
  )
}
<head />
:/
whats that doing their xD
💀
theres no head anymore right
mhm lol
how did i not see this error anywhere
except when i gto a 404 page
not sure tbh, its just a very bad thing to do so nextjs goes all funky
ye
so errors?
nope
tysm
been dealing with a lot of hidden hydration stuff
slowly getting through them
NP
sorry caps
mark a solution @Elite
np
@Arinji np
hey just wondering does

import Head from 'next/head'

still work?
or deprecated
@Elite hey just wondering does js import Head from 'next/head' still work?
it doesn't work in app router but It still work in page router
@Ray it doesn't work in app router but It still work in page router
so its the metadata api now in app router

how can I use that in client pages?
so if I want to do those tags on client what can I do
@Elite so if I want to do those tags on client what can I do
make a server component, call your client component from it
also make a new forum for this plz
@Arinji also make a new forum for this plz
@Ray why you not say this:wat:
shit mb
np
its just that we get points on the leaderboards lol
from getting answers marked
thats why most of us hang out here :D
lmao
@Arinji <@743561772069421169> why you not say this<:wat:1220772839636992112>
because I already have too much points
@Ray because I already have too much points
stfu, i need points