@nuxt/docs-nightly 4.0.0-29112167.918f1988 → 4.0.0-29112967.ebff42f8

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.
@@ -54,6 +54,10 @@ pnpm create nuxt <project-name>
54
54
  bun create nuxt <project-name>
55
55
  ```
56
56
 
57
+ ```bash [deno]
58
+ deno -A npm:create-nuxt@latest <project-name>
59
+ ```
60
+
57
61
  ::
58
62
 
59
63
  ::tip
@@ -96,6 +100,10 @@ bun run dev -o
96
100
  # To use the Bun runtime during development
97
101
  # bun --bun run dev -o
98
102
  ```
103
+
104
+ ```bash [deno]
105
+ deno run dev -o
106
+ ```
99
107
  ::
100
108
 
101
109
  ::tip{icon="i-lucide-circle-check"}
@@ -76,6 +76,7 @@ export default defineNuxtConfig({
76
76
  // spaLoadingTemplateLocation: 'within',
77
77
  // parseErrorData: false,
78
78
  // pendingWhenIdle: true,
79
+ // alwaysRunFetchOnKeyChange: true,
79
80
  // defaults: {
80
81
  // useAsyncData: {
81
82
  // deep: true
@@ -755,6 +756,46 @@ export default defineNuxtConfig({
755
756
  })
756
757
  ```
757
758
 
759
+ ### Key Change Behavior in `useAsyncData` and `useFetch`
760
+
761
+ 🚦 **Impact Level**: Medium
762
+
763
+ #### What Changed
764
+
765
+ When using reactive keys in `useAsyncData` or `useFetch`, Nuxt automatically refetches data when the key changes. When `immediate: false` is set, `useAsyncData` will only fetch data when the key changes if the data has already been fetched once.
766
+
767
+ Previously, `useFetch` had slightly different behavior. It would always fetch data when the key changed.
768
+
769
+ Now, `useFetch` and `useAsyncData` behave consistently - by only fetch data when the key changes if the data has already been fetched once.
770
+
771
+ #### Reasons for Change
772
+
773
+ This ensures consistent behavior between `useAsyncData` and `useFetch`, and prevents unexpected fetches. If you have set `immediate: false`, then you must call `refresh` or `execute` or data will never be fetched in `useFetch` or `useAsyncData`.
774
+
775
+ #### Migration Steps
776
+
777
+ This change should generally improve the expected behavior, but if you were expecting changing the key or options of a non-immediate `useFetch`, you now will need to trigger it manually the first time.
778
+
779
+ ```diff
780
+ const id = ref('123')
781
+ const { data, execute } = await useFetch('/api/test', {
782
+ query: { id },
783
+ immediate: false
784
+ )
785
+ + watch(id, execute, { once: true })
786
+ ```
787
+
788
+ To opt out of this behavior:
789
+
790
+ ```ts
791
+ // Or globally in your Nuxt config
792
+ export default defineNuxtConfig({
793
+ experimental: {
794
+ alwaysRunFetchOnKeyChange: true
795
+ }
796
+ })
797
+ ```
798
+
758
799
  ### Shallow Data Reactivity in `useAsyncData` and `useFetch`
759
800
 
760
801
  🚦 **Impact Level**: Minimal
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: "Events"
3
+ description: "Nuxt provides a powerful event system powered by hookable."
4
+ ---
5
+
6
+ # Events
7
+
8
+ Using events is a great way to decouple your application and allow for more flexible and modular communication between different parts of your code. Events can have multiple listeners that do not depend on each other. For example, you may wish to send an email to your user each time an order has shipped. Instead of coupling your order processing code to your email code, you can emit an event which a listener can receive and use to dispatch an email.
9
+
10
+ The Nuxt event system is powered by [unjs/hookable](https://github.com/unjs/hookable), which is the same library that powers the Nuxt hooks system.
11
+
12
+ ## Creating Events and Listeners
13
+
14
+ You can create your own custom events using the `hook` method:
15
+
16
+ ```ts
17
+ const nuxtApp = useNuxtApp()
18
+
19
+ nuxtApp.hook('app:user:registered', payload => {
20
+ console.log('A new user has registered!', payload)
21
+ })
22
+ ```
23
+
24
+ To emit an event and notify any listeners, use `callHook`:
25
+
26
+ ```ts
27
+ const nuxtApp = useNuxtApp()
28
+
29
+ await nuxtApp.callHook('app:user:registered', {
30
+ id: 1,
31
+ name: 'John Doe',
32
+ })
33
+ ```
34
+
35
+ You can also use the payload object to enable two-way communication between the emitter and listeners. Since the payload is passed by reference, a listener can modify it to send data back to the emitter.
36
+
37
+ ```ts
38
+ const nuxtApp = useNuxtApp()
39
+
40
+ nuxtApp.hook('app:user:registered', payload => {
41
+ payload.message = 'Welcome to our app!'
42
+ })
43
+
44
+ const payload = {
45
+ id: 1,
46
+ name: 'John Doe',
47
+ }
48
+
49
+ await nuxtApp.callHook('app:user:registered', {
50
+ id: 1,
51
+ name: 'John Doe',
52
+ })
53
+
54
+ // payload.message will be 'Welcome to our app!'
55
+ ```
56
+
57
+ ::tip
58
+ You can inspect all events using the **Nuxt DevTools** Hooks panel.
59
+ ::
60
+
61
+ ## Augmenting Types
62
+
63
+ You can augment the types of hooks provided by Nuxt.
64
+
65
+ ```ts
66
+ import { HookResult } from "@nuxt/schema";
67
+
68
+ declare module '#app' {
69
+ interface RuntimeNuxtHooks {
70
+ 'your-nuxt-runtime-hook': () => HookResult
71
+ }
72
+ interface NuxtHooks {
73
+ 'your-nuxt-hook': () => HookResult
74
+ }
75
+ }
76
+
77
+ declare module 'nitro/types' {
78
+ interface NitroRuntimeHooks {
79
+ 'your-nitro-hook': () => void;
80
+ }
81
+ }
82
+ ```
@@ -76,23 +76,4 @@ Learn more about available Nitro lifecycle hooks.
76
76
 
77
77
  ## Additional Hooks
78
78
 
79
- You can add additional hooks by augmenting the types provided by Nuxt. This can be useful for modules.
80
-
81
- ```ts
82
- import { HookResult } from "@nuxt/schema";
83
-
84
- declare module '#app' {
85
- interface RuntimeNuxtHooks {
86
- 'your-nuxt-runtime-hook': () => HookResult
87
- }
88
- interface NuxtHooks {
89
- 'your-nuxt-hook': () => HookResult
90
- }
91
- }
92
-
93
- declare module 'nitro/types' {
94
- interface NitroRuntimeHooks {
95
- 'your-nitro-hook': () => void;
96
- }
97
- }
98
- ```
79
+ Learn more about creating custom hooks in the [Events section](/docs/guide/going-further/events).
@@ -24,7 +24,7 @@ yarn create nuxt -t module my-module
24
24
  ```
25
25
 
26
26
  ```bash [pnpm]
27
- pnpm create nuxt -- -t module my-module
27
+ pnpm create nuxt -t module my-module
28
28
  ```
29
29
 
30
30
  ```bash [bun]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.0.0-29112167.918f1988",
3
+ "version": "4.0.0-29112967.ebff42f8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",