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
<html> tag in <Helmet> is not handled properly on SSR #86
Comments
This is just a notice since your idea might be good and correct me if I'm wrong. This is a notice from InertiaJS Title & meta:
Same goes for Nano JSX
If you check the template makeHTML, you see |
As of now I guess it should return @aiotter What do you think? Edit: { prefix: 'og: https://ogp.me/ns#', lang: 'en' } |
@yandeu I afraid |
btw, I feel it better to have a option to return const app = Nano.renderSSR(() => <App />);
const { body, head } = Nano.Helmet.SSR(app);
const html = Nano.renderSSR(() => (
<html prefix="og: https://ogp.me/ns#">
<head innerHTML={{ __dangerousHtml: head.join("\n") }} />
<body innerHTML={{ __dangerousHtml: body }} />
</html>
)); react-helmet has nice way to accomplish this, say: function HTML () {
const htmlAttrs = helmet.htmlAttributes.toComponent();
const bodyAttrs = helmet.bodyAttributes.toComponent();
return (
<html {...htmlAttrs}>
<head>
{helmet.title.toComponent()}
{helmet.meta.toComponent()}
{helmet.link.toComponent()}
</head>
<body {...bodyAttrs}>
<div id="content">
// React stuff here
</div>
</body>
</html>
);
} If you feel this possible, I'll create a new issue for it. |
The body returned from This looks right: const { body, head, footer, attributes: { html, body } } = Helmet.SSR(app) |
What about this: class App extends Component {
render() {
return (
<div>
<h1>Nano JSX App</h1>
<Helmet>
<html lang="en" amp />
<body class="root" />
<body class="main" id="id" />
<title>My Title</title>
<meta name="description" content="Nano-JSX application" />
</Helmet>
</div>
)
}
}
const app = renderSSR(<App />)
const { attributes, head } = Helmet.SSR(app)
console.log(head) // <title>My Title</title><meta content="Nano-JSX application" name="description" />
console.log(attributes.body) // [Map] { 'class' => 'main', 'id' => 'id' }
console.log(attributes.html) // [Map] { 'lang' => 'en', 'amp' => 'true' }
console.log(attributes.body.toString()) // class="main" id="id"
console.log(attributes.html.toString()) // lang="en" amp="true" |
Looks really nice! That makes us code like this: const app = renderSSR(<App />)
const { attributes, body, head } = Helmet.SSR(app)
const Html = () => (
<html {...Object.fromEntries(attributes.html)}>
<head innerHTML={{ __dangerousHtml: head.join('\n') }} />
<body {...Object.fromEntries(attributes.body)} innerHTML={{ __dangerousHtml: body }} />
</html>
); |
Or even simpler: const app = renderSSR(<App />)
const { body, head, footer, attributes } = Helmet.SSR(app)
const Html = () => {
return `
<!DOCTYPE html>
<html ${attributes.html.toString()}>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${head.join('\n')}
</head>
<body ${attributes.body.toString()}>>
${body}
${footer.join('\n')}
</body>
</html>`
} |
@yandeu Thank you for implementing this! |
I just released v0.0.28 |
Describe the bug
Nano.Helmet#didMount
handles<html>
tag, so it won't work for SSR, resulting to emit incorrect<html>
tag inhead
property of the returning object ofNano.Helmet.SSR()
.To prevent this, Nano JSX should at least delete
<html>
tag or raise an error onNano.Helmet.SSR()
. It would be better if it returnshtmlAttributes
andbodyAttributes
like react-helmet does.The text was updated successfully, but these errors were encountered: