@nuxt/docs-nightly 5.0.0-29548883.c6ed8076 → 5.0.0-29550727.fea006dd
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.
|
@@ -362,12 +362,12 @@ The options object accepts `@testing-library/vue` render options and the followi
|
|
|
362
362
|
|
|
363
363
|
#### `mockNuxtImport`
|
|
364
364
|
|
|
365
|
-
`mockNuxtImport` allows you to mock Nuxt's auto import functionality. For example, to mock `
|
|
365
|
+
`mockNuxtImport` allows you to mock Nuxt's auto import functionality. For example, to mock `useState`, you can do so like this:
|
|
366
366
|
|
|
367
367
|
```ts twoslash
|
|
368
368
|
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
|
|
369
369
|
|
|
370
|
-
mockNuxtImport('
|
|
370
|
+
mockNuxtImport('useState', () => {
|
|
371
371
|
return () => {
|
|
372
372
|
return { value: 'mocked storage' }
|
|
373
373
|
}
|
|
@@ -378,19 +378,19 @@ mockNuxtImport('useStorage', () => {
|
|
|
378
378
|
|
|
379
379
|
You can explicitly type the mock for type safety, and use the original implementation passed to the factory function when mocking complex functionality.
|
|
380
380
|
|
|
381
|
-
```ts twoslash
|
|
381
|
+
```ts twoslash [test/nuxt/import.test.ts]
|
|
382
382
|
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
|
|
383
383
|
|
|
384
|
-
mockNuxtImport<typeof
|
|
384
|
+
mockNuxtImport<typeof useState>('useState', (original) => {
|
|
385
385
|
return (...args) => {
|
|
386
|
-
return { ...original(
|
|
386
|
+
return { ...original('some-key'), value: 'mocked state' }
|
|
387
387
|
}
|
|
388
388
|
})
|
|
389
389
|
|
|
390
390
|
// or specify the target to mock
|
|
391
|
-
mockNuxtImport(
|
|
391
|
+
mockNuxtImport(useState, (original) => {
|
|
392
392
|
return (...args) => {
|
|
393
|
-
return { ...original(
|
|
393
|
+
return { ...original('some-key'), value: 'mocked state' }
|
|
394
394
|
}
|
|
395
395
|
})
|
|
396
396
|
|
|
@@ -407,20 +407,20 @@ If you need to mock a Nuxt import and provide different implementations between
|
|
|
407
407
|
import { vi } from 'vitest'
|
|
408
408
|
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
|
|
409
409
|
|
|
410
|
-
const {
|
|
410
|
+
const { useStateMock } = vi.hoisted(() => {
|
|
411
411
|
return {
|
|
412
|
-
|
|
412
|
+
useStateMock: vi.fn(() => {
|
|
413
413
|
return { value: 'mocked storage' }
|
|
414
414
|
}),
|
|
415
415
|
}
|
|
416
416
|
})
|
|
417
417
|
|
|
418
|
-
mockNuxtImport('
|
|
419
|
-
return
|
|
418
|
+
mockNuxtImport('useState', () => {
|
|
419
|
+
return useStateMock
|
|
420
420
|
})
|
|
421
421
|
|
|
422
422
|
// Then, inside a test
|
|
423
|
-
|
|
423
|
+
useStateMock.mockImplementation(() => {
|
|
424
424
|
return { value: 'something else' }
|
|
425
425
|
})
|
|
426
426
|
```
|
|
@@ -544,7 +544,7 @@ If you would like to use both the end-to-end and unit testing functionality of `
|
|
|
544
544
|
```ts twoslash
|
|
545
545
|
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
|
|
546
546
|
|
|
547
|
-
mockNuxtImport('
|
|
547
|
+
mockNuxtImport('useState', () => {
|
|
548
548
|
return () => {
|
|
549
549
|
return { value: 'mocked storage' }
|
|
550
550
|
}
|
|
@@ -122,7 +122,7 @@ File | Layout Name
|
|
|
122
122
|
|
|
123
123
|
You can also use the [`setPageLayout`](/docs/4.x/api/utils/set-page-layout) helper to change the layout dynamically:
|
|
124
124
|
|
|
125
|
-
```vue twoslash
|
|
125
|
+
```vue twoslash [app/pages/index.vue]
|
|
126
126
|
<script setup lang="ts">
|
|
127
127
|
declare module 'nuxt/app' {
|
|
128
128
|
interface NuxtLayouts {
|
|
@@ -6,32 +6,32 @@ description: Why fixing hydration issues is important
|
|
|
6
6
|
|
|
7
7
|
When developing, you may face hydration issues. Don't ignore those warnings.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Why is it important to fix them?
|
|
10
10
|
|
|
11
11
|
Hydration mismatches are not just warnings - they are indicators of serious problems that can break your application:
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Performance Impact
|
|
14
14
|
|
|
15
15
|
- **Increased time to interactive**: Hydration errors force Vue to re-render the entire component tree, which will increase the time for your Nuxt app to become interactive
|
|
16
16
|
- **Poor user experience**: Users may see content flashing or unexpected layout shifts
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
### Functionality Issues
|
|
19
19
|
|
|
20
20
|
- **Broken interactivity**: Event listeners may not attach properly, leaving buttons and forms non-functional
|
|
21
21
|
- **State inconsistencies**: Application state can become out of sync between what the user sees and what the application thinks is rendered
|
|
22
22
|
- **SEO problems**: Search engines may index different content than what users actually see
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## How to detect them
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
### Development Console Warnings
|
|
27
27
|
|
|
28
28
|
Vue will log hydration mismatch warnings in the browser console during development:
|
|
29
29
|
|
|
30
30
|

|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
## Common reasons
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
### Browser-only APIs in Server Context
|
|
35
35
|
|
|
36
36
|
**Problem**: Using browser-specific APIs during server-side rendering.
|
|
37
37
|
|
|
@@ -60,7 +60,7 @@ const userTheme = useCookie('theme', { default: () => 'light' })
|
|
|
60
60
|
</script>
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
### Inconsistent Data
|
|
64
64
|
|
|
65
65
|
**Problem**: Different data between server and client.
|
|
66
66
|
|
|
@@ -82,7 +82,7 @@ const state = useState('random', () => Math.random())
|
|
|
82
82
|
</script>
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
### Conditional Rendering Based on Client State
|
|
86
86
|
|
|
87
87
|
**Problem**: Using client-only conditions during SSR.
|
|
88
88
|
|
|
@@ -105,7 +105,7 @@ const state = useState('random', () => Math.random())
|
|
|
105
105
|
</template>
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
### Third-party Libraries with Side Effects
|
|
109
109
|
|
|
110
110
|
**Problem**: Libraries that modify the DOM or have browser dependencies (this happens a LOT with tag managers).
|
|
111
111
|
|
|
@@ -129,7 +129,7 @@ onMounted(async () => {
|
|
|
129
129
|
</script>
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
### Dynamic Content Based on Time
|
|
133
133
|
|
|
134
134
|
**Problem**: Content that changes based on current time.
|
|
135
135
|
|