-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): not serializing skipHydrate properties
- Loading branch information
Showing
10 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
<script lang="ts" setup> | ||
// import {useCounter }from '~/stores/counter' | ||
const counter = useCounter() | ||
useTestStore() | ||
useSomeStoreStore() | ||
// await useAsyncData('counter', () => counter.asyncIncrement().then(() => true)) | ||
if (import.meta.server) { | ||
counter.increment() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<p>Count: {{ counter.$state.count }}</p> | ||
<button @click="counter.increment()">+</button> | ||
</div> | ||
<NuxtPage /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts" setup> | ||
// import {useCounter }from '~/stores/counter' | ||
const counter = useCounter() | ||
useTestStore() | ||
useSomeStoreStore() | ||
// await useAsyncData('counter', () => counter.asyncIncrement().then(() => true)) | ||
if (import.meta.server) { | ||
counter.increment() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<p>Count: {{ counter.$state.count }}</p> | ||
<button @click="counter.increment()">+</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts" setup> | ||
const store = useWithSkipHydrateStore() | ||
</script> | ||
|
||
<template> | ||
<h2>skipHydrate() test</h2> | ||
<pre>{{ store.skipped }}</pre> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { skipHydrate } from 'pinia' | ||
|
||
export const useWithSkipHydrateStore = defineStore('with-skip-hydrate', () => { | ||
const skipped = skipHydrate( | ||
ref({ | ||
text: 'I should not be serialized or hydrated', | ||
}) | ||
) | ||
return { skipped } | ||
}) | ||
|
||
if (import.meta.hot) { | ||
import.meta.hot.accept( | ||
acceptHMRUpdate(useWithSkipHydrateStore, import.meta.hot) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
definePayloadPlugin, | ||
definePayloadReducer, | ||
definePayloadReviver, | ||
} from '#imports' | ||
import { shouldHydrate } from 'pinia' | ||
|
||
/** | ||
* Removes properties marked with `skipHydrate()` to avoid sending unused data to the client. | ||
*/ | ||
const payloadPlugin = definePayloadPlugin(() => { | ||
definePayloadReducer( | ||
'skipHydrate', | ||
(data: unknown) => !shouldHydrate(data) && undefined | ||
) | ||
definePayloadReviver('skipHydrate', (data: undefined) => data) | ||
}) | ||
|
||
export default payloadPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters