Comments (7)
Thanks for bringing this up. Definitely something I plan to support. Probably a good idea to get a working prototype of this early on to not have worries later.
from sycamore.
I feel it's worth mentioning that Perseus is a framework based on Sycamore that supports SSG fully, including using it with SSR (with state amalgamation).
from sycamore.
This will exist soon in #67.
from sycamore.
That's great news. If you need a server-side DOM for static rendering, although it's not really done yet, I've been working on https://github.com/philip-peterson/rust-rdom which is a Rust implementation of at least some of the WhatWG DOM spec. I could use help if anyone's interested in collaborating. The more the merrier!
from sycamore.
There is a prototype of rendering template!
to a string in #67 (thanks for all the work @lights0123!). One problem we have now is related to API ergonomics. To support SSR and DOM, we need to compile a different version of the component depending on the context.
Since maple doesn't have a VDOM and doesn't plan to have one, an option would be to make TemplateResult
generic, excepting a type param G
which determines which backend to use (DomNode
or SsrNode
). Pros for this include more flexibility in which backends are used. We could render a TemplateResult
to a string on the client as well if we wanted to. Cons mean that we would need to add a type param to every component.
The alternate route would be to use feature flags that determine which backend TemplateResult
will use. This makes it slightly less flexible in that only one backend can be used at a time. However, I don't really see this as a problem because this use case would be extremely rare (in fact, I cannot think of a single use case where having multiple rendering backends would be useful and to my knowledge, most frameworks/libraries do not support this, e.g. svelte either compiles for dom
or ssr
but not both).
I do not think enabling this niche use case outweighs penalizing everybody else who doesn't need it.
However, there is a workaround for the first possibility. We could recommend creating a new type alias
type Template = TemplateResult<DomNode>
for users who don't need SSR. For those who do, they could add a cargo feature on their crate (called ssr
) and have the following code:
#[cfg(feature = "ssr")]
type Template = Template<SsrNode>;
#[cfg(not(feature = "ssr"))]
type Template = Template<DomNode>;
but then, we're back to the feature flag idea.
Another thing to think about is potentially supporting more rendering backends in the future (e.g. native, gl, etc...). In this case, we might bump into problems with the second approach because maple-core
would not have access to rendering backends defined externally.
A last possibility would be to create a GenericNode
data structure which would have .to_dom_node()
and .to_static_string()
which would create the DomNode
s and SsrNode
s on demand. The problem with this is potential lifetime problems as well as an extra layer of indirection.
Any ideas/opinions on this?
from sycamore.
Well, it could be useful to support both cases at runtime. See vercel/next.js#19606 as an example, or similar requirements (ex a serverless middleware in nextjs).
from sycamore.
Well, it could be useful to support both cases at runtime. See vercel/next.js#19606 as an example, or similar requirements (ex a serverless middleware in nextjs).
Yes that is how it works right now. If you look at https://sycamore-rs.netlify.app/docs/basics/components, you'll see that in the next version, you need a #[component]
attribute macro.
from sycamore.
Related Issues (20)
- view! failing when attribute name ends in `-ref` HOT 1
- Invalid HTML from view! HOT 6
- Optional attributes in view!
- Abstract over reactiveness HOT 1
- SVG with interpolation doesn't render in browser HOT 2
- use_context Error after updating to 0.9.0-beta.2 HOT 4
- Probable bug in signal propagation HOT 4
- Panic updating signal in 0.9.0-beta.2
- Bootstrap scrollspy support HOT 4
- Book (website) routing not properly updating HOT 8
- Shared data update failed when nested routing layout HOT 1
- Is there a tool for converting HTML to sycamore components? HOT 1
- Is there a case of a right-click pop-up menu? HOT 2
- Nested component using string error HOT 1
- Nested component click event error HOT 1
- Nested component click event error HOT 1
- Hydrate example has a javascript error and does not work HOT 2
- Support binding to a radio input value HOT 2
- Console error "closure invoked recursively or after being dropped" when executing `navigate` in a component using `Indexed` HOT 3
- hydration start marker not found after trunk build --release
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 sycamore.