From 9e0a19ceee9d5078db5710120d8e966f0753ef05 Mon Sep 17 00:00:00 2001 From: Ubugeeei Date: Fri, 6 Mar 2026 13:17:38 +0900 Subject: [PATCH] feat: server side props --- active-rfcs/0048-server-side-props.md | 411 ++++++++++++++++++++++++++ 1 file changed, 411 insertions(+) create mode 100644 active-rfcs/0048-server-side-props.md diff --git a/active-rfcs/0048-server-side-props.md b/active-rfcs/0048-server-side-props.md new file mode 100644 index 00000000..e7d4c3f0 --- /dev/null +++ b/active-rfcs/0048-server-side-props.md @@ -0,0 +1,411 @@ +- Start Date: 2026-03-06 +- Target Major Version: 3.x +- Reference Issues: N/A +- Implementation PR: (leave this empty) + +# Summary + +Introduce two new SFC features for server-side data fetching in Vue: + +1. **`defineServerSideProps`** - a compiler macro for declaring server-side data fetching logic that runs on every request during SSR. +2. **` + + +``` + +## ` + + + + +``` + +## Redirect and Not Found + +```html + +``` + +# Motivation + +## Problem + +Currently, Vue does not have a standardized, built-in pattern for per-component server-side data fetching in SSR contexts. Frameworks like Nuxt provide their own solutions (`useAsyncData`, `useFetch`), but there is no first-party convention at the Vue SFC level. This leads to: + +1. **Framework fragmentation** - Each meta-framework implements its own data fetching conventions, making it harder for the ecosystem to share components and patterns. +2. **No clear server/client boundary in SFCs** - Developers must rely on runtime checks or framework-specific conventions to ensure certain code only runs on the server. +3. **Security risks** - Without a clear compile-time server/client boundary, it is easy to accidentally ship server-only code (database credentials, API keys, internal service calls) to the client bundle. +4. **Verbose patterns** - Existing approaches require significant boilerplate to fetch data on the server, serialize it, and hydrate it on the client. + +## Goals + +- Provide a **first-party, framework-agnostic** SSR data fetching primitive at the SFC compiler level. +- Establish a **clear compile-time boundary** between server-only and client code within a single `.vue` file. +- Ensure server-only code (secrets, database access, internal APIs) is **never included in the client bundle**. +- Return **serializable props** that are automatically hydrated on the client, following the same mental model as `defineProps`. +- Support common SSR patterns: **redirect**, **not found**, and **request context** access. + +# Detailed design + +## `defineServerSideProps` + +### API Signature + +`defineServerSideProps` is a compiler macro (like `defineProps`, `defineEmits`) available inside ` +``` + +### Behavior + +- Code inside ` + + + + +``` + +**Type-only imports:** Type exports from `