[PR #5628] [MERGED] fix(game): re-measure the HUD layout when its surface mounts #6854

Closed
opened 2026-10-23 04:14:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5628
Author: @Romuromylus
Created: 8/29/2026
Status: ✅ Merged
Merged: 8/30/2026
Merged by: @Romuromylus

Base: staging ← Head: fix/5626-mobile-webkit-fixture-startup


📝 Commits (7)

  • a446824 fix(game): re-measure the mobile HUD when its surface mounts
  • b1d5ca9 Merge remote-tracking branch 'pasta/staging' into fix/5626-mobile-webkit-fixture-startup
  • c9186ac test(e2e): close the CYOA readiness guard's fail-open path
  • 206fa88 Merge remote-tracking branch 'pasta/staging' into fix/5626-mobile-webkit-fixture-startup
  • bf27812 fix(game): re-measure the HUD layout when its surface mounts
  • e27d318 test(e2e): budget the HUD compaction hold for a cold surface chunk
  • 1591041 test(e2e): bound the frame wait in the HUD compaction hold

📊 Changes

3 files changed (+215 additions, -3 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 e2e/core-flows.e2e.ts (+192 -0)
📝 packages/client/src/components/game/GameSurface.tsx (+22 -3)

📄 Description

Linked issue

Closes #5654

Why this change

This started as a fix for #5626's two flaky mobile WebKit tests. While it was in review, #5633 and #5618 landed and stabilised both of those tests on staging, so I have dropped that work and re-scoped this PR onto the app-side defect the investigation turned up, which is still live.

GameSurface decides its compact HUD layout in an effect keyed on [combatUiActive, normalizedWidgets.length]. That effect measures hudSurfaceRef.current and attaches a ResizeObserver to it. But GameSurface also has an early return for its messages-loading branch, which mounts no surface at all, and the widget state hydrates from chat metadata (useSyncGameState) independently of the messages query. When the widget count lands while that branch is showing, updateWidgetLayout finds no element and returns, and const surface = hudSurfaceRef.current is null so no observer is attached either. Neither dependency changes when the real surface mounts a moment later, so nothing re-measures for the rest of the session.

#5618 changed that effect's reset from a flat false to window.innerWidth < 768. That leaves the stranded value correct on a phone, which is why the mobile CYOA test now passes either way, but it does not address the measurement or the missing observer. Every compact decision that depends on the overlap estimate rather than the width shortcut is still wrong.

The visible result, at a tablet or narrow-desktop width, is that the desktop widget rails render on top of the dialogue and the compact choice stage never appears. Only a window resize recovers it, because the window resize listener is still registered and updateWidgetLayout re-reads the ref when called.

Instrumenting the effect shows both orderings directly:

messages resolve first (correct)
  effect widgets=4 surface=true   -> measured w=900 nextCompact=true

messages resolve last (broken)
  effect widgets=4 surface=false  -> bails, no observer attached
  (no further measurement for the rest of the session)

And at 900px on current staging:

without the fix:  { choiceStage: 0, desktopRails: 2 }
with the fix:     { choiceStage: 1, desktopRails: 0 }

What changed

  • packages/client/src/components/game/GameSurface.tsx: track the HUD surface node in state alongside the existing ref and add it to the layout effect's dependencies, so mounting the surface re-establishes both the measurement and the ResizeObserver. The ref is kept because framer-motion consumes it as constraintsRef in three places, and it is still assigned in the same commit-time ref phase, so drag-constraint resolution is unchanged. The messages-loading branch gets a data-component="GameSurface.MessagesLoading" marker, matching the convention already used across this file; no runtime selector reads it, every existing data-component consumer matches an exact unrelated value.
  • e2e/core-flows.e2e.ts: one new desktop case at 900px. It holds the first page of messages until the loading branch has committed, which pins the ordering rather than leaving it to runner timing, then asserts the branch was actually observed so the hold cannot silently degrade into a no-op, and finally requires the compact stage to be mounted with no desktop rails. 900px is the point of the case: it is past the width < 768 shortcut, so the compact layout can only be reached by measuring.
  • CHANGELOG.md: entry for the fix.

Dropped from the earlier scope: the transcript-swipe change, since #5633 fixed that test upstream with a fresh page per fixture and that approach is better than mine (it does not depend on init-script evaluation order, which Playwright documents as undefined); and the guard I had added to the mobile CYOA test, since #5618's reset makes that case pass with or without this fix, so it no longer demonstrates anything.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Being precise about what backs the ticks above, since two of them are Playwright-driven rather than hand-driven:

  • pnpm check passes (exit 0), as does pnpm version:check.
  • New tablet case, --project=desktop-chromium --retries=0: fails 2/2 with the client fix reverted, reporting the rails rendered and no choice stage, and passes 3/3 with it.
  • The hold's fail-open path is covered: pointing its wait at a marker that does not exist fails on expected the Game messages-loading branch to render while the first page of messages was held rather than passing quietly or timing out somewhere unrelated.
  • Full mobile-webkit job run locally earlier in this branch's life: 101 passed, 96 skipped, 0 failed.
  • CI is green on this head across every lane: all three desktop-chromium shards, all four mobile-webkit shards, all three mobile-chromium shards, complete-node-regressions, container-build-test, pnpm-validate and CodeQL. The container tick rests on that container-build-test job; I did not build an image by hand.
  • The "ran the app" and "edge cases" ticks rest on driving the real app through Playwright at the affected widths (900x800 for the fix, plus the full lanes at 1440x900, Pixel 7 and iPhone 15 Pro), not on a hand-driven browser session. Light/dark and empty-state paths are untouched by this diff: it changes one layout branch selection and adds one DOM marker.

Things I would appreciate a second pair of eyes on:

  • The fix on a real tablet, or a desktop window dragged to roughly 900px: open a Game chat that has HUD widgets on a slow connection and confirm the widgets end up flanking the choice cards rather than sitting over the dialogue.
  • Whether the new case belongs in the desktop lane at all, or whether you would rather this ships without a browser test given #5622's concerns about matrix time. It adds about 10 seconds.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

The failure is a layout state rather than an error, so the clearest evidence is the element counts above: at 900px the pre-fix build mounts two [data-game-widget-rail] elements and no GameSurface.MobileChoiceStage, and the post-fix build mounts the stage and no rails.

Notes for review

#5626 can be closed as resolved by #5633 and #5618; its two tests are green on staging and nothing in this PR touches them any more. I left it open rather than closing someone else's issue on my own read.

The branch carries a merge of staging (the CHANGELOG.md conflict kept both entries, and the core-flows.e2e.ts conflict was resolved in favour of #5633's version wholesale).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Game HUD widget rails overlapping dialogue on tablets and narrow desktop windows.
    • Improved compact HUD layout detection when widgets load asynchronously or while messages are loading.
    • Ensured the HUD updates correctly when its display surface appears after loading.
  • Tests

    • Added end-to-end coverage for HUD compaction at a 900px viewport.
  • Documentation

    • Documented the HUD layout fix in the changelog.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5628 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 8/29/2026 **Status:** ✅ Merged **Merged:** 8/30/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `staging` ← **Head:** `fix/5626-mobile-webkit-fixture-startup` --- ### 📝 Commits (7) - [`a446824`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a446824e0a7059297895306b1c7ffd47e04a0676) fix(game): re-measure the mobile HUD when its surface mounts - [`b1d5ca9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1d5ca9946d95772155a3b2040d908569b66b81d) Merge remote-tracking branch 'pasta/staging' into fix/5626-mobile-webkit-fixture-startup - [`c9186ac`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c9186acf8ecf936e9f7d0fe725e99d2476d31490) test(e2e): close the CYOA readiness guard's fail-open path - [`206fa88`](https://github.com/Pasta-Devs/Marinara-Engine/commit/206fa887157fd17ebc87c2195e20d2a36da9fe08) Merge remote-tracking branch 'pasta/staging' into fix/5626-mobile-webkit-fixture-startup - [`bf27812`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf278125d7ce3e120744d5917b85fc047198fece) fix(game): re-measure the HUD layout when its surface mounts - [`e27d318`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e27d3184fa90bf800fe02b9c8eb1464d8cf12901) test(e2e): budget the HUD compaction hold for a cold surface chunk - [`1591041`](https://github.com/Pasta-Devs/Marinara-Engine/commit/159104144ad9888f9a2ee9d1cea12fda1929f890) test(e2e): bound the frame wait in the HUD compaction hold ### 📊 Changes **3 files changed** (+215 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `e2e/core-flows.e2e.ts` (+192 -0) 📝 `packages/client/src/components/game/GameSurface.tsx` (+22 -3) </details> ### 📄 Description ## Linked issue Closes #5654 ## Why this change This started as a fix for #5626's two flaky mobile WebKit tests. While it was in review, #5633 and #5618 landed and stabilised both of those tests on `staging`, so I have dropped that work and re-scoped this PR onto the app-side defect the investigation turned up, which is still live. `GameSurface` decides its compact HUD layout in an effect keyed on `[combatUiActive, normalizedWidgets.length]`. That effect measures `hudSurfaceRef.current` and attaches a `ResizeObserver` to it. But `GameSurface` also has an early return for its messages-loading branch, which mounts no surface at all, and the widget state hydrates from chat metadata (`useSyncGameState`) independently of the messages query. When the widget count lands while that branch is showing, `updateWidgetLayout` finds no element and returns, and `const surface = hudSurfaceRef.current` is `null` so no observer is attached either. Neither dependency changes when the real surface mounts a moment later, so nothing re-measures for the rest of the session. #5618 changed that effect's reset from a flat `false` to `window.innerWidth < 768`. That leaves the stranded value correct on a phone, which is why the mobile CYOA test now passes either way, but it does not address the measurement or the missing observer. Every compact decision that depends on the overlap estimate rather than the width shortcut is still wrong. The visible result, at a tablet or narrow-desktop width, is that the desktop widget rails render on top of the dialogue and the compact choice stage never appears. Only a window resize recovers it, because the `window` resize listener is still registered and `updateWidgetLayout` re-reads the ref when called. Instrumenting the effect shows both orderings directly: ``` messages resolve first (correct) effect widgets=4 surface=true -> measured w=900 nextCompact=true messages resolve last (broken) effect widgets=4 surface=false -> bails, no observer attached (no further measurement for the rest of the session) ``` And at 900px on current `staging`: ``` without the fix: { choiceStage: 0, desktopRails: 2 } with the fix: { choiceStage: 1, desktopRails: 0 } ``` ## What changed - `packages/client/src/components/game/GameSurface.tsx`: track the HUD surface node in state alongside the existing ref and add it to the layout effect's dependencies, so mounting the surface re-establishes both the measurement and the `ResizeObserver`. The ref is kept because framer-motion consumes it as `constraintsRef` in three places, and it is still assigned in the same commit-time ref phase, so drag-constraint resolution is unchanged. The messages-loading branch gets a `data-component="GameSurface.MessagesLoading"` marker, matching the convention already used across this file; no runtime selector reads it, every existing `data-component` consumer matches an exact unrelated value. - `e2e/core-flows.e2e.ts`: one new desktop case at 900px. It holds the first page of messages until the loading branch has committed, which pins the ordering rather than leaving it to runner timing, then asserts the branch was actually observed so the hold cannot silently degrade into a no-op, and finally requires the compact stage to be mounted with no desktop rails. 900px is the point of the case: it is past the `width < 768` shortcut, so the compact layout can only be reached by measuring. - `CHANGELOG.md`: entry for the fix. Dropped from the earlier scope: the transcript-swipe change, since #5633 fixed that test upstream with a fresh page per fixture and that approach is better than mine (it does not depend on init-script evaluation order, which Playwright documents as undefined); and the guard I had added to the mobile CYOA test, since #5618's reset makes that case pass with or without this fix, so it no longer demonstrates anything. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Being precise about what backs the ticks above, since two of them are Playwright-driven rather than hand-driven: - `pnpm check` passes (exit 0), as does `pnpm version:check`. - New tablet case, `--project=desktop-chromium --retries=0`: fails 2/2 with the client fix reverted, reporting the rails rendered and no choice stage, and passes 3/3 with it. - The hold's fail-open path is covered: pointing its wait at a marker that does not exist fails on `expected the Game messages-loading branch to render while the first page of messages was held` rather than passing quietly or timing out somewhere unrelated. - Full `mobile-webkit` job run locally earlier in this branch's life: 101 passed, 96 skipped, 0 failed. - CI is green on this head across every lane: all three `desktop-chromium` shards, all four `mobile-webkit` shards, all three `mobile-chromium` shards, `complete-node-regressions`, `container-build-test`, `pnpm-validate` and CodeQL. The container tick rests on that `container-build-test` job; I did not build an image by hand. - The "ran the app" and "edge cases" ticks rest on driving the real app through Playwright at the affected widths (900x800 for the fix, plus the full lanes at 1440x900, Pixel 7 and iPhone 15 Pro), not on a hand-driven browser session. Light/dark and empty-state paths are untouched by this diff: it changes one layout branch selection and adds one DOM marker. Things I would appreciate a second pair of eyes on: - The fix on a real tablet, or a desktop window dragged to roughly 900px: open a Game chat that has HUD widgets on a slow connection and confirm the widgets end up flanking the choice cards rather than sitting over the dialogue. - Whether the new case belongs in the desktop lane at all, or whether you would rather this ships without a browser test given #5622's concerns about matrix time. It adds about 10 seconds. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) The failure is a layout state rather than an error, so the clearest evidence is the element counts above: at 900px the pre-fix build mounts two `[data-game-widget-rail]` elements and no `GameSurface.MobileChoiceStage`, and the post-fix build mounts the stage and no rails. ## Notes for review `#5626` can be closed as resolved by #5633 and #5618; its two tests are green on `staging` and nothing in this PR touches them any more. I left it open rather than closing someone else's issue on my own read. The branch carries a merge of `staging` (the `CHANGELOG.md` conflict kept both entries, and the `core-flows.e2e.ts` conflict was resolved in favour of #5633's version wholesale). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Game HUD widget rails overlapping dialogue on tablets and narrow desktop windows. * Improved compact HUD layout detection when widgets load asynchronously or while messages are loading. * Ensured the HUD updates correctly when its display surface appears after loading. * **Tests** * Added end-to-end coverage for HUD compaction at a 900px viewport. * **Documentation** * Documented the HUD layout fix in the changelog. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6854
No description provided.