File tree 3 files changed +24
-3
lines changed
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 {
61
61
// SFC CSS Modules
62
62
export { useCSSModule } from './helpers/useCssModule'
63
63
64
+ // SSR context
65
+ export { useSSRContext , ssrContextKey } from './helpers/useSsrContext'
66
+
64
67
// Internal API ----------------------------------------------------------------
65
68
66
69
// For custom renderers
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import {
11
11
ssrUtils ,
12
12
Slots ,
13
13
warn ,
14
- createApp
14
+ createApp ,
15
+ ssrContextKey
15
16
} from 'vue'
16
17
import {
17
18
ShapeFlags ,
@@ -52,8 +53,6 @@ export type PushFn = (item: SSRBufferItem) => void
52
53
53
54
export type Props = Record < string , unknown >
54
55
55
- const ssrContextKey = Symbol ( )
56
-
57
56
export type SSRContext = {
58
57
[ key : string ] : any
59
58
portals ?: Record < string , string >
You can’t perform that action at this time.
0 commit comments