Skip to content

Play page: the fleet in the first frame, and end-to-end tests - #17

Merged
AdminGodZ merged 2 commits into
mainfrom
t3/ships-in-first-paint
Nov 27, 2026
Merged

AdminGodZ merged 2 commits into
mainfrom
t3/ships-in-first-paint

Conversation

@AdminGodZ

Copy link
Copy Markdown
Owner

Why the ships came in late

The game's script (game.ts) drew the ships. It arrives a round trip after the page whenever it isn't cached: on a first visit, or on any visit after a release changes its file name. Coming from the homepage, the page showed at 0.25 s and the ships popped in at 0.42 s. The ship list ("Not placed"), the count ("0 of 5 placed") and the Start button changed at the same moment.

What changes

  • The page draws the fleet itself. An inline script in Game.astro, placed after the dock, runs before the first paint. It draws the saved fleet, or a random one with the same uniform draw as game.ts. It also fills in the ship list and count, and enables Start. game.ts takes that fleet over as it is (from #home's data-fleet), so nothing is redrawn or animated in again.
  • An early press of Start isn't lost. The inline script notes it, and game.ts starts the battle once the engine is in.
  • The ✓ in the ship list is drawn, not typed. Newsreader has no ✓, so the browser searched the system's fonts for one. A trace showed that search cost a 50 ms layout (at 4× CPU throttle) in the first frame. It's now a small SVG mask in currentColor, and ✓ is dropped from the font's declared character range. The font files are byte-identical, so their cache entries survive.

Measured

Headless Chromium, slow-4G-like network, 4× CPU throttle, median of 9 runs:

First paint Ships appear
Homepage → /play, before 253 ms 423 ms
Homepage → /play, after 254 ms 245 ms (in the first paint)
First visit, before 739 ms
First visit, after 704 ms in the first paint

End-to-end tests (site/e2e, Playwright 1.65.1)

npm run test:e2e runs after a build. A small static server (e2e/serve.mjs) serves dist as Vercel does. The suite runs in Chromium, WebKit, Firefox and a phone (iPhone 15). Every test fails if the page throws or logs an error. CI runs the suite in the website job and uploads traces when it fails.

What it covers:

  • Site: the homepage, its link to the game, the download list, and no sideways scrolling at phone width.
  • First frame: the fleet, ship list and Start with the game script blocked; the script taking that fleet over unchanged; a saved fleet coming back.
  • Placing: picking ships up, turning, moving and putting them back; the overlap and off-the-chart messages; R and Escape; Clear and Random.
  • Battle:
    • a whole game, started before the engine is in, then another game;
    • Start pressed while the script is held back;
    • the heat map following the engine's shots;
    • a resign while the engine aims, whose shot never lands;
    • the no-worker fallback;
    • a forced player win;
    • an engine that fails to load.
  • Offline file: played from disk.

It already caught one bug in this PR: the early Start press was handled before the engine's callback was registered, so the press was silently lost. Fixed.

Checks

  • cargo fmt --check, cargo clippy -D warnings: clean.
  • cargo test: 61 passed.
  • npm run check: 0 errors, 0 warnings, 0 hints.
  • npm run build: builds.
  • npm run test:e2e, locally on Chromium, WebKit and the phone, three repeats: 159 passed, 3 skipped (the keyboard test on the phone).
  • Firefox not run locally: Playwright's Firefox build won't start on this machine's macOS, even by hand. CI runs it on Linux.

The ships were drawn by the game's script, which comes a round trip after
the page whenever it isn't cached (a first visit, or any visit after a
release). From the home page, the page showed at 0.25 s and the ships at
0.42 s. Now the page's own inline script draws the fleet (saved or random),
fills in the dock and enables Start before the first paint; game.ts takes
that fleet over as it is. A press of Start before game.ts is in is noted
and acted on once it is.

The placed tick (✓) in the dock is now drawn with a mask: Newsreader has
no ✓, and finding one among the system's fonts cost a 50 ms layout (slow
phone) in the first frame.

End-to-end tests (site/e2e, Playwright): the site, placing, whole games,
the heat map, resigning mid-move, the no-worker fallback, a forced win, an
engine that fails to load, and the offline file from disk, in Chromium,
WebKit, Firefox and a phone. CI runs them after the build.
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
broadside Ready Ready Preview Nov 27, 2026 8:05am UTC

On CI's WebKit the page took over a second to come up, so the script was in
before Start was pressed and the test checked nothing. Now the script waits
for the test, so the press always comes first.
@AdminGodZ
AdminGodZ merged commit 36d8d89 into main Nov 27, 2026
4 checks passed
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