Repository navigation
Void View RFC - #843
Draft
kossnocorp wants to merge 3 commits into
Draft
Void View RFC#843kossnocorp wants to merge 3 commits into
kossnocorp 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
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.