Comments (10)
I just released v0.0.28
from nano.
What about this:
improve-helmet branch; test with npm run ssr
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"
from nano.
@yandeu Thank you for implementing this!
I cannot wait to test it on my deno project; can you run denoify to update the deno_lib
? So that I can test it before new release!
from nano.
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:
Since JavaScript apps are rendered within the document , they are unable to render markup to the document , as it's outside of their scope. To help with this, Inertia ships with an component, which can be used to set the page <title>, tags, and other elements.
Same goes for Nano JSX <Helmet>
as far as I understand, it does not like React Helmet yet
Support attributes for html
If you check the template makeHTML, you see ${head.join('\n')}
is just additionally added/rendered to the html markup in side the <head>
. So <html lang="en">
is out of scope for Helmet.
from nano.
As of now Nano.Helmet.SSR
returns { body, head, footer }
.
I guess it should return { body, head, footer, html }
, where html would be <html prefix="og: https://ogp.me/ns#">
(open tag only).
@aiotter What do you think?
Edit:
Or better, html
should be an object of attributes like:
{ prefix: 'og: https://ogp.me/ns#', lang: 'en' }
from nano.
@yandeu { prefix: 'og: https://ogp.me/ns#', lang: 'en' }
seems nice!
How about implementing toString()
method to this object, which returns prefix="og: https://ogp.me/ns#'" lang="en"
? This will make people easier to embed the attributes into their HTML string. React-helmet has the similar one, helmet.htmlAttributes.toString()
.
FYR: https://github.com/nfl/react-helmet#as-string-output.
I afraid html
attribute of the returned value of Nano.Helmet.SSR()
becoming different from that of body
attribute then. They can also set the attribute of body
tag with Nano.Helmet
, and it has the same problem. How should it be?
from nano.
btw, I feel it better to have a option to return body
and head
as components instead of string.
I'm coding like following, but I feel it a bit too roundabout.
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.
from nano.
The body returned from Nano.Helmet.SSR()
does NOT include the body attributes.
This looks right:
const { body, head, footer, attributes: { html, body } } = Helmet.SSR(app)
from nano.
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>
);
from nano.
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>`
}
from nano.
Related Issues (20)
- inputs lose focus on... well, input HOT 8
- Cannot use html tags inside renderSSR HOT 3
- Dollar sign causes bad output HOT 8
- Router.Listener() should emit on history.back()
- Omit selected="false" from <option /> HOT 1
- es5 prototype function HOT 3
- Feature Request: Resumability? HOT 1
- Module fails to resolve on versions > `0.0.32` HOT 3
- Updating the docs HOT 1
- Enhancement Suggestion: Making README Dark Mode Compatible HOT 8
- [Feature Proposal] Support for Bun HOT 1
- [Bug] didUnmount() event console.log() fired too late on page change HOT 1
- Render to and from AST HOT 1
- Docs: Write docs for #89
- Docs: Write docs for #86
- [Bug] New Helmet client-side TypeError with external template file HOT 3
- New JSX Transform API won't work on deno HOT 4
- Router from array error HOT 5
- Body not expected HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano.