@nuxt/docs 4.0.0-alpha.4 → 4.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -992,6 +992,7 @@ Nuxt now generates separate TypeScript configurations for different contexts to
992
992
  * `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
993
993
  * `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
994
994
  * `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
995
+ * `.nuxt/tsconfig.shared.json` - For code shared between app and server contexts (like types and non-environment specific utilities)
995
996
  * `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
996
997
 
997
998
  2. **Backward compatibility**: Existing projects that extend `.nuxt/tsconfig.json` will continue to work as before.
@@ -1027,6 +1028,7 @@ However, to take advantage of improved type checking, you can opt in to the new
1027
1028
  "references": [
1028
1029
  { "path": "./.nuxt/tsconfig.app.json" },
1029
1030
  { "path": "./.nuxt/tsconfig.server.json" },
1031
+ { "path": "./.nuxt/tsconfig.shared.json" },
1030
1032
  { "path": "./.nuxt/tsconfig.node.json" }
1031
1033
  ]
1032
1034
  }
@@ -76,17 +76,27 @@ Any redirection on the server will result in a `Location:` header being sent to
76
76
 
77
77
  :read-more{to="/docs/guide/directory-structure/middleware"}
78
78
 
79
- ### Step 6: Setup Page and Components
79
+ ### Step 6: Render Page and Components
80
80
 
81
- Nuxt initializes the page and its components during this step and fetches any required data with `useFetch` and `useAsyncData`. Since there are no dynamic updates and no DOM operations occur on the server, Vue lifecycle hooks such as `onBeforeMount`, `onMounted`, and subsequent hooks are **NOT** executed during SSR.
81
+ Nuxt renders the page and its components and fetches any required data with `useFetch` and `useAsyncData` during this step. Since there are no dynamic updates and no DOM operations occur on the server, Vue lifecycle hooks such as `onBeforeMount`, `onMounted`, and subsequent hooks are **NOT** executed during SSR.
82
+
83
+ By default, Vue pauses dependency tracking during SSR for better performance.
84
+
85
+ ::callout{icon="i-lucide-lightbulb"}
86
+ There is no reactivity on the server side because Vue SSR renders the app top-down as static HTML, making it impossible to go back and modify content that has already been rendered.
87
+ ::
82
88
 
83
89
  ::important
84
90
  You should avoid code that produces side effects that need cleanup in root scope of `<script setup>`. An example of such side effects is setting up timers with `setInterval`. In client-side only code we may setup a timer and then tear it down in `onBeforeUnmount` or `onUnmounted`. However, because the unmount hooks will never be called during SSR, the timers will stay around forever. To avoid this, move your side-effect code into `onMounted` instead.
85
91
  ::
86
92
 
87
- ### Step 7: Render and Generate HTML Output
93
+ ::tip{icon="i-lucide-video" to="https://youtu.be/dZSNW07sO-A" target="_blank"}
94
+ Watch a video from Daniel Roe explaining Server Rendering and Global State.
95
+ ::
96
+
97
+ ### Step 7: Generate HTML Output
88
98
 
89
- After all components are initialized and data is fetched, Nuxt combines the components with settings from `unhead` to generate a complete HTML document. This HTML, along with the associated data, is sent back to the client to complete the SSR process.
99
+ After all required data is fetched and the components are rendered, Nuxt combines the rendered components with settings from `unhead` to generate a complete HTML document. This HTML, along with the associated data, is then sent back to the client to complete the SSR process.
90
100
 
91
101
  ::callout{icon="i-lucide-lightbulb"}
92
102
  After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
@@ -92,6 +92,7 @@ When you run `nuxt dev` or `nuxt build`, Nuxt will generate multiple `tsconfig.j
92
92
  - **`.nuxt/tsconfig.app.json`** - Configuration for your application code
93
93
  - **`.nuxt/tsconfig.node.json`** - Configuration for your `nuxt.config` and modules
94
94
  - **`.nuxt/tsconfig.server.json`** - Configuration for server-side code (when applicable)
95
+ - **`.nuxt/tsconfig.shared.json`** - For code shared between app and server contexts (like types and non-environment specific utilities)
95
96
  - **`.nuxt/tsconfig.json`** - Legacy configuration for backward compatibility
96
97
 
97
98
  Each of these files is configured to reference the appropriate dependencies and provide optimal type-checking for their specific context.
@@ -55,6 +55,10 @@ Since `.env` files are not used in production, you must explicitly set environme
55
55
 
56
56
  * Many cloud service providers, such as Vercel, Netlify, and AWS, provide interfaces for setting environment variables via their dashboards, CLI tools or configuration files.
57
57
 
58
+ ::important
59
+ `runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
60
+ ::
61
+
58
62
  ## Production Preview
59
63
 
60
64
  For local production preview purpose, we recommend using [`nuxt preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
@@ -5,7 +5,7 @@ head.title: "tsconfig.json"
5
5
  navigation.icon: i-lucide-file
6
6
  ---
7
7
 
8
- Nuxt [automatically generates](/docs/guide/concepts/typescript) multiple TypeScript configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, `.nuxt/tsconfig.node.json`) with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
8
+ Nuxt [automatically generates](/docs/guide/concepts/typescript) multiple TypeScript configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, `.nuxt/tsconfig.node.json` and `.nuxt/tsconfig.shared.json`) with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
9
9
 
10
10
  You can benefit from this by creating a `tsconfig.json` in the root of your project with the following content:
11
11
 
@@ -19,6 +19,9 @@ You can benefit from this by creating a `tsconfig.json` in the root of your proj
19
19
  {
20
20
  "path": "./.nuxt/tsconfig.server.json"
21
21
  },
22
+ {
23
+ "path": "./.nuxt/tsconfig.shared.json"
24
+ },
22
25
  {
23
26
  "path": "./.nuxt/tsconfig.node.json"
24
27
  }
@@ -159,7 +159,7 @@ const { data: users2 } = useAsyncData('users', () => $fetch('/api/users'), { imm
159
159
  By default, Nuxt waits until a `refresh` is finished before it can be executed again.
160
160
 
161
161
  ::note
162
- If you have not fetched data on the server (for example, with `server: false`), then the data _will not_ be fetched until hydration completes. This means even if you await [`useAsyncData`](/docs/api/composables/use-async-data) on the client side, `data` will remain `null` within `<script setup>`.
162
+ If you have not fetched data on the server (for example, with `server: false`), then the data _will not_ be fetched until hydration completes. This means even if you await [`useAsyncData`](/docs/api/composables/use-async-data) on the client side, `data` will remain `undefined` within `<script setup>`.
163
163
  ::
164
164
 
165
165
  ## Type
@@ -170,7 +170,7 @@ function useAsyncData<DataT, DataE>(
170
170
  options?: AsyncDataOptions<DataT>
171
171
  ): AsyncData<DataT, DataE>
172
172
  function useAsyncData<DataT, DataE>(
173
- key: string | Ref<string> | ComputedRef<string>,
173
+ key: MaybeRefOrGetter<string>,
174
174
  handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
175
175
  options?: AsyncDataOptions<DataT>
176
176
  ): Promise<AsyncData<DataT, DataE>>
@@ -184,7 +184,7 @@ type AsyncDataOptions<DataT> = {
184
184
  default?: () => DataT | Ref<DataT> | null
185
185
  transform?: (input: DataT) => DataT | Promise<DataT>
186
186
  pick?: string[]
187
- watch?: WatchSource[] | false
187
+ watch?: MultiWatchSources | false
188
188
  getCachedData?: (key: string, nuxtApp: NuxtApp, ctx: AsyncDataRequestContext) => DataT | undefined
189
189
  }
190
190
 
@@ -194,11 +194,11 @@ type AsyncDataRequestContext = {
194
194
  }
195
195
 
196
196
  type AsyncData<DataT, ErrorT> = {
197
- data: Ref<DataT | null>
197
+ data: Ref<DataT | undefined>
198
198
  refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
199
199
  execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
200
200
  clear: () => void
201
- error: Ref<ErrorT | null>
201
+ error: Ref<ErrorT | undefined>
202
202
  status: Ref<AsyncDataRequestStatus>
203
203
  };
204
204
 
@@ -103,7 +103,7 @@ function useFetch<DataT, ErrorT>(
103
103
  ): Promise<AsyncData<DataT, ErrorT>>
104
104
 
105
105
  type UseFetchOptions<DataT> = {
106
- key?: string
106
+ key?: MaybeRefOrGetter<string>
107
107
  method?: string
108
108
  query?: SearchParams
109
109
  params?: SearchParams
@@ -119,7 +119,8 @@ type UseFetchOptions<DataT> = {
119
119
  default?: () => DataT
120
120
  transform?: (input: DataT) => DataT | Promise<DataT>
121
121
  pick?: string[]
122
- watch?: WatchSource[] | false
122
+ $fetch?: typeof globalThis.$fetch
123
+ watch?: MultiWatchSources | false
123
124
  }
124
125
 
125
126
  type AsyncDataRequestContext = {
@@ -128,11 +129,11 @@ type AsyncDataRequestContext = {
128
129
  }
129
130
 
130
131
  type AsyncData<DataT, ErrorT> = {
131
- data: Ref<DataT | null>
132
+ data: Ref<DataT | undefined>
132
133
  refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
133
134
  execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
134
135
  clear: () => void
135
- error: Ref<ErrorT | null>
136
+ error: Ref<ErrorT | undefined>
136
137
  status: Ref<AsyncDataRequestStatus>
137
138
  }
138
139
 
@@ -151,7 +152,7 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
151
152
 
152
153
  | Option | Type | Default | Description |
153
154
  | ---| --- | --- | --- |
154
- | `key` | `string` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
155
+ | `key` | `MaybeRefOrGetter<string>` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
155
156
  | `method` | `string` | `'GET'` | HTTP request method. |
156
157
  | `query` | `object` | - | Query/search params to append to the URL. Alias: `params`. Supports refs/computed. |
157
158
  | `params` | `object` | - | Alias for `query`. |
@@ -167,10 +168,10 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
167
168
  | `transform` | `(input: DataT) => DataT \| Promise<DataT>` | - | Function to transform the result after resolving. |
168
169
  | `getCachedData`| `(key, nuxtApp, ctx) => DataT \| undefined` | - | Function to return cached data. See below for default. |
169
170
  | `pick` | `string[]` | - | Only pick specified keys from the result. |
170
- | `watch` | `WatchSource[] \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
171
+ | `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
171
172
  | `deep` | `boolean` | `false` | Return data in a deep ref object. |
172
173
  | `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
173
- | `$fetch` | `typeof $fetch` | - | Custom $fetch implementation. |
174
+ | `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. |
174
175
 
175
176
  ::note
176
177
  All fetch options can be given a `computed` or `ref` value. These will be watched and new requests made automatically with any new values if they are updated.
@@ -189,10 +190,10 @@ This only caches data when `experimental.payloadExtraction` in `nuxt.config` is
189
190
 
190
191
  | Name | Type | Description |
191
192
  | --- | --- |--- |
192
- | `data` | `Ref<DataT \| null>` | The result of the asynchronous fetch. |
193
+ | `data` | `Ref<DataT \| undefined>` | The result of the asynchronous fetch. |
193
194
  | `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. By default, Nuxt waits until a `refresh` is finished before it can be executed again. |
194
195
  | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
195
- | `error` | `Ref<ErrorT \| null>` | Error object if the data fetching failed. |
196
+ | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
196
197
  | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. See below for possible values. |
197
198
  | `clear` | `() => void` | Resets `data` to `undefined` (or the value of `options.default()` if provided), `error` to `undefined`, set `status` to `idle`, and cancels any pending requests. |
198
199
 
@@ -164,6 +164,9 @@ Nuxt can type-check your app using [`vue-tsc`](https://github.com/vuejs/language
164
164
  {
165
165
  "path": "./.nuxt/tsconfig.server.json"
166
166
  },
167
+ {
168
+ "path": "./.nuxt/tsconfig.shared.json"
169
+ },
167
170
  {
168
171
  "path": "./.nuxt/tsconfig.node.json"
169
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-rc.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",