Skip to content

Void Server Components RFC - #871

Draft
kossnocorp wants to merge 1 commit into
mainfrom
server-components
Draft

kossnocorp wants to merge 1 commit into
mainfrom
server-components

Conversation

@kossnocorp

Copy link
Copy Markdown
Contributor

This PR is a follow-up for the discussion with @cpojer in #843. It also overlaps with #731 by @yusukebe that implements Hono JSX adapter but takes different direction.

It is a proposal to add built-in Void Server Components that would allow exporting a JSX component from pages/**/*.server.tsx. The implementation is based on hono/jsx and enables server-only rendering without any client JS or even installing a view framework such as React or Vue.

// pages/about.server.tsx

export default function AboutPage() {
  return (
    <main>
      <h1>About</h1>
      <p>This is a simple page</p>
    </main>
  );
}

The body of the component becomes the loader:

// pages/weather.server.tsx

import type { CloudContext } from 'void';
import { SourceLink } from '../components/SourceLink.tsx';

export default async function WeatherPage(c: CloudContext) {
  const [location, temperature] = await fetchWeather(c.req.query('location'));

  return (
    <>
      <h1>Current weather in {location?.name || 'Unknown location'}</h1>

      <SourceLink file="pages/weather.server.tsx" />

      <form method="get" action="/weather">
        <label>
          Location{' '}
          <select name="location">
            {hubs.map(({ id, name }) => (
              <option key={id} value={id} selected={id === location?.id}>
                {name}
              </option>
            ))}
          </select>
        </label>{' '}
        <button type="submit">Show</button>
      </form>

      {typeof temperature === 'number' ? (
        <p>Temperature: {temperature} °C</p>
      ) : (
        <p>Weather data is unavailable right now.</p>
      )}

      <p>
        This async component reads the location from the URL and waits for{' '}
        <a href="https://open-meteo.com/">Open-Meteo</a> on the server.
      </p>
    </>
  );
}

But explicit loaders are also supported, so the API is consistent.

It also supports all the regular page features like layout, prerender, CSS, error pages, etc.


The idea is to provide a complete experience out-of-box and allow users build static pages before opting into using a heavier view framework.

The PR doesn't cover using islands and include client components yet. If we have an agreement on direction, we should definitely think it through how to approach it and provide great DX for people mixing server and client components without falling into the same traps as Next.js did.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://server-components-void-cloud.voidzero-docs.workers.dev (commit 469aab0)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://01772a80-void-cloud.voidzero-docs.workers.dev 469aab0 2026-11-17T23:56:19.571Z Visit the dashboard ↗

@yusukebe

Copy link
Copy Markdown

Hey @kossnocorp ! This is super interesting. The follows are my thoughts:

  • I think this is separate from @void/hono. But we should choose one of the two PRs for now.
  • I really like the idea of providing JSX rendering for SSR (Server Components) by default.
  • The original reason we created Hono JSX was to render static pages as an alternative to template engines like Mustache and Handlebars. So the motivation is the same (I think).
  • One of the good things about Hono is that it supports SSR out of the box without any dependencies. This is great for DX, so bringing this idea to Void makes sense.
  • On the other hand, I'm not sure what we should do when users need client-side interactivity. Should they switch to React or Vue? Or should we create @void/hono and use its client-side features? I think supporting islands for client-side interactivity could be a good idea. Or we could simply decide to support SSR only.

@kossnocorp

Copy link
Copy Markdown
Contributor Author

@yusukebe thank you for the feedback!

I think this is separate from @void/hono. But we should choose one of the two PRs for now.

Yeah, sorry I didn't see @void/hono PR when I started experimenting with #843. I'm not attached to any of these. I just wanted to show how I see it working.

The original reason we created Hono JSX was to render static pages as an alternative to template engines like Mustache and Handlebars. So the motivation is the same (I think).

Definetely!

One of the good things about Hono is that it supports SSR out of the box without any dependencies. This is great for DX, so bringing this idea to Void makes sense.

I loved how easy it was to implement it using hono/jsx. Kudos for such great work!

On the other hand, I'm not sure what we should do when users need client-side interactivity. Should they switch to React or Vue? Or should we create @void/hono and use its client-side features? I think supporting islands for client-side interactivity could be a good idea. Or we could simply decide to support SSR only.

I think islands would be the most logical way to go. I at least would be pleased if I could stick to static and add sprinkles of JS where needed for docs and such.

But switching is also fine since Hono JSX is pretty standard, and we can even provide a skill to help the transition.

@yusukebe

Copy link
Copy Markdown

@kossnocorp

Thanks!

Also, I haven't measured it yet, but I think the server-side bundle size will be much smaller than React or other libraries.

@kotarotaniguchi0523

Copy link
Copy Markdown
Contributor

I like the idea behind this proposal, but I'm a little concerned about using Hono JSX as a foundation for Void.

While looking through the Hono JSX source code, I noticed several potential bugs and design issues. I appreciate the ongoing fixes, but I'm still unsure whether it's mature enough for Void to rely on long-term.

I'm especially concerned about hono/jsx/dom. I don't think it fully meets the goal of providing a great user experience, which Christoph mentioned in his comment on #731. Since islands and client components may be considered in the future, I think this is worth keeping in mind.

My main concern is that these issues could become significant technical debt for Void over time. It might be worth exploring other approaches, including a solution designed specifically for Void, before committing to Hono JSX.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants