-
Notifications
You must be signed in to change notification settings - Fork 36
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
uhtml/ssr - Added both easy SSR and worker.js target #114
Conversation
Thanks! It works well! Maybe you will be interested in the final product. |
I used uhtml/ssr a bit more, and... my code ended up like this:
given how Is it possible for a html`` template to exist without |
@iacore I am not sure I am following ... see the test example: https://github.com/WebReflection/uhtml/blob/main/test/ssr.mjs you can have one or more documents (one per page to render if you want) and I can't provide a global document as that's hostile. I have removed types and used the suggested way to export things in there ... I don't know why TS doesn't understand that but I wonder if you are on latest TS. As follow up questions:
module.exports = typeof process === 'object' ?
require('uhtml/ssr')('...') :
{ ...require('uhtml/keyed'), document }; This Make it an Would this improve the API? |
I don't want to use
This is the issue. uhtml does not allow components to be defined with a generic In preact, the components are defined with JSX/hyperscript, so this is not a problem. So my question is, can For the types, I will fix it. |
you need to import The Hole is just a class and represents entries expected as holes within the |
Here is a more concrete example. Here's a file, import { html, render } from 'uhtml'
html`<h1>a</h1>` If I run it with node, it doesn't work.
Can this limitation be overcome? IMO, the definition of a component (even as simple as html`<h1>a</h1>`) should not depend on the DOM environment to exist. i.e. DOM would be needed only when the component is rendered, not when it is defined. I think I will read the source code of uhtml to understand how it works. |
yes, that's why you want either If you are OK in polluting the global context then in node only: import initSSR from 'uhtml/ssr';
const { document } = initSSR('...');
Object.assign(globalThis, {
document,
DocumentFragment: document.createDocumentFragment().constructor
}); Then you should be able to use that file and eventually serve edit P.S. that entry point should run before the rest of your node app runs or use |
@iacore another alternative is to use importMap so that on browser you get just that while on node you get your file that bootstrap the SSR and exports then everything it offers, after placing the What I do in my tests is like this: https://github.com/WebReflection/uhtml/blob/main/test/modern.mjs#L9-L13 |
Thanks! This is exactly what I'm looking for! |
This MR brings forward the hydro branch #113 as I got stuck but also I am not sure anymore I was doing the right thing ... but as I don't want to get stuck, it made sense to at least provide an
uhtml/ssr
export and fix some gotcha with the persistent fragment.This MR also fixes #111 by removing TypeScirpt as a whole and provide just JSDoc TS for the provided files. I hope this won't break anyone out there but as types were buggy this can land as minor as it doesn't break anything, it adds a new
uhtml/ssr
export, and it should improve TS / types in general.The hydro branch is on hold until I have both head and time to get that right.