Skip to content
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

feat(next,ui): improves loading states #6434

Merged
merged 70 commits into from
May 29, 2024
Merged

Conversation

jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented May 20, 2024

Description

Significantly improves the loading states within the Admin Panel by avoiding rendering full screen loading overlays. To do this we needed to 1. load as much on the server as possible and 2. prevent Cumulative Layout Shift while streaming in components:

  1. Determines the admin theme server-side: feat(next): server-side theme detection #6452
  2. Builds form state server-side: feat: extracts buildFormState logic from endpoint for reuse #6501
    • We now hydrate the DocumentInfoProvider from the server when navigating pages (no more calls to /api/form-state on initial page load)
    • On the client when no props are provided this component populates itself using the REST API (i.e. document drawers)
  3. Determines the publish access server-side to limit CLS: fix(next,ui): fixes global doc permissions and optimizes publish access data loading #6451
  4. Improves data loading strategies. The bullets above make it possible to stream in bits of the admin panel sooner. Since we know the schemas ahead of time, we can render fields as soon as the page is ready, even while data is still loading. To do this:
    • There is a new initializing state in the Form component
    • Fields now subscribe to this property display as read-only while the JS loads in the background (where applicable)
  5. Server-renders the dashboard view
  6. Removes form submission overlays like on the login and document edit views
  7. Other misc. changes have been made to avoid CLS such as:
  8. Other unrelated changes / fixes that made their way into this PR:
    • Properly 404s when user lacks read access on the entity, i.e. they navigate to the list or document view, they now see "not found" as opposed to "unauthorized"
    • The account view was incorrectly a part of the "auth" routes as so the redirect was failing to hit

Overall, the admin panel now feels faster with less lag. BUT in the future we really ought to:

  1. Implement an initial app loading screen. I had a POC for this, but it proved to be buggy so was removed. To achieve this we can simply wrap the JSX in the root layout with a React.Suspense, and render the loading spinner as a fallback. But Next.js was rendering this twice and causing a blink which I simply could not figure out after much trial and error.
  2. Implement a route-based loading indicator, but unfortunately this is currently not feasible in Next.js App Router. The suggested solution here: [next/navigation] Next 13: useRouter events? vercel/next.js#41934 (comment) is to wrap the Link component and tie into the useTransition API—but routing can originate from js-based events elsewhere and this pattern would not catch those events.
  3. Improve document processing loading states, maybe by tying into route-based loading indicator described above, or simply changing the button label to display "loading...".
  • I have read and understand the CONTRIBUTING.md document in this repository.

@jacobsfletch jacobsfletch changed the title poc: better loading states chore(ui): better loading states May 20, 2024
@jacobsfletch jacobsfletch changed the title chore(ui): better loading states feat(next,ui): better loading states May 20, 2024
@jacobsfletch jacobsfletch changed the title feat(next,ui): better loading states feat(next,ui): ssr theme detection and better loading states May 21, 2024
@jacobsfletch jacobsfletch changed the title feat(next,ui): ssr theme detection and better loading states feat(next,ui): better loading states May 22, 2024
@jacobsfletch jacobsfletch changed the title feat(next,ui): better loading states feat(next,ui): improves loading states May 29, 2024
@jacobsfletch jacobsfletch marked this pull request as ready for review May 29, 2024 15:46
@jacobsfletch jacobsfletch merged commit 92f458d into beta May 29, 2024
44 checks passed
@jacobsfletch jacobsfletch deleted the chore/loading-states branch May 29, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants