Skip to content

feat(ssr): add server entrypoint#164

Merged
dangreen merged 1 commit into
mainfrom
feat/ssr-server-entrypoint
Jul 13, 2026
Merged

feat(ssr): add server entrypoint#164
dangreen merged 1 commit into
mainfrom
feat/ssr-server-entrypoint

Conversation

@dangreen

Copy link
Copy Markdown
Member

Summary

Adds an optional server entrypoint to @nano_kit/ssr, alongside the existing client and renderer.

When the server plugin option is set, that file is bundled into dist/server (instead of emitting the default renderer bundle) and receives the renderer through a new typed virtual:app-renderer module. Default behaviour is unchanged — without server, the renderer bundle is still produced.

Changes

  • @nano_kit/ssr vite-plugin: server / serverDir options, virtual:app-renderer resolution, and an SSR build branch that emits the server bundle.
  • Types: ambient virtual:app-renderer declaration (shipped script virtual.d.ts pulled in from index.d.ts); RenderData.statusCode narrowed to a ResponseStatusCode literal union.
  • Examples: event-board react/preact/svelte moved to src/server.ts importing virtual:app-renderer; server build bundles deps via ssr.noExternal (gated to build, so dev still loads the renderer through Vite's SSR module runner); api factory renamed to api.

Testing

  • packages/ssr: oxlint + vitest (incl. new server-build test) + tsc — green.
  • Examples: build emits dist/server + dist/client; prod server (SSR + bundled api + static with cache headers) and dev (SSR middleware + api plugin) verified at runtime.

🤖 Generated with Claude Code

Add an optional `server` plugin option that bundles a custom server entry
into `dist/server` instead of the default renderer bundle. The server
imports the renderer through a new typed `virtual:app-renderer` ambient
module, and `RenderData.statusCode` is narrowed to a `ResponseStatusCode`
literal union.

The event-board examples adopt the new entrypoint via `src/server.ts`.
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.86%. Comparing base (543d1d6) to head (c51baa6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #164   +/-   ##
=======================================
  Coverage   83.86%   83.86%           
=======================================
  Files         138      138           
  Lines        2968     2968           
  Branches      560      560           
=======================================
  Hits         2489     2489           
  Misses        340      340           
  Partials      139      139           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional server entrypoint to the @nano_kit/ssr Vite plugin, enabling production SSR builds to emit a bundled server output (dist/server) that can import the configured renderer via a new virtual:app-renderer module, while keeping the default renderer build behavior unchanged when server is not provided.

Changes:

  • Extend the SSR Vite plugin with server/serverDir options and virtual:app-renderer resolution, and adjust SSR build output routing.
  • Ship an ambient virtual:app-renderer type declaration and narrow renderer statusCode typing to a ResponseStatusCode literal union.
  • Update event-board examples to build/run via dist/server/index.js, use virtual:app-renderer, and simplify the API factory to api().

Reviewed changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ssr/test/app/server.js Adds a server entry fixture importing virtual:app-renderer for server-build tests.
packages/ssr/src/vite-plugin/virtual.d.ts Introduces ambient typing for the virtual:app-renderer module.
packages/ssr/src/vite-plugin/index.spec.ts Adds a new vitest case covering server entry bundling with virtual:app-renderer.
packages/ssr/src/vite-plugin/index.js Implements server/serverDir handling and virtual module resolution for server builds.
packages/ssr/src/vite-plugin/index.d.ts Updates plugin option types to include server and serverDir and pulls in virtual typings.
packages/ssr/src/renderer/utils.ts Tightens status/redirect helper return types and uses ResponseStatusCode in responseStatus.
packages/ssr/src/renderer/renderer.types.ts Defines ResponseStatusCode and narrows RenderData.statusCode to it.
packages/ssr/package.json Adjusts build script to ship additional .d.ts files for the plugin.
examples/event-board/svelte-nano_kit-ssr/vite.config.ts Configures SSR bundling for build and provides server entry to the SSR plugin.
examples/event-board/svelte-nano_kit-ssr/src/server.ts Switches prod server to virtual:app-renderer and updates API mounting.
examples/event-board/svelte-nano_kit-ssr/package.json Runs preview/start from dist/server/index.js.
examples/event-board/svelte-nano_kit-ssr/api/server.js Updates API server mounting to align with api() returning a Hono app.
examples/event-board/svelte-nano_kit-ssr/api/index.js Renames createApiApp to api and removes the old wrapper.
examples/event-board/react-nano_kit-intl-ssr/vite.config.ts Configures SSR bundling for build and provides server entry to the SSR plugin.
examples/event-board/react-nano_kit-intl-ssr/src/server.ts Switches prod server to virtual:app-renderer and updates API mounting.
examples/event-board/react-nano_kit-intl-ssr/package.json Runs preview/start from dist/server/index.js.
examples/event-board/react-nano_kit-intl-ssr/api/server.js Updates API server mounting to align with api() returning a Hono app.
examples/event-board/react-nano_kit-intl-ssr/api/index.js Renames createApiApp to api and removes the old wrapper.
examples/event-board/preact-nano_kit-intl-ssr/vite.config.ts Configures SSR bundling for build and provides server entry to the SSR plugin.
examples/event-board/preact-nano_kit-intl-ssr/src/server.ts Switches prod server to virtual:app-renderer and updates API mounting.
examples/event-board/preact-nano_kit-intl-ssr/package.json Runs preview/start from dist/server/index.js.
examples/event-board/preact-nano_kit-intl-ssr/api/server.js Updates API server mounting to align with api() returning a Hono app.
examples/event-board/preact-nano_kit-intl-ssr/api/index.js Renames createApiApp to api and removes the old wrapper.
examples/event-board/common/api/server.js Updates common API server mounting to align with api() returning a Hono app.
examples/event-board/common/api/index.js Renames createApiApp to api and removes the old wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ssr/src/renderer/utils.ts
Comment thread packages/ssr/package.json
@dangreen dangreen merged commit eefd560 into main Jul 13, 2026
11 checks passed
@dangreen dangreen deleted the feat/ssr-server-entrypoint branch July 13, 2026 11:36
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.

2 participants