Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server component roadmap #19772

Open
9 of 12 tasks
danielroe opened this issue Mar 17, 2023 · 15 comments
Open
9 of 12 tasks

server component roadmap #19772

danielroe opened this issue Mar 17, 2023 · 15 comments

Comments

@danielroe
Copy link
Member

danielroe commented Mar 17, 2023

We have experimental support in Nuxt 3 for both island components and server-only components (which are implemented using islands) - see nuxt/framework#5689 and nuxt/framework#9972 for initial implementations and #17956 for initial partial RFC.

There are a number of future linked improvements. This issue is to track those and provide some place to document the linking story, purpose and usage of server components within Nuxt.

Purpose and usage

Currently we are collecting use patterns to ensure that the final API and implementation for server components is useful. But the following are some benefits we are exploring:

  1. security and direct access to server APIs within certain components
  2. separate caching strategies for individual chunks of HTML
  3. leaner bundle size (keeping some dependencies solely on the server, e.g. syntax highlighting)
  4. extensibility
  5. rendering individual components within other modules or server routes (e.g. for component previews, OG images, PDF downloads, etc.)
  6. ...

Comments and suggestions are very welcome.

Roadmap

@Twitch0125
Copy link

I think it'd make sense to have all the available auto imports for server route handlers be available for server components.

@Hebilicious
Copy link
Member

Hebilicious commented Apr 23, 2023

This looks promising. Here's my personal 2 cents for "server components".

Disclaimer: I think this name in general is extremely confusing, due to the fact that it's already complicated to understand what's going on. This is not really a problem related to Nuxt, but React has the same problem with RSC, where most people don't really know how they differ from SSR components... Anyways here is some reading to get up to speed ... .

1) More Unified Rendering API

Right now here's a recap of what is possible (correct me if I'm wrong) :

  • Nitro route rules : It is possible to decide where and how a page will be rendered. This also allows the handling of more things, like caching rules, redirect, headers ...

    • This works at the page level through a config file
    • This allows patterns like SPA/SSG/SSR/SSR+SWR
  • Nuxt Server components : It is possible to tag a component as server only by using .server.vue. This disable hydration and achieve the same thing as SSG.

    • Works at the component level through the file name
    • This allows pattern like "0 javascript" components.
  • Nuxt Client components : This is a vue component that can be used to disable SSR at the component level, using a wrapper component.

    • Works at the component level through a wrapper component
    • This allows patterns like "Javascript only" rendering.

As we add more and more features and new things, this becomes hard to understand what takes priority and how everything works. I'm not sure what would be a good way to unify everything. That being said, given that routes and pages are also components, I would personally like to have a good granular API that works for both:

// This could be "aliased" to nuxt="server" and further down to "nuxt-server"
<script setup nuxt="{ render: 'server', hydrate: false }">
console.log("This will be logged on the server only")
</script>
<template>Server Only</template>
// This could be "aliased" to nuxt="client" and further down "nuxt-client"
<script setup nuxt="{ render: 'client' }">
console.log("This will be logged on the client only")
</script>
<template>Client Only</template>

This would be compatible with the "naming" api, ie, renaming a file to .server.vue would effectively do the same as using the nuxt="server" script tag. <ClientOnly /> could be deprecated and replaced by .client.vue.

There could be a configuration file/hook to define custom rendering "templates" so they can be re-used easily (like nuxt="server" => nuxt="{ render:'server', hydrate: false}").

If I'm not mistaken the default for all components and pages should be nuxt="{ render:'server', hydrate: 'true' }" and therefore can be omitted. There should be an easy way to change this default, to enable full SPA or SSG by default.

This is meant to work in tandem with Nitro and these should be "merged" with route rules (the same keys can be used in both route rules and here to unify the API). Some kind of human-readable auto-generated artifact (nuxt-rendered.json ?) should be generated, representing the component tree, so there's a source of truth of what's going on. This can be used by VSCode extensions and the likes for more advanced use case, such as displaying a different file icon for server/client components...

We can detect the "invalid" configurations (ie render: "client" + prerender: "true" or hydrate: "true") and emit a warning.

Alternative API

A few other alternatives API are worth suggesting :

//could be nuxt-render etc
<render>
export { render: 'server', hydrate: false, prerender: true }
</render>
<script setup>console.log("full static")</script>
<script setup>
useNuxtRender(() => ({render: "server", hydrate: "false"}))
console.log("server Only")
</script>

2) "Hybrid Component tree" and Streaming

Currently RSC can support a tree like this (we can achieve something similar with slots)
image
The entire tree is passed as JSON, and the client side code can reconstruct it with references to the client only components.
So maybe the RFC here needs to be extended to handle all use-cases ?

The streaming part can be a little confusing, we definitely need better naming conventions...
I know that there's some plans regarding streaming, and I wrote this in another issue, and this might be off-topic. Now that Lambda supports streaming, as well as Cloudflare Workers, how does this relate to Server Component streaming is an interesting question. They are different, as the HTML streaming is something related to the way the server sends HTML to the client, while the server component streaming is JSON based api-communication.

What I would assume is that if we have some kind of nested layout like this :

+------+------------------------------------+
| Index                                     |
|      +------+-----------------------------+
|      | SSG                                |
|      |      +------+----------------------+
|      |      | ServerOnly                  |
|      |      +-----------------------------+
|      +------------------------------------+
+------+------------------------------------+

Here Nuxt could use both HTML streaming (using vue pipeToWebWritable instead of renderToString), to send what's already present on the server (static layouts, pre-rendered pages/components), and then execute the the ServerOnly component rendering and pass that to the client using ... a different "stream" ?

Now I don't know if this different stream is what you meant by "Hybrid/remote/streaming sources for server components".

Note that for React, the Root component needs to be a "server component", and that server components supports children (ie slots) that can be either client or server components.

3) Nuxt Islands and relation to @vue/core

I'm not very familiar with that part of the code

The current implementation looks a little like this right now : the current server components use createStaticVNode/createStaticVNode and raw html from an internal nitro endpoint to render server components on the client.
The Nitro endpoint use renderToString, then respond with an object that contains the serialised html and the state (payload). That payload is then "revived" on the client side.

Perhaps this revive logic should be handled by Vue and not by Nuxt. I'm not sure what the benefits would be or if that's something that isn't priority, but it's worth mentioning here. Maybe the vue renderer should have this functionality and should be able to "revive" the state, but also event listeners, lifecycle hooks and everything else that is needed.

huang-julien pushed a commit to huang-julien/nuxt-hydration that referenced this issue May 16, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [nuxt](https://togithub.com/nuxt/nuxt) | [`3.4.2` ->
`3.5.0`](https://renovatebot.com/diffs/npm/nuxt/3.4.2/3.5.0) |
[![age](https://badges.renovateapi.com/packages/npm/nuxt/3.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/nuxt/3.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/nuxt/3.5.0/compatibility-slim/3.4.2)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/nuxt/3.5.0/confidence-slim/3.4.2)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>nuxt/nuxt</summary>

### [`v3.5.0`](https://togithub.com/nuxt/nuxt/releases/tag/v3.5.0)

[Compare Source](https://togithub.com/nuxt/nuxt/compare/v3.4.3...v3.5.0)

> 3.5.0 is a minor (feature) release with lots of new features to play
with.

#### 👀 Highlights

##### ⚡️ Vue 3.3 released!

Vue 3.3 has been released, with lots of exciting features, particularly
around type support. This also brings a significant improvement to data
fetching when navigating between nested pages
([nuxt/nuxt#20777),
thanks to [@&#8203;antfu](https://togithub.com/antfu) and
[@&#8203;baiwusanyu-c](https://togithub.com/baiwusanyu-c).

-   new `defineOptions` macro
-   'generic' components
-   typed slots and using external types in defineProps
-   ... and more

Read **[the full release
announcement](https://blog.vuejs.org/posts/vue-3-3)** for more details.

##### 🙌 Nitropack v2.4

We've been working on lots of improvements to Nitro and these have
landed already in Nitro v2.4 - you may already have this upgrade, which
contains a lot of bug fixes, updates to the module worker format for
Cloudflare, Vercel KV support and more.

One note: if you're deploying to Vercel or Netlify and want to benefit
from incremental static regeneration, you should now update your route
rules:

```diff
routeRules: {
--  '/blog/**': { swr: 3000 },
++  '/blog/**': { isr: 3000 },
}
```

Read **[the full release
notes](https://togithub.com/unjs/nitro/releases/tag/v2.4.0)**.

##### 💖 New defaults

**Rich JSON payload serialisation** is now enabled by default
([nuxt/nuxt#19205,
[nuxt/nuxt#20770).
This is both faster and allows serialising complex objects in the
payload passed from the Nuxt server to client (and also when extracting
payload data for prerendered sites).

This now means that **various rich JS types are supported
out-of-the-box**: regular expressions, dates, Map and Set and BigInt as
well as NuxtError - and Vue-specific objects like `ref`, `reactive`,
`shallowRef` and `shallowReactive`.

You can find [an
example](https://togithub.com/nuxt/nuxt/blob/main/test/fixtures/basic/pages/json-payload.vue)
in our test suite.

This is all possible due to
[Rich-Harris/devalue#&#8203;58](https://togithub.com/Rich-Harris/devalue/pull/58).
For a long time, Nuxt has been using our own fork of devalue owing to
issues serialising Errors and other non-POJO objects, but we now have
transitioned back to the original.

You can even register your own custom types with a new object-syntax
Nuxt plugin:

```ts [plugins/custom-payload-type.ts]
export default definePayloadPlugin(() => {
  definePayloadReducer('BlinkingText', data => data === '<original-blink>' && '_')
  definePayloadReviver('BlinkingText', () => '<revivified-blink>')
})
```

You can read more about how this works
[here](https://togithub.com/rich-harris/devalue#custom-types).

##### 🛝 Interactive server components

This feature should be considered highly experimental, but thanks to
some great work from
[@&#8203;huang-julien](https://togithub.com/huang-julien) we now support
interactive content within server components via *slots*
([nuxt/nuxt#20284).

You can follow the server component roadmap at
[nuxt/nuxt#19772.

##### ⏰ Environment config

You can now configure fully typed, per-environment overrides in your
`nuxt.config`:

```js
export default defineNuxtConfig({
  $production: {
    routeRules: {
      '/**': { isr: true }
    }
  },
  $development: {
    //
  }
})
```

If you're authoring layers, you can also use the `$meta` key to provide
metadata that you or the consumers of your layer might use.

Read more:
[nuxt/nuxt#20329.

##### 💪 Fully typed pages

You can benefit from fully typed routing within your Nuxt app via this
experimental integration with
https://github.com/posva/unplugin-vue-router - thanks to some great work
from [@&#8203;posva](https://togithub.com/posva)! Out of the box, this
will enable typed usage of `navigateTo`, `<NuxtLink>`, `router.push()`
and more. You can even get typed params within a page by using `const
route = useRoute('route-name')`.

```ts
export default defineNuxtConfig({
  experimental: {
    typedPages: true
  }
})
```

##### 🔎 'Bundler' module resolution

We now have full support within Nuxt for the `bundler` strategy of
[module
resolution](https://www.typescriptlang.org/docs/handbook/module-resolution.html).
We would recommend adopting this if possible. It has type support for
subpath exports, for example, but more exactly matches the behaviour of
build tools like Vite and Nuxt than `Node16` resolution.

```ts
export default defineNuxtConfig({
  typescript: {
    tsConfig: {
      compilerOptions: {
        moduleResolution: 'bundler'
      }
    }
  }
})
```

This turns on TypeScript's ability to 'follow' Node subpath exports. For
example, if a library has a subpath export like `mylib/path` that is
mapped to `mylib/dist/path.mjs` then the types for this can be pulled in
from `mylib/dist/path.d.ts` rather than requiring the library author to
create `mylib/path.d.ts`.

##### ⚗️ Separate server types

We plan to improve clarity within your IDE between the 'nitro' and 'vue'
part of your app, and we've shipped the first part of this via a
separate generated `tsconfig.json` for your `~/server` directory
([nuxt/nuxt#20559).
You can use by adding an additional `~/server/tsconfig.json` with the
following content:

```json
{
  "extends": "../.nuxt/tsconfig.server.json"
}
```

Although right now these values won't be respected when type checking,
you should get better type hints in your IDE.

##### 💀 Deprecations

Although we have not typed or documented the `build.extend` hook from
Nuxt 2, we have been calling it within the webpack builder. We are now
explicitly deprecating this and will remove it in a future minor
version.

#### ✅ Upgrading

As usual, our recommendation for upgrading is to run:

```sh
nuxi upgrade --force
```

This will refresh your lockfile as well, and ensures that you pull in
updates from other dependencies that Nuxt relies on, particularly in the
unjs ecosystem.

#### 👉 Changelog

[compare
changes](https://togithub.com/nuxt/nuxt/compare/v3.4.3...v3.5.0)

##### 🚀 Enhancements

- **kit:** Add `prepend` option to `addImportsDir`
([#&#8203;20307](https://togithub.com/nuxt/nuxt/pull/20307))
- **nuxt:** Add scoped helper for clearing error within boundary
([#&#8203;20508](https://togithub.com/nuxt/nuxt/pull/20508))
- **nuxt:** Auto import 'watchPostEffect' and 'watchSyncEffect' from vue
([#&#8203;20279](https://togithub.com/nuxt/nuxt/pull/20279))
- **vite:** Introduce `vite:configResolved` hook
([#&#8203;20411](https://togithub.com/nuxt/nuxt/pull/20411))
- **webpack:** Introduce `webpack:configResolved` hook
([#&#8203;20412](https://togithub.com/nuxt/nuxt/pull/20412))
- **kit:** Allow vite and webpack plugins to be prepended
([#&#8203;20403](https://togithub.com/nuxt/nuxt/pull/20403))
- **nuxt:** Add layer meta and env overrides to config types
([#&#8203;20329](https://togithub.com/nuxt/nuxt/pull/20329))
- **test-utils:** Add option to configure test server port
([#&#8203;20443](https://togithub.com/nuxt/nuxt/pull/20443))
- **nuxt:** Allow access to components within app
([#&#8203;20604](https://togithub.com/nuxt/nuxt/pull/20604))
- **kit:** Support passing getter to `addVitePlugin` and
`addWebpackPlugin`
([#&#8203;20525](https://togithub.com/nuxt/nuxt/pull/20525))
- **cli:** Allow greater control of `nuxi analyze` from cli
([#&#8203;20387](https://togithub.com/nuxt/nuxt/pull/20387))
- **nuxt:** Add `nuxtApp.runWithContext`
([#&#8203;20608](https://togithub.com/nuxt/nuxt/pull/20608))
- **deps:** Upgrade to nitropack v2.4
([#&#8203;20688](https://togithub.com/nuxt/nuxt/pull/20688))
- **nuxt:** Add experimental `typedPages` option
([#&#8203;20367](https://togithub.com/nuxt/nuxt/pull/20367))
- **nuxt:** Add apps to nuxt build-time instance
([#&#8203;20637](https://togithub.com/nuxt/nuxt/pull/20637))
- **cli:** Allow passing overrides to other nuxi commands
([#&#8203;20760](https://togithub.com/nuxt/nuxt/pull/20760))
- **schema:** Enable rich json payloads by default
([#&#8203;20770](https://togithub.com/nuxt/nuxt/pull/20770))
- **deps:** Update vue to v3.3
([#&#8203;20478](https://togithub.com/nuxt/nuxt/pull/20478))
- **nuxt:** Use `runWithContext` within `callWithNuxt`
([#&#8203;20775](https://togithub.com/nuxt/nuxt/pull/20775))
- **nuxt:** Add `useRequestURL` helper
([#&#8203;20765](https://togithub.com/nuxt/nuxt/pull/20765))
- **nuxt:** Allow fallback production content in `<DevOnly>`
([#&#8203;20817](https://togithub.com/nuxt/nuxt/pull/20817))
- **kit:** `addBuildPlugin` for builder-agnostic implementation
([#&#8203;20587](https://togithub.com/nuxt/nuxt/pull/20587))
- **nuxt:** Allow keeping fallback for `NuxtClientFallback`
([#&#8203;20336](https://togithub.com/nuxt/nuxt/pull/20336))
- **nuxt:** Support separate server tsconfig
([#&#8203;20559](https://togithub.com/nuxt/nuxt/pull/20559))
- **nuxt:** Full scoped slots support for server components
([#&#8203;20284](https://togithub.com/nuxt/nuxt/pull/20284))
- **nuxt:** Support parallel plugins
([#&#8203;20460](https://togithub.com/nuxt/nuxt/pull/20460))

##### 🩹 Fixes

- **nuxt:** Remove backwards-compatible runtimeConfig proxy
([#&#8203;20340](https://togithub.com/nuxt/nuxt/pull/20340))
- **nuxt:** Add `@nuxt/devtools` module before core modules
([#&#8203;20595](https://togithub.com/nuxt/nuxt/pull/20595))
- **nuxt:** Properly handle query for component wrapper
([#&#8203;20591](https://togithub.com/nuxt/nuxt/pull/20591))
- **nuxt:** Skip payload extraction for island context
([#&#8203;20590](https://togithub.com/nuxt/nuxt/pull/20590))
- **nuxt:** Remove internal `<FragmentWrapper>`
([#&#8203;20607](https://togithub.com/nuxt/nuxt/pull/20607))
- **nuxt:** Ensure `useError` is called with nuxt app context
([#&#8203;20585](https://togithub.com/nuxt/nuxt/pull/20585))
- **nuxt:** Run page meta plugin on all pages (and only pages)
([#&#8203;20628](https://togithub.com/nuxt/nuxt/pull/20628))
- **nuxt, vite:** Ignore `nuxt_component` ssr style and `isVue`
([#&#8203;20679](https://togithub.com/nuxt/nuxt/pull/20679))
- **webpack:** Warn when using deprecated `build.extend` hook
([#&#8203;20605](https://togithub.com/nuxt/nuxt/pull/20605))
- **nuxt:** Allow resolving client nuxt app to singleton
([#&#8203;20639](https://togithub.com/nuxt/nuxt/pull/20639))
- **nuxt:** Generate empty sourcemaps for wrappers
([#&#8203;20744](https://togithub.com/nuxt/nuxt/pull/20744))
- **nuxt:** Prevent treeshaking hooks with composable names
([#&#8203;20745](https://togithub.com/nuxt/nuxt/pull/20745))
- **kit:** Prefer esm resolution for modules to install
([#&#8203;20757](https://togithub.com/nuxt/nuxt/pull/20757))
- **vite:** Expand `fs.allow` dirs to include app files
([#&#8203;20755](https://togithub.com/nuxt/nuxt/pull/20755))
- **nuxt:** Deduplicate global components before registration
([#&#8203;20743](https://togithub.com/nuxt/nuxt/pull/20743))
- **nuxt:** Remove webstorm compatibility augmentation
([0258acdc8](https://togithub.com/nuxt/nuxt/commit/0258acdc8))
- **nuxt:** Enable suspensible behaviour for nested pages
([#&#8203;20777](https://togithub.com/nuxt/nuxt/pull/20777))
- **cli:** Hard-reload nuxt when `.env` changes
([#&#8203;20501](https://togithub.com/nuxt/nuxt/pull/20501))
- **nuxt:** Avoid destructuring error prop (works around upstream bug)
([#&#8203;20795](https://togithub.com/nuxt/nuxt/pull/20795))
- **nuxt:** Always inline styles for server/island components
([#&#8203;20599](https://togithub.com/nuxt/nuxt/pull/20599))
- **nuxt:** Allow serialising undefined refs
([#&#8203;20828](https://togithub.com/nuxt/nuxt/pull/20828))
- **nuxt:** Transform client fallbacks directly on SFCs
([#&#8203;20835](https://togithub.com/nuxt/nuxt/pull/20835))
- **vite:** Dedupe/optimize more vue core deps
([#&#8203;20829](https://togithub.com/nuxt/nuxt/pull/20829))
- **nuxt:** Get fallback for `<DevOnly>` from parsed html
([#&#8203;20840](https://togithub.com/nuxt/nuxt/pull/20840))
- **nuxt:** Ensure all dir parts are present in component name
([#&#8203;20779](https://togithub.com/nuxt/nuxt/pull/20779))
- **nuxt:** Allow `pages:extend` to enable pages module
([#&#8203;20806](https://togithub.com/nuxt/nuxt/pull/20806))
- **nuxt:** Stop loading indicator on vue errors
([#&#8203;20738](https://togithub.com/nuxt/nuxt/pull/20738))
- **nuxt:** Add types for webpack/vite environments
([#&#8203;20749](https://togithub.com/nuxt/nuxt/pull/20749))
- **nuxt:** Pass from + savedPosition to first `scrollBehavior`
([#&#8203;20859](https://togithub.com/nuxt/nuxt/pull/20859))

##### 💅 Refactors

- **schema:** Move `runtimeCompiler` option out of experimental
([#&#8203;20606](https://togithub.com/nuxt/nuxt/pull/20606))
- **kit:** Use esm utils for `resolvePath`
([#&#8203;20756](https://togithub.com/nuxt/nuxt/pull/20756))

##### 📖 Documentation

- Fix typo ([#&#8203;20577](https://togithub.com/nuxt/nuxt/pull/20577))
- Update tailwind configuration guide
([#&#8203;20598](https://togithub.com/nuxt/nuxt/pull/20598))
- Fix fetch composable examples
([#&#8203;20603](https://togithub.com/nuxt/nuxt/pull/20603))
- Note that `useCookie` does not share state
([#&#8203;20665](https://togithub.com/nuxt/nuxt/pull/20665))
- Selective pre-rendering options
([#&#8203;20670](https://togithub.com/nuxt/nuxt/pull/20670))
- Ensure we guard all `navigateTo` examples
([#&#8203;20678](https://togithub.com/nuxt/nuxt/pull/20678))
- Add `useSeoMeta` and `useServerSeoMeta` pages
([#&#8203;20656](https://togithub.com/nuxt/nuxt/pull/20656))
- Recommend `<NuxtLayout>` when migrating `error.vue`
([#&#8203;20690](https://togithub.com/nuxt/nuxt/pull/20690))
- Add lagon to presets list
([#&#8203;20706](https://togithub.com/nuxt/nuxt/pull/20706))
- Add `await` before lazy composable examples
([7e7e006e9](https://togithub.com/nuxt/nuxt/commit/7e7e006e9))
- Add missing step migrating to `pinia`
([#&#8203;20778](https://togithub.com/nuxt/nuxt/pull/20778))
- Server directory improvements
([d53cc604d](https://togithub.com/nuxt/nuxt/commit/d53cc604d))

##### 🏡 Chore

- Revert markdownlint upgrade
([da29dea5c](https://togithub.com/nuxt/nuxt/commit/da29dea5c))
- Run docs lint workflow on dep upgrades
([c536e5a63](https://togithub.com/nuxt/nuxt/commit/c536e5a63))
- Revert `markdownlint-cli` update and prevent auto-update
([675445f98](https://togithub.com/nuxt/nuxt/commit/675445f98))
- Ban `@ts-ignore`
([4f0d3d4ae](https://togithub.com/nuxt/nuxt/commit/4f0d3d4ae))
- Do not install example dependencies
([#&#8203;20689](https://togithub.com/nuxt/nuxt/pull/20689))
- Disallow `.only` in tests
([ad97cb45a](https://togithub.com/nuxt/nuxt/commit/ad97cb45a))
- Type-check `.mjs` files
([#&#8203;20711](https://togithub.com/nuxt/nuxt/pull/20711))
- Fix typo in `pnpm-workspace.yaml`
([#&#8203;20751](https://togithub.com/nuxt/nuxt/pull/20751))
- Update target for `externalVue` removal
([a33d2e7ae](https://togithub.com/nuxt/nuxt/commit/a33d2e7ae))
-   Lint ([742f61766](https://togithub.com/nuxt/nuxt/commit/742f61766))

##### ✅ Tests

- Test with bundler module resolution
([#&#8203;20629](https://togithub.com/nuxt/nuxt/pull/20629))

##### 🤖 CI

- Run autofix on renovate branches
([af75f18cf](https://togithub.com/nuxt/nuxt/commit/af75f18cf))
- Run 2.x nightly release on node 16
([a81f9e4c8](https://togithub.com/nuxt/nuxt/commit/a81f9e4c8))
- Add conditional for node 16 test
([aee1218e6](https://togithub.com/nuxt/nuxt/commit/aee1218e6))
- Set max memory for nuxt2 release script globally
([d1a5719cb](https://togithub.com/nuxt/nuxt/commit/d1a5719cb))
- Add workflow to release branches
([bc28d536c](https://togithub.com/nuxt/nuxt/commit/bc28d536c))
- Update pr condition
([f8c7b34bd](https://togithub.com/nuxt/nuxt/commit/f8c7b34bd))
- Update repo 🤣
([f88c1e645](https://togithub.com/nuxt/nuxt/commit/f88c1e645))
- Allow specifying tag for edge releases
([5fdb6a6d6](https://togithub.com/nuxt/nuxt/commit/5fdb6a6d6))
- Comment with link to tag of released version
([f945cb197](https://togithub.com/nuxt/nuxt/commit/f945cb197))
- Pass tag as argument
([1aec0e503](https://togithub.com/nuxt/nuxt/commit/1aec0e503))
- Release edge versions of labelled prs
([cdc42d044](https://togithub.com/nuxt/nuxt/commit/cdc42d044))

##### ❤️  Contributors

-   Daniel Roe ([@&#8203;danielroe](https://togithub.com/danielroe))
-   Sébastien Chopin ([@&#8203;Atinux](https://togithub.com/Atinux))
-   Anthony Fu ([@&#8203;antfu](https://togithub.com/antfu))
- Julien Huang
([@&#8203;huang-julien](https://togithub.com/huang-julien))
- Alexander
([@&#8203;xanderbarkhatov](https://togithub.com/xanderbarkhatov))
- Dario Ferderber
([@&#8203;darioferderber](https://togithub.com/darioferderber))
-   白雾三语 ([@&#8203;baiwusanyu-c](https://togithub.com/baiwusanyu-c))
-   Inesh Bose ([@&#8203;ineshbose](https://togithub.com/ineshbose))
-   Lehoczky Zoltán ([@&#8203;Lehoczky](https://togithub.com/Lehoczky))
-   Emile Caron ([@&#8203;emilecaron](https://togithub.com/emilecaron))
- Eckhardt (Kaizen) Dreyer
([@&#8203;Eckhardt-D](https://togithub.com/Eckhardt-D))
-   Eduardo San Martin Morote
-   Tom Lienard ([@&#8203;QuiiBz](https://togithub.com/QuiiBz))
-   Scscgit ([@&#8203;scscgit](https://togithub.com/scscgit))
-   Clément Ollivier ([@&#8203;clemcode](https://togithub.com/clemcode))
- Jamie Warburton ([@&#8203;Jamiewarb](https://togithub.com/Jamiewarb))
-   Enkot ([@&#8203;enkot](https://togithub.com/enkot))
-   Phojie Rengel ([@&#8203;phojie](https://togithub.com/phojie))
-   Harlan Wilton ([@&#8203;harlan-zw](https://togithub.com/harlan-zw))
- Gergő Jedlicska
([@&#8203;gjedlicska](https://togithub.com/gjedlicska))
- Stefan Milosevic
([@&#8203;smilosevic](https://togithub.com/smilosevic))
-   Pavel Mokin ([@&#8203;Lyrialtus](https://togithub.com/Lyrialtus))

### [`v3.4.3`](https://togithub.com/nuxt/nuxt/releases/tag/v3.4.3)

[Compare Source](https://togithub.com/nuxt/nuxt/compare/v3.4.2...v3.4.3)

> 3.4.3 is a patch release with the latest bug fixes. 🐞 It is expected
that the next release will be v3.5, in approximately two weeks' time.

#### ✅ Upgrading

As usual, our recommendation for upgrading is to run:

```sh
nuxi upgrade --force
```

This will refresh your lockfile as well, and ensures that you pull in
updates from other dependencies that Nuxt relies on, particularly in the
unjs ecosystem.

#### 👉 Changelog

[compare
changes](https://togithub.com/nuxt/nuxt/compare/v3.4.2...v3.4.3)

##### 🩹 Fixes

- **nuxt:** Don't call `timeEnd` unless we're debugging
([#&#8203;20424](https://togithub.com/nuxt/nuxt/pull/20424))
- **nuxt:** Use key to force server component re-rendering
([#&#8203;19911](https://togithub.com/nuxt/nuxt/pull/19911))
- **nuxt:** Add basic typings for `<ClientOnly>`
([f1ded44e8](https://togithub.com/nuxt/nuxt/commit/f1ded44e8))
- **nuxt:** Use `event.node.req` in cookie utility
([#&#8203;20474](https://togithub.com/nuxt/nuxt/pull/20474))
- **deps:** Relax upper node version constraint
([#&#8203;20472](https://togithub.com/nuxt/nuxt/pull/20472))
- **nuxi,schema:** Support `devServer.https: true`
([#&#8203;20498](https://togithub.com/nuxt/nuxt/pull/20498))
- **nuxt:** Throw 404 when accessing `/__nuxt_error` directly
([#&#8203;20497](https://togithub.com/nuxt/nuxt/pull/20497))
- **nuxt:** Use `callAsync` for executing hooks with context
([#&#8203;20510](https://togithub.com/nuxt/nuxt/pull/20510))
- **nuxt:** Improved typing support for app config
([#&#8203;20526](https://togithub.com/nuxt/nuxt/pull/20526))
- **nuxt:** Call `app:error` in SSR before rendering error page
([#&#8203;20511](https://togithub.com/nuxt/nuxt/pull/20511))
- **nuxt:** Restrict access to single renderer outside of test/rootDir
([#&#8203;20543](https://togithub.com/nuxt/nuxt/pull/20543))
- **nuxt:** Throw errors when running legacy `asyncData`
([#&#8203;20535](https://togithub.com/nuxt/nuxt/pull/20535))
- **nuxt:** Transform `#components` imports into direct component
imports ([#&#8203;20547](https://togithub.com/nuxt/nuxt/pull/20547))
- **nuxt:** Return `RenderResponse` for redirects
([#&#8203;20496](https://togithub.com/nuxt/nuxt/pull/20496))

##### 📖 Documentation

- Fix typos on docs homepage
([#&#8203;20456](https://togithub.com/nuxt/nuxt/pull/20456))
- Update links to `vue-router` docs
([#&#8203;20454](https://togithub.com/nuxt/nuxt/pull/20454))
- Remove RC reference and add link to vue migration build
([#&#8203;20485](https://togithub.com/nuxt/nuxt/pull/20485))
- Add cdn proxy section
([#&#8203;20408](https://togithub.com/nuxt/nuxt/pull/20408))
- Add a next steps link to first page of migration docs
([#&#8203;20512](https://togithub.com/nuxt/nuxt/pull/20512))
- Add custom fetch composable example
([#&#8203;20115](https://togithub.com/nuxt/nuxt/pull/20115))
- Adjust wrong link after repo migration
([#&#8203;20536](https://togithub.com/nuxt/nuxt/pull/20536))

##### ✅ Tests

- Exclude default error pages from bundle test
([ba320a558](https://togithub.com/nuxt/nuxt/commit/ba320a558))
- Update snapshot
([ac598e4f4](https://togithub.com/nuxt/nuxt/commit/ac598e4f4))

##### 🤖 CI

- Publish edge release with provenance
([ec1503731](https://togithub.com/nuxt/nuxt/commit/ec1503731))
- Run release script with node 18
([0d10e9734](https://togithub.com/nuxt/nuxt/commit/0d10e9734))
- Try releasing `nuxt-edge` with provenance
([753c4c2a3](https://togithub.com/nuxt/nuxt/commit/753c4c2a3))
- Run nuxt2 nightly release on node 14 again
([48c034cf0](https://togithub.com/nuxt/nuxt/commit/48c034cf0))

##### ❤️  Contributors

-   Daniel Roe ([@&#8203;danielroe](https://togithub.com/danielroe))
-   Anthony Fu ([@&#8203;antfu](https://togithub.com/antfu))
- Julien Huang
([@&#8203;huang-julien](https://togithub.com/huang-julien))
- Andrew Luca
([@&#8203;iamandrewluca](https://togithub.com/iamandrewluca))
-   Adrien Zaganelli ([@&#8203;adrienZ](https://togithub.com/adrienZ))
- Michael Gale (he/him)
([@&#8203;miclgael](https://togithub.com/miclgael))
-   Clément Ollivier ([@&#8203;clemcode](https://togithub.com/clemcode))
-   Paul Melero ([@&#8203;gangsthub](https://togithub.com/gangsthub))
- Jonas Thelemann
([@&#8203;dargmuesli](https://togithub.com/dargmuesli))
-   Johannes Przymusinski ([@&#8203;cngJo](https://togithub.com/cngJo))
- Idorenyin Udoh
([@&#8203;idorenyinudoh](https://togithub.com/idorenyinudoh))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/huang-julien/nuxt-hydration).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS44Ny4xIiwidXBkYXRlZEluVmVyIjoiMzUuODcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@HendrikJan
Copy link

I'm probably a bit lat at this party, but I've got an alternative to .server components that has slightly different but mostly the same benefits: #20802

@cosbgn
Copy link

cosbgn commented Jun 1, 2023

I agree with @HendrikJan - His solution would be ideal for my use case. My main issue with component.server.vue is that I would still need multiple files, I would need a billing.vue page and a billing.server components, which doesn't change much from having a billing.js endpoint, I would still have 2 files to manage my billing.

Ideally I want one billing.vue page where I have all my billing logic, frontend and backed.
I have so many file-x.vue for frontend and file-x.js for backend - I would really love to unify them in one single file.

@Hebilicious
Copy link
Member

Hebilicious commented Jun 1, 2023

I agree with @HendrikJan - His solution would be ideal for my use case. My main issue with component.server.vue is that I would still need multiple files, I would need a billing.vue page and a billing.server components, which doesn't change much from having a billing.js endpoint, I would still have 2 files to manage my billing.

Ideally I want one billing.vue page where I have all my billing logic, frontend and backed. I have so many file-x.vue for frontend and file-x.js for backend - I would really love to unify them in one single file.

What you are both discussing is another feature that is quite different from server components.
A SFC block or something like this can be implemented without too much effort (I think):

//page/todos.vue
<server>
export default defineEventHandler(() => {
	return [{id: 1, description: "hello-world"}]
})
</server>
<script setup>
const { data } = useFetch("/api/todos")
console.log(data) // [{id: 1, description: "hello-world"}]
</script>

What would happen is that the server block content would be added as route handler in /api/todos.ts.
I've been thinking about doing something like this with a nuxt module... If enough people are interested I might just move forward with it.

Edit : This is now available as a module https://github.com/Hebilicious/server-block-nuxt

@cosbgn
Copy link

cosbgn commented Jun 1, 2023

I've been thinking about doing something like this with a nuxt module... If enough people are interested I might just move forward with it.

As a module it would be amazing and I think the implementation is great (using fetch) and keeping it as a backend function

@urbgimtam
Copy link

I've been trying out Nuxt Server Components and really enjoyed the experience!

But I have a few questions that I consider interesting:

  • If there was a way for Nuxt to automatically detect if a component can be upgraded into a server component (ie: doesn't have interactivity, etc), wouldn't it be interesting to apply this detection and conversion all over the Nuxt app? What would be its pros and cons?

  • The usage of Server Components can improve interaction responsiveness due to less hydration and less js to be downloaded to the client. But at the extreme, wouldn't the server CPU become taxed, building all the HTML to ship to the client? Would a caching system for Server Components bring benefits, and how could that work?

@jd-solanki
Copy link
Contributor

jd-solanki commented Jul 28, 2023

If there was a way for Nuxt to automatically detect if a component can be upgraded into a server component (ie: doesn't have interactivity, etc), wouldn't it be interesting to apply this detection and conversion all over the Nuxt app? What would be its pros and cons?

I really liked this, In addition to this, I also like to ask will it be possible to identify if the component is rendered on server or on the client because when my react/nextjs colleagues ask my help on server component first time I wonder about is "how do you identify if that component loaded on sever or client". The point is, for beginner to server side components it might be the nightmare.

@MuhammadKhizar7
Copy link

  • The usage of Server Components can improve interaction responsiveness due to less hydration and less js to be downloaded to the client. But at the extreme, wouldn't the server CPU become taxed, building all the HTML to ship to the client? Would a caching system for Server Components bring benefits, and how could that work?

I also discussed the same thing before in a discussion #16469. I think server components and caching go hand in hand (just like React does). Otherwise, what would be the difference between Nuxt and PHP or ASP.NET Razor pages (they also have page caching)? With server components and on edge (Vercel, Cloudflare Worker), there is a cost and time delay (like 10 API calls) every time this page renders, just like in server-side PHP, etc.

I am proposing component caching along with the current page-level caching. Some components change often, while others do not. Why not cache these components instead of the page? Or, if they never change, make them static?

@clemvnt
Copy link

clemvnt commented Aug 30, 2023

Hey guys,

With the future evolution of interactive components within server components, will there be a "mode" where all pages are server components by default?

@Rigo-m
Copy link
Contributor

Rigo-m commented Sep 1, 2023

From a team-oriented standpoint, is it feasible to add an option to the nuxt.config so that by default every component is a server component and client hydration is opt-in?
This would help with streamlining development so that the approach for the whole team is to work in a client-performance, small client bundle environment and thoroughly think through the addition of client side javascript.
I don't know if I conveyed my thoughts correctly on this one.
Let me know.

@madebyfabian
Copy link
Sponsor Collaborator

madebyfabian commented Oct 8, 2023

Hi there! I just discovered something currently not implemented that could be interesting:

When using throw createError({ statusCode: 404 }) in a server component, I expect nuxt to transfer the error to the client and display an error page. Just like it's advised to do so in regular components at https://nuxt.com/docs/getting-started/error-handling#example-1.

When I try to do that with a server component, the follow happens:

  1. The HTTP Request to this component (/__nuxt_island/...) returns a clean http 404. That's kind of good.
  2. But then I get a log from vue-router, complaining the route doesn't exist:
    [Vue Router warn]: No match found for location with path "/__nuxt_island/MyComponent_KtzRNsoXNj"
  3. And the rendered page on the client doesn't show any signs of an error. Just a blank page.

Is there a way to catch these so that I get the error.vue template displayed, and nuxt catching that error?

@Youhan
Copy link
Contributor

Youhan commented Oct 20, 2023

Would there be a way to serve a server component using nuxt and then consume it using vanilla JS on other apps?

@fabianwohlfart
Copy link

Encountered a little caveat that I was not aware of, not sure if it's mentioned somewhere:
A component islands always needs a root element.

@fabianwohlfart
Copy link

Is there a way to not run into 431 header issues when using server components, for example for long texts passed as props to a markdown component, despite changing the server settings max-http-header-size?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests