Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use initialQuery, add back meta tag for initial load of users
  • Loading branch information
Kira-Pilot committed Oct 19, 2023
commit 9f459d9fceddaeb3a6e38b4a8715136bad78d821
1 change: 1 addition & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<meta property="og:type" content="website" />
<meta property="csrf-token" content="{{ .CSRF.Token }}" />
<meta property="build-info" content="{{ .BuildInfo }}" />
<meta property="user" content="{{ .User }}" />
<meta property="entitlements" content="{{ .Entitlements }}" />
<meta property="appearance" content="{{ .Appearance }}" />
<meta property="experiments" content="{{ .Experiments }}" />
Expand Down
5 changes: 4 additions & 1 deletion site/src/api/queries/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
UpdateUserPasswordRequest,
UpdateUserProfileRequest,
UsersRequest,
User,
} from "api/typesGenerated";
import { getAuthorizationKey } from "./authCheck";
import { getMetadataAsJSON } from "utils/metadata";

export const users = (req: UsersRequest): UseQueryOptions<GetUsersResponse> => {
return {
Expand Down Expand Up @@ -90,7 +92,8 @@ export const authMethods = () => {
export const me = () => {
return {
queryKey: ["me"],
queryFn: async () => API.getAuthenticatedUser(),
initialData: getMetadataAsJSON<User>("user"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with this approach is that getMetadataAsJSON will get recalculated every single render, even though the value is basically a constant embedded in the HTML

This should be safe to extract outside the function

queryFn: API.getAuthenticatedUser,
};
};

Expand Down