-
Notifications
You must be signed in to change notification settings - Fork 403
fix: seed useUser with auth.currentUser to prevent undefined on initial render #731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ca91b31
754b9d4
93ec591
b1814a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,17 @@ export function useUser<T = unknown>(options?: ReactFireOptions<T>): ObservableS | |
| const observableId = `auth:user:${auth.name}`; | ||
| const observable$ = user(auth); | ||
|
|
||
| return useObservable(observableId, observable$, options); | ||
| const _options: ReactFireOptions<T> = { ...options }; | ||
|
|
||
| // If a user is already signed in, seed initialData so consumers see the user | ||
| // synchronously on the first render without waiting for the async observable. | ||
| // We only do this when currentUser is truthy to avoid masking the uninitialized | ||
| // (null before auth has loaded from storage) case as "signed out". | ||
| if (auth.currentUser && !('initialData' in _options) && !('startWithValue' in _options)) { | ||
| _options.initialData = auth.currentUser as unknown as T; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| return useObservable(observableId, observable$, _options); | ||
| } | ||
|
|
||
| export function useIdTokenResult(user: User, forceRefresh = false, options?: ReactFireOptions<IdTokenResult>): ObservableStatus<IdTokenResult> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider documenting the behavior change where users will see it: one JSDoc sentence on
useUser(first render issuccessfor already-signed-in users; in suspense mode, signed-in users no longer suspend) + a docs regen. The suspense change is arguably the biggest surface change and it's currently only visible by reading this code comment.