Skip to content

🤖 perf: add the static first-run view's early script as a server constant (T3 C step 2 PR 4a) - #6486

Merged
ThomasK33 merged 5 commits into
mainfrom
perf/t3-c2-pr4a-early-script
Oct 14, 2026
Merged

ThomasK33 merged 5 commits into
mainfrom
perf/t3-c2-pr4a-early-script

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds FIRST_RUN_EARLY_SCRIPT and FIRST_RUN_TEMPLATE_ID to src/node/orpc/firstRunView.ts: the inline script that will decide on the served / whether the static first-run view shows, and that loads the app after the view paints. Nothing serves it in this PR. PR 4b injects it, together with the template, the module list and the redirect.

Background

Option C step 2 of #5971 (plan section 5.6, PR 4a). #6444 added the view's markup, and #6445 defined the deferred module list (<script type="application/json" id="xum-pre-modules">) that this script loads the app from.

Implementation

The script, in order:

  1. Slashless URL: the redirect script navigates the page away, so the early script does nothing.
  2. Paint-cache key set (onboardingWizardViewed is "true") or hidden tab: load the app at once, with no API call and no view.
  3. Otherwise: POST api/splashScreens/getViewedSplashScreens and api/providers/getConfig together, with Authorization: Bearer from the trimmed ?token=, or else the stored mux:auth-token (as ManagedAPIProvider picks it). One AbortController aborts both after 1,000 ms, and that is the script's only timer.
  4. Failure, 401 or abort: load the app with no view, as today. With a 401 the app shows its token prompt.
  5. Show rule: the wizard is not in the viewed list, no provider has isConfigured === true, and mux-gateway.couponCodeSet is not true.
  6. Show: clone the view from <template id="xum-pre-template"> (waiting for DOMContentLoaded if the template is not parsed yet), then load the app two requestAnimationFrames later. If the tab turns hidden first, it loads the app at once, and it never inserts the view after the app has loaded.

"Load the app" runs once. It validates the list (a missing or malformed list removes the view and logs, because there is no app to load), then adds the list's modulepreload links at once, and the module script (both with crossorigin) once the HTML is parsed: a dynamic module runs as soon as it loads, unlike the deferred tag it replaces, and main.tsx needs #root. The module script's error event removes #xum-pre.

The script has no request or user data in it, and it inserts the view from a template clone, never as HTML. PR 4b must place the module list before the script, because steps 2 and 4 load the app while the <head> is still parsing.

Validation

Tests (first commit, src/node/orpc/firstRunView.test.ts, 15 tests now) run the shipped script string in happy-dom with a fake fetch, timers and frames. I applied each mutation in a scratch edit, saw the named test fail, and restored the file:

Test Mutations it catches
shows the view, starts both POSTs together, and loads the app two frames later one frame instead of two; POSTs one after the other; no bearer header; the stored token before ?token=; an extra setTimeout(loadApp, 5000) safety timer
sends the stored token when the URL has none no bearer header
no view, app at once when: the wizard was viewed / a provider is configured / a gateway coupon is set / a POST returns 401 / a POST fails / the POSTs take over 1,000 ms each check removed (viewed, provider, coupon, r.ok); the abort removed; the catch removed
no API call, app at once when: the paint-cache key is set / the tab is hidden each check removed
loads the app at once when the tab turns hidden while the view waits for its frames no visibilitychange listener
removes the view when the app's module script fails to load no error listener
waits for DOMContentLoaded when the POSTs answer before the template is parsed no readyState wait
does nothing on a slashless URL no slashless check
drops the view when the module list is unusable (round-1 fix) the unguarded JSON.parse of the list
(the DOMContentLoaded test also runs with ?token=%20 and a stored token) the stored token not sent when the URL has none; an untrimmed URL token (round-2 fix)
adds the app's module script only once the HTML is parsed (round-2 fix) the module script added while readyState is loading

The tests fail on main because the two exports do not exist yet.

Gates on the perf host (files in /home/coder/perf-runs/t3/c2-pr4a-gates/):

Gate Result
src/node/orpc/firstRunView.test.ts 15 pass, 0 fail
make check-react-compiler 23/24 hot components compile (1 known skipped)
make crap-check PASS, 0 violations, 0 warnings
make static-check Formatting and all three tsgo projects pass. The full ESLint run was OOM-killed on the shared host (cgroup full). ESLint on the two changed files passes, and CI's Static Checks covers the final head
make first-load-js, normal builds of base b20d868fcf and head 466,417 vs 466,279 B .br (-138 B, version-stamp noise: chunk names differ)
make first-load-js, head built with base's src/version.ts pinned 466,417 B, and the report is byte-identical to base's. Full dist/ sha256: only node/orpc/firstRunView.js and .js.map differ

Deferred to PR 4b

  • ONBOARDING_WIZARD_SPLASH_ID is a literal in the script (Codex round 1). This PR may touch only firstRunView.ts and its test. PR 4b moves the splash id to src/common/constants/ together with the module-list id (xum-pre-modules, a local constant here).
  • Known limit (Codex round 1): in a split-origin build (VITE_BACKEND_URL), the script asks the serving xum server, not the configured backend. A wrong "no" keeps today's load. A wrong "yes" shows the view until PR 1's handoff removes it.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $346.60

… PR 4a)

The early script (plan section 5.6) decides on "/" whether the static first-run view shows, and
loads the app after it paints. These tests run the script string in happy-dom with a fake fetch,
timers and frames: the shown path (both POSTs at once, bearer token, app two frames after the
view, the 1 s abort as the only timer), every early-script row of the removal table, the
paint-cache and hidden-tab skips with zero API calls, a tab hidden while the view waits, a failed
module script, and the slashless no-op. They fail on main because firstRunView.ts has no
FIRST_RUN_EARLY_SCRIPT and FIRST_RUN_TEMPLATE_ID yet.

anthropic:claude-opus-5-5 high 346.60
…tant (T3 C step 2 PR 4a)

FIRST_RUN_EARLY_SCRIPT in src/node/orpc/firstRunView.ts is the inline script PR 4b will put on
the served "/" (plan section 5.6). Nothing serves it yet.

With the paint-cache key set or a hidden tab it loads the app at once, with no API call. Else it
POSTs the viewed splash list and the provider config together (URL or stored token, bearer),
with one 1,000 ms abort, its only timer. A failure, a 401 or the abort loads the app with no
view. When the wizard will open on its gateway step (not viewed, no configured provider, no
gateway coupon), it clones the view from its <template> (waiting for DOMContentLoaded when the
template is not parsed yet) and loads the app two frames later, or at once when the tab turns
hidden. A module script that fails to load removes the view. The app is loaded once, from the
#xum-pre-modules list that scripts/perf/firstLoadJs.ts also reads.

The test file's element checks now compare to null in a boolean: a failing expect on an element
dumped enough output to time out the run. A new test covers the DOMContentLoaded wait.

anthropic:claude-opus-5-5 high 346.60
make static-check failed on the new test file: happy-dom's Event is not the DOM's Event for the
Document-typed nodes (TS2769), the Function call was untyped (no-unsafe-call), and Array.fill
gave any[]. The harness now types the script function, builds events through one cast, and
narrows the window with a local.

anthropic:claude-opus-5-5 high 346.60
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T09:03:02.829913Z 448145e New commits
🔒 Security Review ✅ Completed 2026-10-14T09:02:12.556147Z 448145e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef8bc9fc2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/orpc/firstRunView.ts Outdated
Comment thread src/node/orpc/firstRunView.ts
Comment thread src/node/orpc/firstRunView.ts
Comment thread src/node/orpc/firstRunView.ts
…a review)

Codex round 1 on #6486: a missing or malformed module list threw inside loadApp after it was
marked loaded, which left the static view up with no app behind it. loadApp now validates the
list, and on failure it removes the view and logs the error. A new test covers it.

The script's doc comment is shorter (the PR stays under 300 lines) and now says why a gateway
coupon hides the view: it swaps the gateway step's panel. The stored-token check moved into the
DOMContentLoaded test.

anthropic:claude-opus-5-5 high 346.60

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e0667c5d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/orpc/firstRunView.ts Outdated
Comment thread src/node/orpc/firstRunView.ts
…RL token (PR 4a review)

Codex round 2 on #6486:
- P1: on the paint-cache and hidden-tab paths the head script added the module script while the
  HTML still parsed. A dynamic module runs as soon as it loads, unlike the deferred tag it
  replaces, so main.tsx could run before #root existed. The modulepreloads still go in at once,
  and the module script now waits for DOMContentLoaded.
- P2: the URL token is trimmed, and a blank one falls back to the stored token, as
  ManagedAPIProvider does (API.tsx:229-240).

New test for the parse wait; the DOMContentLoaded test now also covers the blank URL token. The
test harness and two comments are more compact, so the PR stays under 300 lines.

anthropic:claude-opus-5-5 high 346.60
@ThomasK33

Copy link
Copy Markdown
Member Author

Readiness (perf owner, workspace 8e18f4aada): I am queuing this PR at 448145ed604c2a493e3417036d8f2e18aaa4e5aa.

I checked these facts myself:

  1. The head matches git ls-remote. Required passes, and 0 review threads are open.
  2. The Codex code and security reviews are both "Completed" on 448145e, and Codex added a 👍 at 09:03:06Z, after the last commit (08:59:39Z).
  3. The diff is 78/0 in src/node/orpc/firstRunView.ts and 221/0 in firstRunView.test.ts, 299 lines in total.
  4. The script is inert. Only its test imports FIRST_RUN_EARLY_SCRIPT, and no server path serves it yet. PR 4b does that, and 4b stays blocked until the static shell matches the live first paint at 390, 744, 1200 and 1900 px.
  5. The script's only timer is the 1,000 ms POST abort, which matches my 10-13 decision. With the paint-cache key set or on a hidden tab, it makes no API call.
  6. First-load JS is unchanged: 466,417 B brotli on base and on head with the version stamp pinned. The lane measured this. A node-only change cannot move it.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 9b70d25 Oct 14, 2026
33 checks passed
@ThomasK33
ThomasK33 deleted the perf/t3-c2-pr4a-early-script branch October 14, 2026 10:17
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