Skip to content

Fix user name pop-in by fetching /session/me in a loader#1164

Merged
david-crespo merged 1 commit into
mainfrom
prefetch-user
Sep 19, 2022
Merged

Fix user name pop-in by fetching /session/me in a loader#1164
david-crespo merged 1 commit into
mainfrom
prefetch-user

Conversation

@david-crespo

@david-crespo david-crespo commented Sep 19, 2022

Copy link
Copy Markdown
Collaborator

Look at the diff with whitespace changes hidden!

Wrap all authenticated routes in an element-less Route with a loader that prefetches /session/me. That way we don't get the user's name popping in in the header as shown below.

The loader moves the loading time to before the page has loaded. This is likely not introducing any additional delay to the pageload because it runs in parallel to any other loaders that are already running at that time.

2022-09-19-user-pop-in

@vercel

vercel Bot commented Sep 19, 2022

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
console-ui-storybook ✅ Ready (Inspect) Visit Preview Sep 19, 2022 at 8:17PM (UTC)

apiQueryClient.prefetchQuery('organizationPolicyView', requireOrgParams(params)),
// used to resolve user names
apiQueryClient.prefetchQuery('userList'),
apiQueryClient.prefetchQuery('userList', {}),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The {} is now required as a result of removing the ? from the params arg. This ensures the call matches the one it's prefetching for — if they don't match, then the call in the component will not reuse this data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant