Next.js Discord

Discord Forum

Comments in Next.js

Answered
Goldstripe sardinella posted this in #help-forum
Open in Discord
Avatar
Goldstripe sardinellaOP
In the vercel website Theres comments like <!--$!--> or <!--$?-->. Im just curious how do those get into the html? I know about react suspense that adds <!--$--> </--/$--> but I want to know how those also get added. if anyone knows this Please do let me know
Answered by gin
nothing its adding it because the skeleton is the fallback
View full answer

64 Replies

Avatar
Goldstripe sardinellaOP
(ping me if someone responds)
Avatar
Tibetan Spaniel
I'm sure you can use the dangerouslySetInnerHTML attribute so any html can get past through. Please also understand why it is named dangerous.
I think there's other but I don't actually know.
@Goldstripe sardinella
Avatar
Goldstripe sardinellaOP
pretty sure its added by something done in the server
and u cant write JSX in dangerouslySetInnerHTML
Avatar
Tibetan Spaniel
wait, i though u want to allow the html comment to show at production
Avatar
Goldstripe sardinellaOP
no
it has something to do with server side rendering
@Tibetan Spaniel this is from the response html in the vercel's website so im assuming is has something to do both with React suspense and server side rendering but I cant figure it out
Image
Image
(btw if u respond and i dont answer dont be shy to ping me)
Avatar
Asian black bear
I can't guess what exactly you wanna know
its like a XY problem.
Avatar
Goldstripe sardinellaOP
how do they get those comments is what I wanna know
Avatar
Asian black bear
im not sure but they put those comments while deploying or building on Vercel.
Avatar
Goldstripe sardinellaOP
from my understanding you dont know how those comments are made/added right?
Avatar
Why do you want to know this? This is not something nextjs users need to even think about.

To answer your question: https://github.com/facebook/react/blob/94e4acaa1477e65cac02ba86058cde0afe4c8f1f/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L189

const SUSPENSE_START_DATA = '$';
const SUSPENSE_END_DATA = '/$';
const SUSPENSE_PENDING_START_DATA = '$?';
const SUSPENSE_FALLBACK_START_DATA = '$!';
Avatar
Goldstripe sardinellaOP
so it only adds if there's a promise in it or am I missing something?
Avatar
Seems you are interested in how react works internally, you have the source file above and are free to inspect how these constants are used in the implementation.
Avatar
Goldstripe sardinellaOP
I already saw it im just asking cuz i aint understanding that much
Avatar
I don’t, either. Not a react team maintainer. I can only tell you, by the link above, that those comments are added automatically by react, and since nextjs uses react, and vercel uses nextjs, those comments show up on the Vercel website. If you only want to know why those comments exist, this should be a satisfactory answer. If you want to know what happens with those comments, that is an implementation detail and you need to manually inspect the code yourself or find someone who can do that. This server doesn’t have any active members who are part of the react team or contribute to react regularly
Avatar
Goldstripe sardinellaOP
well im looking for someone who knows when they're added
i figured to come here cuz I thought there would be experts that have an answer
and i dont know react's discord server
Avatar
The point is that this is an implementation detail. It is not something people outside the team even need to know. If your code fails for whatsoever reason, it is because of something else, not these comments and these comments won’t help with debugging.
Avatar
Goldstripe sardinellaOP
it's not causing issues lol it's curiosity
Avatar
just by looking at this i think it is marking the suspense boundary for some internal function
Image
Avatar
Goldstripe sardinellaOP
those get added by default when u use <Suspense>. but im looking for these
Image
Avatar
Image
function name tells u what it is for
Avatar
Goldstripe sardinellaOP
which line is this? i cant find it
Avatar
Goldstripe sardinellaOP
could you possibly show me like a code that adds the comment im still having trouble trying to understand lol Sorry.
Avatar
Goldstripe sardinellaOP
wait so those comments dont even come from a react component?
actually let me give a example
I might be making it harder to understand lol
import React, { Suspense } from 'react'

const A = () => {
  return (
    <Suspense fallback={<h1>this is loading</h1>}>
        a content in a suspense
    </Suspense>
  )
}

export default A


this for example adds the <!--$--> <!--/$--> comments around the text. but what about the <!--$?--> or <!--$!-->
you get me?
Avatar
its probably to check if the suspense is pending and where it starts
Avatar
Goldstripe sardinellaOP
then shouldnt it get added by default when u use Suspense?
Avatar
are you seeing this somewhere or what
<!--$?-->
Avatar
Goldstripe sardinellaOP
what do you mean
idk if this is what u mean
Avatar
yeah
Avatar
Goldstripe sardinellaOP
ima tryna figure out what you do in the code that it adds those comments
Avatar
nothing its adding it because the skeleton is the fallback
Answer
Avatar
if u see the skeleton the suspense has probably not finished and thats why these are there
and by looking at the function i send u above
it checks exactly for that
Avatar
Goldstripe sardinellaOP
ive tried it myself why does it not get added im kind of confused
Avatar
cause it probably gets removed after the suspense has finished
Avatar
Goldstripe sardinellaOP
1 second
Avatar
Goldstripe sardinellaOP
the way it works is really weird
or maybe its just me
Avatar
Goldstripe sardinellaOP
alright nevermind
@gin @joulev thanks so much
idk how to delete this thread now
Avatar
no problem
Avatar
Goldstripe sardinellaOP
do u know how do i close this
Avatar
u can mark my answer as solution, it will close then
thanks! 👍
Avatar
Goldstripe sardinellaOP
u2
Avatar
Tibetan Spaniel
no, it's a bit weird, and i'm curios too, just don't have time for that now 😅