Comments (20)
@elliotdavies would that let us drop the whitelist of self-closing elements? If so, I'm 100% in favor of always outputting /
for void elements. Happy to merge that PR if you're good to create it.
from preact-render-to-string.
@developit Not that I can see – you still need some way to know whether to self-close e.g. <br/>
or instead do a full closing tag e.g. <div>...</div>
, and I think a whitelist is the only reliable way to check that.
Still, this should be a pretty minimal change. I'll write up the PR and you can take a look.
from preact-render-to-string.
Works for me.
from preact-render-to-string.
Lol I was just changing the tests for preact-helmet to take this difference into account but it looks like I'm going to have to be changing them back pretty soon...
from preact-render-to-string.
@Download that's odd - how come you had to change the tests? If you're rendering JSX to strings in tests, I'd recommend using preact-render-to-string/jsx
- it preserves non-string props.
from preact-render-to-string.
@developit
I am porting react-helmet to preact. It's tests tend to render some component, then check that the output matches some literal string.
I noticed two big differences with the output from Preact vs the one expected in the tests:
- React outputs
="true"
for boolean properties, but Preact does not (I actually prefer Preact's more concise style). E.g.<meta data-preact-helmet="true" ... />
vs<meta data-preact-helmet ... />
- React self-closes elements that Preact does/did not. E.g:
<base href="https://localhost"/>
vs<base href="https://localhost">
There also seem to be some differences between the output of render
(when using innerHTML
or outerHTML
to serialize to String) and that of renderToString
. Again nothing serious but it would be better/simpler for testing if the results would be more consistent. It seems render
does render the self-closing tag for example. And it's only renderToString
that omits the ="true"
for booleans.
Personally I like the more concise form; it's more readable (imho) and it saves precious bytes. :)
from preact-render-to-string.
@Download render()
+ innerHTML
would actually return /
depending on if the document was XHTML or HTML.
from preact-render-to-string.
@developit Yes I think it's just renderToString
which makes it shorter. The test is using/testing both forms. But it's also most important for renderToString
to be short (to get low TTI). So even though it is annoying when testing that both Strings are subtly different, I think it is an advantage for Preact to keep it this way.
It might be interesting to have a test that just renders all kinds of markups in both ways and compare. Only differences that are beneficial should stay (or maybe give renderToString
a flag to toggle).
from preact-render-to-string.
Flag to toggle would be good, that way it has the option to return either XHTML or HTML.
from preact-render-to-string.
Hi @developit – just wondering if there's any chance you could bump the release version so as to include this?
from preact-render-to-string.
Can do, yup.
from preact-render-to-string.
Released as 3.6.0!
from preact-render-to-string.
Thanks!
from preact-render-to-string.
When using htm, the auto slash feature doesn't seem to work. Unclosed elements return undefined
in the output.
from preact-render-to-string.
@brandonpittman Just to clarify: Are you using preact-render-to-string
in combination with htm
?
from preact-render-to-string.
@marvinhagemeister Yep.
from preact-render-to-string.
@brandonpittman Can you share a snippet or a codesandbox which shows the problem?
from preact-render-to-string.
@brandonpittman Just spoke with @jviide which is the maintainer of htm
. Unclosed void
elements are not supported in htm
and therefore will lead to undefined behaviour. In htm
you must always use a closing /
.
from preact-render-to-string.
@marvinhagemeister Yeah, I figured that out on my own. Wasted a lot of time figuring it out though.
from preact-render-to-string.
@brandonpittman Did you import preact/debug
somewhere? That's where all our debug warnings are and it should catch undefined
vnodes. It only needs to be included once (best at the top of your app, before rendering starts).
from preact-render-to-string.
Related Issues (20)
- With Nextjs Error: Objects are not valid as a child. Encountered an object with the keys {} HOT 5
- Shallow rendering and parameter object serialization HOT 1
- Rendering shallow makes a Fragment into a <p> HOT 4
- Async Render for Async Components in the tree?
- Behavior for falsy data attributes not same as preact.
- 5.2.5 breaks server side rendering of @preact/signals HOT 2
- renderToString with {pretty: true} causes undesirable newlines with text nodes HOT 1
- Rendering asynchronous component throws an error HOT 9
- Meta charset not rendered as expected HOT 1
- Void elements have whitespace at closing
- Using effects from @preact/signals causes memory leak HOT 2
- CommonJS bundle broken for v6 HOT 1
- unpkg package seems failed HOT 2
- Unable to import shallowRender from preact-render-to-string/jsx due to TypeScript type errors
- preact and htm function does not return html when ssr rendered from mjs file HOT 3
- xlink:href becomes xlink::href
- `options._diff` not called for implicit Fragments HOT 2
- `preact/debug` warnings not thrown because `vnode.__k` is not set
- Stream Rendering Roadmap HOT 1
- Invalid nesting detection with `preact/debug` HOT 1
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 preact-render-to-string.