Skip to content

Load home highlights behind the loading screen - #576

Merged
karanshukla merged 1 commit into
mainfrom
perf/home-cls
Nov 26, 2026
Merged

karanshukla merged 1 commit into
mainfrom
perf/home-cls

Conversation

@karanshukla

Copy link
Copy Markdown
Owner

Summary

The home page fetched its highlights alongside the restaurant list and only rendered the section once they arrived. The location skeletons were already on screen, so they jumped about 300 px down when the highlights landed: CLS 0.226 in Lighthouse, 0.275 in a throttled Moto G4 trace, all from that one shift.

Reserving skeleton space for the highlights fixes it for a restaurant that has them (0.005) and breaks one that doesn't, which then jumps the other way (0.258 mobile, 0.134 desktop). The page has to know before it renders, so BrandProvider now fetches the highlights in parallel with the brand, behind the loading screen it already shows, and hands them out through useHighlights.

Follow-up to #574 and #575.

Related issue

None.

Scope

  • API (OpenRestoApi)
  • Frontend (openresto-frontend)
  • Database migration
  • Docs / infra

Changes

  • Home only loads restaurants itself. Pull-to-refresh on native no longer refetches highlights; it still reloads the list and each card's availability.
  • fetchHighlights moves to its own api/highlights.ts (home was its only caller). jest.setup.ts mocks it to [], because a real call from the provider took a response other suites had queued on fetch for their own requests (222 failures across 9 suites before this).
  • Every page now fetches the highlights list, admin included. It is small and runs in parallel with /api/brand, so it adds no round trip.

CLS from a layout-shift trace (throttled Moto G4, 4x CPU, and a 1350x940 desktop):

Before Skeleton only (not shipped) This PR
With highlights, mobile 0.275 0.005 0.000
With highlights, desktop 0.006 0.000
No highlights, mobile 0.258 0.000
No highlights, desktop 0.134 0.037

The 0.037 left on desktop with no highlights is the footer moving as location skeletons turn into slightly taller cards. Same on main, under 0.1.

Lighthouse 13.6.0, mobile preset, median of 3, against main after #575:

Home before Home after
Score 43 53
CLS 0.226 0
LCP 6.1 s 6.2 s
TBT 1.07 s 1.21 s
Transferred 769 KB 769 KB

No JS was added, so the TBT difference is run-to-run variance.

Testing

  • OpenRestoApi.Tests pass locally (no API changes)
  • Frontend tests/build pass locally: npm run check, tsc --noEmit, check:doc-links, npm test and npm run test:android (4161 tests each), expo export --platform web
  • CI passes (build, migration-check)
  • Manually verified the change end-to-end: layout-shift traces above, against the seeded demo with its 5 highlights and with the table emptied.

Migrations

  • This PR includes a database migration
  • Migration was tested locally (up and, if applicable, down)

Checklist

  • No secrets, connection strings, or credentials committed
  • Docs updated if API contracts or setup changed

The home page fetched its highlights alongside the restaurant list and only
rendered the section once they arrived, so the location skeletons already on
screen jumped about 300px down when they landed (CLS 0.226 on mobile). Reserving
skeleton space instead would make a restaurant without highlights jump the other
way, so the page has to know before it renders.

BrandProvider now fetches the highlights in parallel with the brand, behind the
loading screen it already shows, and hands them out through useHighlights. The
home screen only loads restaurants itself, and pull-to-refresh no longer
refetches highlights. fetchHighlights moves to its own api/highlights.ts, which
jest.setup mocks so suites that queue fetch responses are not handed an extra
request.
@karanshukla
karanshukla merged commit 1d17608 into main Nov 26, 2026
24 checks passed
@karanshukla
karanshukla deleted the perf/home-cls branch November 26, 2026 16:32
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