Skip to content

fix(prefab): preserve structural edits through redo - #897

Open
bofeng-song wants to merge 3 commits into
cocos:mainfrom
bofeng-song:fix/prefab-edit-structure-undo
Open

fix(prefab): preserve structural edits through redo#897
bofeng-song wants to merge 3 commits into
cocos:mainfrom
bofeng-song:fix/prefab-edit-structure-undo

Conversation

@bofeng-song

Copy link
Copy Markdown
Contributor

Problem

After adding or removing nodes in prefab editing mode and saving, Undo could remove the structural change but Redo did not reliably restore it in the prefab asset or its scene instances.

Cause

Structural edits were recorded as individual node commands, while saving the prefab wrote the complete prefab asset separately. The asset reload could therefore replace the replayed node state with serialized content that did not match the Undo/Redo command.

Fix

  • Start a dedicated Undo group when a prefab editor opens and restart it after saves or history-clearing reloads.
  • Capture the prefab root snapshot and serialized asset content at the start of each edit group.
  • On save, append a prefab asset command to the group so Undo and Redo restore both the asset content and the prefab root structure together.
  • Preserve Undo history across the reload triggered by saving the prefab asset.
  • Add a regression test covering add child, save, Undo, and Redo with asset-content assertions.

Validation

  • npx tsc --noEmit --pretty false
  • npx jest src/core/scene/test/editor-close-options.test.ts src/core/scene/test/editor-save-as.test.ts --runInBand

@bofeng-song
bofeng-song force-pushed the fix/prefab-edit-structure-undo branch from 005e40c to 6b0401e Compare August 31, 2026 06:36
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