fix(web): faster server response + no layout shift on load and transitions - #136
Open
damianrosellen1 wants to merge 3 commits into
Open
fix(web): faster server response + no layout shift on load and transitions#136damianrosellen1 wants to merge 3 commits into
damianrosellen1 wants to merge 3 commits into
Conversation
The proxy fetched siteLanguageSettings on every page request, and with SANITY_API_READ_TOKEN set (any deploy with Visual Editing) it always used the drafts perspective against the live API — uncached, no CDN. Every cold start and every 60s TTL expiry blocked the response on that round trip; locally measured 1.0s cold / ~150ms steady-state TTFB, worse on serverless where isolates recycle constantly. - proxy: published perspective via the CDN host for regular traffic; drafts only for requests that carry the Draft Mode cookie (and in dev), fetched per request and never written to the shared cache - proxy: stale-while-revalidate with a single-flight refresh — an expired cache entry is served immediately while one background refresh runs, so only the first request of a process ever waits for Sanity - render path: fetchSiteLanguageSettings gates the drafts client on draftMode().isEnabled (or dev) instead of token presence, falling back to the existing unstable_cache'd published path; draftMode() throwing outside request scope (generateStaticParams) is treated as disabled Presentation previews of unpublished language changes keep working — draft-mode requests still resolve drafts in both proxy and render path. Side effect: sitemap.xml revalidate drops 1h -> 60s because the language settings read now participates in unstable_cache instead of bypassing Next's cache entirely. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- next/font display: block -> swap. block hid all text for up to 3s while Geist loaded; swap paints immediately in the metrics-adjusted fallback next/font generates, so the swap itself doesn't shift layout. - Thread a priority flag from ModulesRenderer (module index 0) into ModuleMedia (image / video / loop poster) and ModuleContentRefs (first card image). The first module is the LCP candidate, but every image rendered as loading=lazy with a fade-in from opacity 0 — the LCP image of a media-first page was deferred and then faded in. Priority media loads eager + fetchpriority=high and skips the fade. Rich-text-embedded media (project body) intentionally stays lazy — an image mid-text isn't reliably above the fold. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Two shifts fired on client-side navigations: - Scrollbar appear/disappear between short and scrollable pages shifted the whole layout horizontally on classic-scrollbar systems (Windows/Linux). scrollbar-gutter: stable on <html> reserves the gutter permanently. - The route-loading skeleton painted on every navigation, then got replaced by real content — a visible skeleton -> content jump even though ISR + prefetch resolve most navigations in well under 300ms. The skeleton now stays invisible for 300ms (opacity keyframe, both fill mode) so fast navigations never show it; genuinely slow loads (draft mode, cold cache) still get feedback after the delay. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ Deploy Preview for bef-next-sanity-starter ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
5 tasks
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.
Fixes the two reported performance problems: slow initial loading / server response time, and CLS on initial load and page transitions.
Problem 1 — Server response time (TTFB)
Root cause: the proxy (middleware) blocked every page request on a
siteLanguageSettingsfetch. WithSANITY_API_READ_TOKENset — i.e. on any deploy with Visual Editing — that fetch always used the drafts perspective against the live API (no CDN, no shared cache). Every cold start and every 60s TTL expiry paid a full Sanity round trip before even a fully static page could be served. The render path (fetchSiteLanguageSettings) had the same token-gated drafts fetch on every render.Fix (
97f4fe4):fetchSiteLanguageSettingsgates the drafts client ondraftMode().isEnabledinstead of token presence and otherwise uses the existingunstable_cached published path (tag-invalidated via/api/revalidate).Local
next startmeasurements (homepage, token set):The structural win matters most on serverless, where every new isolate paid the blocking fetch.
Problem 2 — CLS on initial load and transitions
Three independent causes, three fixes:
a5d9827):display: "block"hid all text for up to 3s while Geist loaded. Nowswap— text paints immediately in the metrics-adjusted fallback thatnext/fontgenerates, so the swap itself doesn't shift layout.a5d9827): every image renderedloading="lazy"+ fade-in fromopacity: 0, including the first module's media.ModulesRenderernow threadspriorityinto module index 0 (ModuleMediaimage/video/loop poster,ModuleContentRefsfirst card) → eager +fetchpriority=high, no fade. Rich-text-embedded media intentionally stays lazy (mid-text images aren't reliably above the fold).78f69f7):scrollbar-gutter: stableon<html>— the scrollbar appearing/disappearing between short and scrollable pages shifted the whole layout horizontally (Windows/Linux).Side effects / notes
sitemap.xmlrevalidate drops 1h → 60s (the language-settings read now participates inunstable_cacheinstead of bypassing Next's cache)./api/draft-mode/disableclears it.Verified
pnpm typecheck,pnpm formatclean; production build green, all routes still SSG/ISR/de200,/en→ 307/,/en/docs→ 307/docs,/de/docs200font-display: swap,scrollbar-gutter: stable, and the 300ms skeleton delay present in the built CSS🤖 Generated with Claude Code