File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323import { useFirebaseApp } from '../app'
2424import {
2525 isDocumentRef ,
26+ isSSR ,
2627 noop ,
2728 OperationsType ,
2829 ResetOption ,
@@ -67,6 +68,10 @@ export function _useFirestoreRef(
6768 const options = Object . assign ( { } , firestoreOptionsDefaults , localOptions )
6869 const initialSourceValue = unref ( docOrCollectionRef )
6970
71+ if ( isSSR ( ) ) {
72+ options . once = true
73+ }
74+
7075 const data = options . target || ref < unknown | null > ( )
7176 // set the initial value from SSR even if the ref comes from outside
7277 data . value = getInitialValue ( initialSourceValue , options . ssrKey , data . value )
Original file line number Diff line number Diff line change 99 Timestamp ,
1010} from 'firebase/firestore'
1111import { StorageReference } from 'firebase/storage'
12+ import { inject , ssrContextKey } from 'vue-demi'
1213import type { Ref , ShallowRef } from 'vue-demi'
1314
1415export const noop = ( ) => { }
@@ -272,3 +273,17 @@ export type _Mutable<T> = {
272273export interface _ResolveRejectFn {
273274 ( value : unknown ) : void
274275}
276+
277+ /**
278+ * Check if we are in an SSR environment within a composable. Used to force `options.once` to `true`.
279+ *
280+ * @internal
281+ */
282+ export function isSSR ( ) : boolean {
283+ return (
284+ ! ! inject ( ssrContextKey , null ) ||
285+ //
286+ // @ts -expect-error
287+ import . meta. env ?. SSR
288+ )
289+ }
You can’t perform that action at this time.
0 commit comments