Repository navigation
perf(playground): render the language list on the server - #6
Merged
Merged
Conversation
The playground page waited for two browser requests, ListLanguages and the default language's GetTemplate, before it showed anything but a skeleton. The page is now a server component that fetches both and passes them to the client page. The header, the language select and the starter code are in the first HTML response. - One 700 ms budget covers both calls. On timeout or error the page renders without the data and the browser fetches as before. - Results are cached in memory: successes for 60 s, failures for 15 s. Concurrent renders share one request. Server requests all come from the frontend's IP, so calling the gateway on every page view would use up that IP's rate-limit bucket. - No cookies and no Origin header are sent; the gateway accepts such requests. PLAYGROUND_API_INTERNAL_URL can point the server at an internal gateway address. The default is NEXT_PUBLIC_API_URL. - The response is passed as base64 protobuf, because language limits hold 64-bit integers. - With the development fake backend the server stays out, so fake data is still used. - The CSP nonce model is unchanged. The page was already rendered per request, and Next.js adds the nonce to its own inline scripts. Production build, local gateway, median of 7 loads: LCP fell from 724 ms to 580 ms unthrottled, and from 2980 ms to 2644 ms with Fast 4G and 4x CPU throttling. The LCP element is the first editor line in both cases.
0xmhha
force-pushed
the
perf/server-language-list
branch
from
October 29, 2026 03:28
0872696 to
b794ca4
Compare
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.
Summary
The playground page now gets the language list and the default language's starter code on the server, so the first HTML already contains the header, the language select and the starter program.
ListLanguagesandGetTemplate.GetSession.LCP, production build (
next buildandnext start) against the local gateway, median of 7 fresh loadsIn both cases the LCP element is the first line of the Monaco editor. Monaco still loads from jsDelivr, which is the largest remaining cost and is the subject of a separate change.
Design
src/app/[locale]/page.tsxis now a server component. It callsloadInitialLanguages()and rendersPlaygroundClient.PlaygroundClient.tsxis the previous page, unchanged apart from passing the data touseLanguages(initial).useLanguages(initial)starts ready, withloadingfalse, the default language selected and the starter code set. It sends no request untilretry().src/lib/rpc/server.ts(the only new caller of@connectrpc, kept insidelib/rpc):AbortSignal.timeout) covers both calls. A failed template still returns the list, and the client then uses its built-in sample.rl:other:ip:*) is per IP. Calling it on every page view would drain that bucket.originGuardaccepts requests with neither, and nothing user-specific is fetched.PLAYGROUND_API_INTERNAL_URL(read at run time, documented in the README and.env.example) lets the server reach the gateway by an internal address. The default isNEXT_PUBLIC_API_URL.?fake=modes keep working.ListLanguagesResponsecrosses to the client as base64 binary protobuf (lib/rpc/initial.ts), because language limits contain 64-bit integers. Invalid or empty data falls back to the client fetch.pickDefaultLanguageanddefaultTemplateIdmoved to a React-freefeatures/editor/language-defaults.tsso the server page can use them.useLanguagesre-exports them.Testing
npx vitest run: 263 tests pass. New tests cover:ListLanguagesrejected after 20 ms;useLanguages(initial)starting ready without a request, and its built-in sample fallback.npx playwright test tests/e2e/fake: 15 tests pass.next startwith the local gateway):ListLanguagesorGetTemplaterequest;npm run typecheck: passes.npm run lint: 0 errors and 12 warnings, as on main.npm run build: passes.npm audit --audit-level=low: 0 vulnerabilities.Not verified
@stackPlaywright suite. The local backend containers were in use by other work.