feat: new setting +vue (vue.keepAlive, fix vikejs/vike#3433) - #236
Merged
Conversation
New cumulative setting `+vue` for Vue integration options — the Vue counterpart of vike-react's `+react` setting (https://vike.dev/react-setting). First supported option: `vue.keepAlive` (`boolean | KeepAliveProps`) preserves page component instances (and thus their state) across client-side navigation, by wrapping the <Page> component with Vue's built-in <KeepAlive> component. Wrapping <slot/> with <KeepAlive> inside a +Layout component cannot work: <KeepAlive> only caches its direct child component, whereas slot content is rendered as a Fragment which <KeepAlive> cannot cache. Thus vike-vue applies <KeepAlive> where it works: directly around the routed <Page> component. Usage: // pages/+vue.ts export default { keepAlive: true, // or KeepAliveProps, e.g. { max: 10 } } satisfies Config['vue'] The +vue setting is cumulative and can also be a function of pageContext; more specific values override less specific ones. See https://github.com/orgs/vikejs/discussions/3433 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MU13ncNmLi5rz2xySmm5rZ
brillout
force-pushed
the
claude/github-discussion-link-np303g
branch
from
July 7, 2026 08:04
7dda4cd to
89e518d
Compare
+keepAlive+vue (vue.keepAlive)
+vue (vue.keepAlive)+vue (vue.keepAlive, fix vikejs/vike#3433)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
New cumulative setting
+vuefor Vue integration options — the Vue counterpart of vike-react's+reactsetting.Its first option is
vue.keepAlive(boolean | KeepAliveProps): it preserves page component instances — and thus their state — across client-side navigation, by wrapping the<Page>component with Vue's built-in<KeepAlive>component.Fixes the use case raised in https://github.com/orgs/vikejs/discussions/3433.
Why the runtime (and not userland)?
Wrapping
<slot />with<KeepAlive>inside a+Layout(or a hypothetical+Wrapper) component cannot work:<KeepAlive>only caches its direct child component, whereas slot content is rendered as a Fragment which<KeepAlive>cannot cache. So the only place<KeepAlive>can be applied is wherevike-vuerenders the routed<Page>component — i.e. increateVueApp().Usage
The setting is cumulative and can also be a function of
pageContext(like+react); more specific values override less specific ones.Changes
types/Config.ts: newvuesetting type (VueSetting | ((pageContext) => VueSetting | undefined)) withkeepAlive?: boolean | KeepAliveProps.+config.ts: register thevuesetting (env: { server: true, client: true },cumulative: true).integration/resolveVueSetting.ts: merge the cumulative values (vike orders them most-specific first, so we merge in reverse for correct precedence) and call function values withpageContext.createVueApp.ts: conditionally wrap the routed<Page>component with<KeepAlive>(reactive across navigation, likeLayout).<KeepAlive>is SSR-compatible — on the server it simply renders its child.examples/full: new/keep-alive/first+/keep-alive/secondpages with a shared+vue.ts(keepAlive: true), and an e2e test asserting that a counter's state survives a round-trip client-side navigation.Testing
pnpm run build✅pnpm exec test-e2e examples/full✅ (dev + preview, including the new keepAlive test)pnpm run test:types✅pnpm run format:check✅Documentation PR: vikejs/vike#3434 (docs for
https://vike.dev/vue-setting)🤖 Generated with Claude Code
https://claude.ai/code/session_01MU13ncNmLi5rz2xySmm5rZ