mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #158] [MERGED] Fix Game Mode new scene opening mid-scene instead of at segment 0 #4486
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4486
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/158
Author: @Romuromylus
Created: 4/21/2026
Status: ✅ Merged
Merged: 4/21/2026
Merged by: @SpicyMarinara
Base:
main← Head:fix-game-mode-new-scene-index-reset📝 Commits (2)
7bd79edFix Game Mode new scene opening mid-scene instead of at segment 06b67677Merge branch 'main' into fix-game-mode-new-scene-index-reset📊 Changes
1 file changed (+4 additions, -0 deletions)
View changed files
📝
packages/client/src/components/game/GameNarration.tsx(+4 -0)📄 Description
Summary
In Game Mode, when a new GM response arrives, the narration opens on a later segment instead of the first line of the new scene — it visually jumps "into the middle" rather than starting at segment 0.
Root cause
Two
useEffects inGameNarration.tsxcooperate to produce the jump:Effect A — main new-message handler (around line 789): on
latestAssistant.idchange, theisRestoredbranch (line 799) setsactiveIndexto the saved segment index and flipsrestoredRef.current = true. On subsequent new scenes it correctly falls through to the non-restore branch (line 816) and setsactiveIndex = playerSegmentOffset— but it never clearsrestoredRef.currentback tofalse.Effect B — "segments grow after restore" handler (around line 833):
This exists for the legitimate case where async party dialogue arrives after page reload and grows the segment list — then we want to snap to the exact saved index.
The failure sequence on a new scene:
activeIndex = 0.segments.lengthchanges.restoredRef.currentis stilltruefrom the initial restore.restoredSegmentIndexis the stale saved index from the previous scene (persisted viaGameSurface.handleSegmentChangeand re-read by therestoredSegmentIndexmemo).activeIndexwith the stale value — the mid-scene open.Fix
Clear
restoredRef.currentat the end of Effect A's non-restore branch. Once we've advanced past the initial restored message, Effect B should no longer apply the saved index.Why this preserves the restore path
isRestoredbranch still setsrestoredRef.current = trueand returns early; the new clear lives only in the non-restore branch, so Effect B still fires correctly when party segments arrive for the restored message.activeIndex = 0, and dropsrestoredRef.current = false. Effect B short-circuits at its first guard; no mid-scene jump.restoredRef.currentwas alreadyfalse; writingfalseagain is a no-op.React guarantees effect execution order: Effect A is declared before Effect B, so the ref is already cleared by the time Effect B checks it in the same render cycle.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.