Repository navigation
Faster first loads: static public pages, data with the page, Ask on demand - #1
Merged
Merged
Conversation
The panel imports the markdown renderer, KaTeX and highlight.js, and it sat in the providers every page loads, so even the sign-in form downloaded them. It now loads the first time Ask opens.
The root layout read the session, which made every page render per request: a visitor's first load waited on a function, cold start included. The routes now sit in two groups. (public) holds the landing page, sign-in, sign-up, shared pages and the consent screen, and reads no session, so the landing page, sign-in and sign-up are prerendered. (app) holds the notebook, and its layout reads the session for the spine. / is the contents when signed in and the landing page otherwise. A rewrite in next.config.ts decides on the session cookie before any page runs, so that costs no function either; a stale cookie reaches the contents page and is sent to sign-in. The chromeless route list is gone: the notebook's frame only exists in (app). On the server, React Query now gets a new client per render instead of one shared module-level client.
Pages rendered empty, hydrated, then fetched their data: the spine's four lists and the page's own, each its own request and function after the JavaScript had run. The server now runs the same loaders while rendering and hands the results to React Query (prefetch and HydrationBoundary), so a page arrives with its data and the hooks find it already cached. The notebook layout sends the spine's lists once per load; each page sends its own. The routes' data logic moved into lib functions that the routes and the prefetch both call, and the query keys they share live in lib/query-keys.ts, so the two can't drift. Today and due revisions are keyed by the user's local date: the browser keeps its time zone in the lk-tz cookie and the server works out the same day (lib/zone.ts). Without the cookie, the browser fetches those two as before. Sign-in now ends in a full page load. The router on the sign-in page learned / while signed out, and / is a different page once the session cookie is set.
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Measured on production (functions now in Mumbai, next to the database):
Changes:
(public)(landing, sign-in, sign-up, share, consent) and(app)(the notebook). Only(app)reads the session. A rewrite innext.config.tssends/to the contents when the session cookie is present, so the landing page needs no function either. Sign-in now ends in a full page load into the notebook.lk-tzcookie.Checked locally under
next start:/,/loginand/signupbuild as static.?next=, sign-out and a stale cookie.