Repository navigation
Void View RFC - #843
Void View RFC#843kossnocorp wants to merge 3 commits into
Conversation
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://view-void-cloud.voidzero-docs.workers.dev (commit 2a6991b)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
|
I like this idea. It's amazing how flexible Void's architecture is. Another idea/direction – a
|
|
I think this is super interesting. I don't know yet if we should merge this into Void by default – since it's a standalone package it could also be an external project. This is an interesting direction in contrast to Hono JSX at #731. This PR explicitly only supports server-side rendering, which avoids a lot of the work that the framework adapters are doing. If we want to merge Hono JSX, we should consider either taking the same direction as here (server rendering only), or going all-in and supporting every UI framework adapter feature. We should make a decision for this PR and #731 together. |
|
@cpojer @yangshun thank you for the feedback! @cpojer that's a very good point, I didn't realize there's Hono JSX PR. Also, your comment adds a bit of the context: #731 (comment)
Honestly I doubt there's a point making it an optional extension. I used The problem I see is that at this point it would be Sisyphus work to try to convince people to adopt a new JSX-based framework as an option. If we make it an extension people can opt into then I believe everyone will ignore it and will become a dead weight we commit to support. I think the whole idea only makes sense if we commit to make it built-in experience for those who:
Then it would provide Astro-like experience where people able to start small and adopt React/Vue & co incrementally. I might be dead wrong, but I see it only working as nonchalant "here's how Void make static pages easy, no biggie." VoidZero is a tooling brand and selling a new view framework would be much tougher than a new linter or formatter, not to mention that people are sick of new frameworks. If you like, I could work on a better implementation, prepare a palatable demo and write a blog post presenting it as a VoidZero experiment and see how people react.
I think the same applies there, as if made Hono JSX the default option for Void, that would make Void a stronger offering that works out-of-box. Although, unlike my proposal, having Hono JSX as an opt-in makes sense as there are Hono JSX users. However, I think Void View proposal fits Void better as it clicks with loaders naturally whereas Hono JSX kind of asks to use the components body for server side queries. I have an idea to try to make |
What
Void View is a proposal for a standard Void templating system that allows using JSX to define pages' HTML, as well as reusable components.
By default, JSX results in static HTML with no JS loaded into a page.
Dynamic components, e.g., with
letor function event handlers, transform into minimal JS needed to render and update such a component. It utilizes modern web APIs, such as Web Components and<template>elements.Instead of relying on virtual DOM or any other runtime-heavy way to update HTML, it clones the template element, uses
<slot>tags to set interpolation, and simply replaces children with a new element.Additionally, similar to Astro, it enables component-scoped styles defined in the
<style>tag right in a component JSX.It is based on an idea I explored earlier this year.
To try it, checkout the
viewbranch, inspect./playground/viewand run the playground:Examples
Page
This component will result in
/aboutrendering as a static page:Static Component
This component renders to static HTML with
.labelscoped to the component elements (via.label[data-vv-cid-1f803408]):Dynamic Component
This component renders on the server but also provides JS code that updates it dynamically:
It will produce JS that looks something like that (simplified from a real example to make it more readable):
And
<template>tags that provide the HTML for client-side rendering (also simplified):Why
Unopinionated Built-in Views
Void has no built-in primitives to define views and requires using React, Vue, Svelte, or Solid, even in the simplest cases.
When needed to add a basic dynamic behavior to a page, i.e., switching tabs on a landing page, it forces including bundle-heavy framework runtimes:
With Void View, it will be possible to work on static pages with some dynamic elements and delay bringing heavier frameworks later.
It preserves a framework-agnostic approach while providing the view aspect without committing to one or another framework.
Portability
JSX components can be easily ported to React, Solid, or Vue. Simplest React components could also be used with the Void View renderer without changing anything.
JSX components are universally understood and without the hooks' complexity.
Performance
Because Void View ships only JS required to coordinate dynamic components rendering, it makes web pages as fast as they can be without losing the comfort of composable components and a simple rendering model.
I also suspect that replacing children with already-parsed
<template>tags and the lack of function calls for every tag intrinsic to usual JSX components would be more performant than going through virtual DOM in part of the cases. But I will need to do extensive testing to prove it.Perfect Fit for Loaders
Theoretically, JSX -> Web Components could be a complex problem if forced to follow the Astro approach and allow putting server code right into the function body.
With Void loaders, there's no such need to handle server-side in these components at all, and it makes the implementation trivial and edge cases very limited.
Glue-Views
Similar to Astro templates, it is possible to extend Void View to allow importing any other framework components and rendering them as HTML or dynamic islands.
Adding MDX or Markdown rendering support to enable using Void for documentation websites is also straightforward and enables a wider range of use cases for Void and hence the Void Platform.
Why Not X
Why not HTML + Raw Web Components
Web Components are fine until you have to rerender a part of it. Then it becomes a mess with bugs all familiar for whoever used to write a lot of jQuery.
Why not Astro
I love Astro, but because it relies on a custom language, it makes it difficult to work with: from tooling support to inability to define two components in a single file.
There's also no answer to adding dynamic behavior, that force to resort to using a view framework or writing JS that binds events and updates DOM manually, which almost always turns into a mess.
Void View is based on plain TypeScript and modern web APIs, making it a lighter, more flexible, and more powerful alternative to Astro.
What's Next?
This is a prototype and not built optimized for production. There are plenty of edge cases that need to be addressed, and also there are plenty of opportunities to juice performance and minimize the amount of JS shipped to the absolute minimum.
All that I would cover in a new PR (along with a more thoughtful implementation) or a thread somewhere is that there's an interest from the team.
Please share your thoughts, concerns or ask any questions.