reactfire 4.2.2 → 4.2.3-exp.4329c43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { SuspenseSubject } from './SuspenseSubject';
3
3
  import { ReactFireOptions } from './';
4
- export declare function preloadObservable<T>(source: Observable<T>, id: string): SuspenseSubject<T>;
4
+ export declare function preloadObservable<T>(source: Observable<T>, id: string, suspenseEnabled?: boolean): SuspenseSubject<T>;
5
5
  export interface ObservableStatus<T> {
6
6
  /**
7
7
  * The loading status.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.2.2",
2
+ "version": "4.2.3-exp.4329c43",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
@@ -36,7 +36,7 @@
36
36
  "docs:fork": "typedoc --options typedoc.json --gitRemote upstream && markdown-toc -i docs/use.md"
37
37
  },
38
38
  "peerDependencies": {
39
- "firebase": "^9.0.0",
39
+ "firebase": "^9.0.0 || >=9.11.0-20220929164943 || next",
40
40
  "react": ">=16 || experimental"
41
41
  },
42
42
  "husky": {
@@ -15,7 +15,7 @@ export class SuspenseSubject<T> extends Subject<T> {
15
15
  // @ts-expect-error: TODO: double check to see if this is an RXJS thing or if we should listen to TS
16
16
  private _resolveFirstEmission: () => void;
17
17
 
18
- constructor(innerObservable: Observable<T>, private _timeoutWindow: number) {
18
+ constructor(innerObservable: Observable<T>, private _timeoutWindow: number, private _suspenseEnabled: boolean) {
19
19
  super();
20
20
  this._firstEmission = new Promise<void>((resolve) => (this._resolveFirstEmission = resolve));
21
21
  this._innerObservable = innerObservable.pipe(
@@ -38,7 +38,13 @@ export class SuspenseSubject<T> extends Subject<T> {
38
38
 
39
39
  // set a timeout for resetting the cache, subscriptions will cancel the timeout
40
40
  // and reschedule again on unsubscribe
41
- this._timeoutHandler = setTimeout(this._reset.bind(this), this._timeoutWindow);
41
+ if (this._suspenseEnabled) {
42
+ // Noop if suspense is enabled
43
+ console.log('SuspenseSubject: Suspense is enabled');
44
+ this._timeoutHandler = setTimeout(() => {}, this._timeoutWindow);
45
+ } else {
46
+ this._timeoutHandler = setTimeout(this._reset.bind(this), this._timeoutWindow);
47
+ }
42
48
  }
43
49
 
44
50
  get hasValue(): boolean {
package/src/auth.tsx CHANGED
@@ -24,15 +24,8 @@ export function useUser<T = unknown>(options?: ReactFireOptions<T>): ObservableS
24
24
 
25
25
  const observableId = `auth:user:${auth.name}`;
26
26
  const observable$ = user(auth);
27
- const _options: ReactFireOptions<T> = { ...options } ?? {};
28
27
 
29
- // only set/override initialData if auth has finished loading
30
- if (auth.currentUser !== undefined) {
31
- _options.initialData = auth.currentUser;
32
- _options.startWithValue = auth.currentUser;
33
- }
34
-
35
- return useObservable(observableId, observable$, _options);
28
+ return useObservable(observableId, observable$, options);
36
29
  }
37
30
 
38
31
  export function useIdTokenResult(user: User, forceRefresh: boolean = false, options?: ReactFireOptions<IdTokenResult>): ObservableStatus<IdTokenResult> {
@@ -117,15 +110,15 @@ export interface SignInCheckOptionsClaimsValidator extends SignInCheckOptionsBas
117
110
  *
118
111
  * ```ts
119
112
  * // pass in an object describing the custom claims a user must have
120
- * const {status, data: signInCheckResult} = useSignInCheck({requiredClaims: {admin: true}});
113
+ * const {status, data: signInCheckResult} = useSigninCheck({requiredClaims: {admin: true}});
121
114
  *
122
115
  * // pass in a custom claims validator function
123
- * const {status, data: signInCheckResult} = useSignInCheck({validateCustomClaims: (userClaims) => {
116
+ * const {status, data: signInCheckResult} = useSigninCheck({validateCustomClaims: (userClaims) => {
124
117
  * // custom validation logic...
125
118
  * }});
126
119
  *
127
120
  * // You can optionally force-refresh the token
128
- * const {status, data: signInCheckResult} = useSignInCheck({forceRefresh: true, requiredClaims: {admin: true}});
121
+ * const {status, data: signInCheckResult} = useSigninCheck({forceRefresh: true, requiredClaims: {admin: true}});
129
122
  * ```
130
123
  */
131
124
  export function useSigninCheck(
@@ -180,7 +173,7 @@ export function useSigninCheck(
180
173
  })
181
174
  );
182
175
 
183
- return useObservable(observableId, observable);
176
+ return useObservable(observableId, observable, options);
184
177
  }
185
178
 
186
179
  function getClaimsObjectValidator(requiredClaims: Claims): ClaimsValidator {
@@ -201,7 +194,7 @@ function getClaimsObjectValidator(requiredClaims: Claims): ClaimsValidator {
201
194
  }
202
195
 
203
196
  /**
204
- * @deprecated Use `useSignInCheck` instead
197
+ * @deprecated Use `useSigninCheck` instead
205
198
  *
206
199
  * Conditionally render children based on [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims).
207
200
  *
@@ -238,7 +231,7 @@ export function ClaimsCheck({ user, fallback, children, requiredClaims }: Claims
238
231
  }
239
232
 
240
233
  /**
241
- * @deprecated Use `useSignInCheck` instead
234
+ * @deprecated Use `useSigninCheck` instead
242
235
  *
243
236
  * Conditionally render children based on signed-in status and [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims).
244
237
  *
package/src/firestore.tsx CHANGED
@@ -35,7 +35,7 @@ function getDocObservableId(ref: DocumentReference) {
35
35
  }
36
36
 
37
37
  /**
38
- * Suscribe to Firestore Document changes
38
+ * Subscribe to Firestore Document changes
39
39
  *
40
40
  * You can preload data for this hook by calling `preloadFirestoreDoc`
41
41
  */
@@ -57,7 +57,7 @@ export function useFirestoreDocOnce<T = DocumentData>(ref: DocumentReference<T>,
57
57
  }
58
58
 
59
59
  /**
60
- * Suscribe to Firestore Document changes and unwrap the document into a plain object
60
+ * Subscribe to Firestore Document changes and unwrap the document into a plain object
61
61
  */
62
62
  export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T> {
63
63
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
@@ -16,11 +16,11 @@ if (!(globalThis as any as ReactFireGlobals)._reactFirePreloadedObservables) {
16
16
  // Starts listening to an Observable.
17
17
  // Call this once you know you're going to render a
18
18
  // child that will consume the observable
19
- export function preloadObservable<T>(source: Observable<T>, id: string) {
19
+ export function preloadObservable<T>(source: Observable<T>, id: string, suspenseEnabled = false) {
20
20
  if (preloadedObservables.has(id)) {
21
21
  return preloadedObservables.get(id) as SuspenseSubject<T>;
22
22
  } else {
23
- const observable = new SuspenseSubject(source, DEFAULT_TIMEOUT);
23
+ const observable = new SuspenseSubject(source, DEFAULT_TIMEOUT, suspenseEnabled);
24
24
  preloadedObservables.set(id, observable);
25
25
  return observable;
26
26
  }
@@ -97,12 +97,13 @@ export function useObservable<T = unknown>(observableId: string, source: Observa
97
97
  if (!observableId) {
98
98
  throw new Error('cannot call useObservable without an observableId');
99
99
  }
100
- const observable = preloadObservable(source, observableId);
100
+ const suspenseEnabled = useSuspenseEnabledFromConfigAndContext(config.suspense);
101
+
102
+ const observable = preloadObservable(source, observableId, suspenseEnabled);
101
103
 
102
104
  // Suspend if suspense is enabled and no initial data exists
103
105
  const hasInitialData = config.hasOwnProperty('initialData') || config.hasOwnProperty('startWithValue');
104
106
  const hasData = observable.hasValue || hasInitialData;
105
- const suspenseEnabled = useSuspenseEnabledFromConfigAndContext(config.suspense);
106
107
  if (suspenseEnabled === true && !hasData) {
107
108
  throw observable.firstEmission;
108
109
  }