[GH-ISSUE #5654] [Issue]: Game HUD never compacts when its surface mounts after the widget state hydrates #3129

Closed
opened 2026-10-21 05:59:51 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Romuromylus on GitHub (Aug 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5654

Originally assigned to: @Romuromylus on GitHub.

Summary

When a Game chat's custom widget state hydrates while the transcript is still loading, GameSurface measures its HUD layout before the surface element exists and attaches no ResizeObserver, so the layout is never measured again on its own. At widths above the compact-by-width shortcut this leaves the desktop widget rails rendered on top of the dialogue until the window happens to be resized.

Expected behavior

A Game chat with HUD widgets opened at a tablet or narrow-desktop width should collapse into the compact choice stage, with the widget rails flanking the choice cards, regardless of whether the transcript or the chat metadata resolved first.

Actual behavior

The desktop widget rails render over the dialogue and the compact stage never appears. Nothing recovers it for the rest of the session except a window resize, because the observer that would have re-measured the layout was never attached.

The mechanism is in packages/client/src/components/game/GameSurface.tsx. The widget-layout effect is keyed on [combatUiActive, normalizedWidgets.length]. It measures hudSurfaceRef.current and attaches a ResizeObserver to it, but GameSurface also has an early return for its messages-loading branch that 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.

#5618 changed that effect's reset from a flat false to window.innerWidth < 768, which makes the stranded value coincidentally correct on a phone. It does not address the measurement or the missing observer, so every case where the compact layout depends on the overlap estimate rather than raw width is still broken.

Steps to reproduce

  1. Open the app in a window about 900px wide.
  2. Open a Game chat with an active session and four custom HUD widgets in its blueprint (two hud_left, two hud_right), whose latest assistant message carries a [choices: ...] block.
  3. Arrange for the first page of messages to resolve after the chat detail, which is the ordinary ordering on a slow connection or a loaded machine. The reliable way to force it is to hold the first GET /api/chats/<id>/messages response until the surface has rendered its loading state.
  4. Observe the widget rails sitting over the dialogue with no compact choice stage.
  5. Resize the window by any amount and watch the layout correct itself.

Instrumenting the effect shows the two 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)

A Playwright probe at 900px reports { choiceStage: 0, desktopRails: 2 } on current staging, against { choiceStage: 1, desktopRails: 0 } once the effect re-measures when the surface mounts.

Environment

  • Marinara Engine version: 2.4.4 (staging, currently 5c6ac775e)
  • Install type: source
  • OS + version: Windows 11
  • Browser or app shell: Chromium and WebKit via the Playwright lanes; the width is what matters, not the engine

Logs, screenshots, or video

No console errors. The surface renders completely and only the layout branch is wrong, which is why it reads as a styling problem rather than a failure.

Additional context

Found while investigating #5626. The two tests named there are now green on staging after #5633 and #5618, but both of those addressed the symptoms; this is the app-side defect underneath, and it survives on any path where the compact decision depends on measurement instead of the window.innerWidth < 768 shortcut.

Workaround for users: resize the window once after opening the chat.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Aug 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5654 Originally assigned to: @Romuromylus on GitHub. ## Summary When a Game chat's custom widget state hydrates while the transcript is still loading, `GameSurface` measures its HUD layout before the surface element exists and attaches no `ResizeObserver`, so the layout is never measured again on its own. At widths above the compact-by-width shortcut this leaves the desktop widget rails rendered on top of the dialogue until the window happens to be resized. ## Expected behavior A Game chat with HUD widgets opened at a tablet or narrow-desktop width should collapse into the compact choice stage, with the widget rails flanking the choice cards, regardless of whether the transcript or the chat metadata resolved first. ## Actual behavior The desktop widget rails render over the dialogue and the compact stage never appears. Nothing recovers it for the rest of the session except a window resize, because the observer that would have re-measured the layout was never attached. The mechanism is in `packages/client/src/components/game/GameSurface.tsx`. The widget-layout effect is keyed on `[combatUiActive, normalizedWidgets.length]`. It measures `hudSurfaceRef.current` and attaches a `ResizeObserver` to it, but `GameSurface` also has an early return for its messages-loading branch that 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. #5618 changed that effect's reset from a flat `false` to `window.innerWidth < 768`, which makes the stranded value coincidentally correct on a phone. It does not address the measurement or the missing observer, so every case where the compact layout depends on the overlap estimate rather than raw width is still broken. ## Steps to reproduce 1. Open the app in a window about 900px wide. 2. Open a Game chat with an active session and four custom HUD widgets in its blueprint (two `hud_left`, two `hud_right`), whose latest assistant message carries a `[choices: ...]` block. 3. Arrange for the first page of messages to resolve after the chat detail, which is the ordinary ordering on a slow connection or a loaded machine. The reliable way to force it is to hold the first `GET /api/chats/<id>/messages` response until the surface has rendered its loading state. 4. Observe the widget rails sitting over the dialogue with no compact choice stage. 5. Resize the window by any amount and watch the layout correct itself. Instrumenting the effect shows the two 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) ``` A Playwright probe at 900px reports `{ choiceStage: 0, desktopRails: 2 }` on current `staging`, against `{ choiceStage: 1, desktopRails: 0 }` once the effect re-measures when the surface mounts. ## Environment - Marinara Engine version: 2.4.4 (`staging`, currently `5c6ac775e`) - Install type: source - OS + version: Windows 11 - Browser or app shell: Chromium and WebKit via the Playwright lanes; the width is what matters, not the engine ## Logs, screenshots, or video No console errors. The surface renders completely and only the layout branch is wrong, which is why it reads as a styling problem rather than a failure. ## Additional context Found while investigating #5626. The two tests named there are now green on `staging` after #5633 and #5618, but both of those addressed the symptoms; this is the app-side defect underneath, and it survives on any path where the compact decision depends on measurement instead of the `window.innerWidth < 768` shortcut. Workaround for users: resize the window once after opening the chat. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:59:51 +07:00
Author
Owner

@Romuromylus commented on GitHub (Aug 30, 2026):

Fixed by #5628, squash-merged to staging as 7f43d455e.

The widget-layout effect now depends on the HUD surface node itself, so mounting the surface re-establishes both the measurement and the ResizeObserver. A hydration that lands while the messages-loading branch is up no longer strands the layout.

Covered by a regression case at 900px in e2e/core-flows.e2e.ts, which is past the width < 768 shortcut and so can only reach the compact layout by measuring. It holds the first page of messages until the loading branch has committed to pin the ordering, and asserts the branch was actually observed so the hold cannot quietly stop guarding. It fails with the fix reverted (two [data-game-widget-rail] elements and no choice stage) and passes with it.

Closing as resolved.

<!-- gh-comment-id:5465767149 --> @Romuromylus commented on GitHub (Aug 30, 2026): Fixed by #5628, squash-merged to `staging` as 7f43d455e. The widget-layout effect now depends on the HUD surface node itself, so mounting the surface re-establishes both the measurement and the `ResizeObserver`. A hydration that lands while the messages-loading branch is up no longer strands the layout. Covered by a regression case at 900px in `e2e/core-flows.e2e.ts`, which is past the `width < 768` shortcut and so can only reach the compact layout by measuring. It holds the first page of messages until the loading branch has committed to pin the ordering, and asserts the branch was actually observed so the hold cannot quietly stop guarding. It fails with the fix reverted (two `[data-game-widget-rail]` elements and no choice stage) and passes with it. Closing as resolved.
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#3129
No description provided.