File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1+ import { inject } from '../apiInject'
2+ import { warn } from '../warning'
3+
4+ export const ssrContextKey = Symbol ( __DEV__ ? `ssrContext` : `` )
5+
6+ export const useSSRContext = < T = Record < string , any > > ( ) => {
7+ if ( ! __GLOBAL__ ) {
8+ const ctx = inject < T > ( ssrContextKey )
9+ if ( ! ctx ) {
10+ warn (
11+ `Server rendering context not provided. Make sure to only call ` +
12+ `useSsrContext() conditionally in the server build.`
13+ )
14+ }
15+ return ctx
16+ } else if ( __DEV__ ) {
17+ warn ( `useSsrContext() is not supported in the global build.` )
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ export {
6161// SFC CSS Modules
6262export { useCSSModule } from './helpers/useCssModule'
6363
64+ // SSR context
65+ export { useSSRContext , ssrContextKey } from './helpers/useSsrContext'
66+
6467// Internal API ----------------------------------------------------------------
6568
6669// For custom renderers
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import {
1111 ssrUtils ,
1212 Slots ,
1313 warn ,
14- createApp
14+ createApp ,
15+ ssrContextKey
1516} from 'vue'
1617import {
1718 ShapeFlags ,
@@ -52,8 +53,6 @@ export type PushFn = (item: SSRBufferItem) => void
5253
5354export type Props = Record < string , unknown >
5455
55- const ssrContextKey = Symbol ( )
56-
5756export type SSRContext = {
5857 [ key : string ] : any
5958 portals ?: Record < string , string >
You can’t perform that action at this time.
0 commit comments