-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't add html comments in _document.js #3904
Comments
You can write comments in JSX by wrapping them in curly braces. But keep in mind you have to return a single element from React components. This works: const MyComponent = (props) => {
return (
<div>
{/*This is a comment*/}
Some Text
</div>
)
} This will cause an error: const MyComponent = (props) => {
return (
{/*This is a comment*/}
<div>
Some Text
</div>
)
} |
Hey @dbrodie122 dbrodie122 thanks for the input but I need an html comment to appear in the dom / server side rendered html. Jsx comments don't make it into the dom. Example: I think it's the |
Have you tied this in your own _document.js?
So later in DOM, it would be like
Since google would crawl the document as a plain text, feels like this would work. |
Pretty clever @haohcraft . That does the trick. Thanks 🙏 |
I also need to do this, but unfortunately can't be inside a script tag. Its something that needs to be injected right into the header. I'm using nginx to do virtual includes so it needs to look like
any thoughts? |
I also need what miwialex is saying too... Not inside a script tag... Can't figure out a way. |
@miwialex I figured out a way to do this, hackily tonight.. I had a huge issue with JSS and Emotion conflicting and needed to add a comment which JSS references to change the insertion order of the CSS... Anyways long story short what worked for me is this, in my _document.js Basically above my (the Next.js HEAD component), I added this:
Then everything in the HEAD component got appended after that, which worked for my use case, at least in chrome, I haven't tested other browsers... So for me it looks like this:
|
@craigcbrunner @haohcraft You both deserve a medal, spent so much time trying to figure this out. Thank you. |
@craigcbrunner To change the CSS injection order, I followed this steps:
|
Can't add html comments in
_document.js
, I believe this is just a something that isn't possible with jsx, but wondering if there may be a workaround.The reason I need to do this is because google is trying to index urls that are in the
__NEXT_DATA__
object and I'd like to wrap the whole script tag in<!--googleoff: all-->
.The text was updated successfully, but these errors were encountered: