-
Notifications
You must be signed in to change notification settings - Fork 18
Page loading skeleton #2754
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
Merged
Merged
Page loading skeleton #2754
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| import { useLocation } from 'react-router' | ||
|
|
||
| import { PageContainer } from '~/layouts/helpers' | ||
| import { classed } from '~/util/classed' | ||
|
|
||
| import { MswBanner } from './MswBanner' | ||
|
|
||
| const Block = classed.div`motion-safe:animate-pulse2 rounded bg-tertiary` | ||
|
|
||
| export function PageSkeleton({ skipPaths }: { skipPaths?: RegExp[] }) { | ||
| const { pathname } = useLocation() | ||
|
|
||
| // HACK: we can only hang a HydrateFallback off the root route/layout, so in | ||
| // order to avoid rendering this skeleton on pages that don't have this grid | ||
| // layout, all we can do is match the path | ||
| if (skipPaths?.some((regex) => regex.test(pathname))) return null | ||
|
|
||
| // we need the msw banner here so it doesn't pop in on load | ||
| return ( | ||
| <> | ||
| {process.env.MSW_BANNER ? <MswBanner disableButton /> : null} | ||
| <PageContainer> | ||
| <div className="flex items-center gap-2 border-b border-r p-3 border-secondary"> | ||
| <Block className="h-8 w-8" /> | ||
| <Block className="h-4 w-24" /> | ||
| </div> | ||
| <div className="flex items-center justify-between gap-2 border-b p-3 border-secondary"> | ||
| <Block className="h-4 w-24" /> | ||
| <div className="flex items-center gap-2"> | ||
| <Block className="h-6 w-16" /> | ||
| <Block className="h-6 w-32" /> | ||
| </div> | ||
| </div> | ||
| <div className="border-r p-4 border-secondary"> | ||
| <Block className="mb-10 h-4 w-full" /> | ||
| <div className="mb-6 space-y-2"> | ||
| <Block className="h-4 w-32" /> | ||
| <Block className="h-4 w-24" /> | ||
| </div> | ||
| <div className="space-y-2"> | ||
| <Block className="h-4 w-14" /> | ||
| <Block className="h-4 w-32" /> | ||
| <Block className="h-4 w-24" /> | ||
| <Block className="h-4 w-14" /> | ||
| </div> | ||
| </div> | ||
| <div className="" /> | ||
| </PageContainer> | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Without this, when loading the root (an extremely common thing to do) you'd see the skeleton flash and then it would go blank wile the loaders for the next route load. I think doing it this way is fine as long we never link to
/, which we don't. We'll have to see if there's any weird behavior, though. I think another workaround would be to leave the element thing in place and give this route a loader that just calls the loader from the projects page, that way the loading time is spent with the fallback up.