fix: restore shape ID counter before createPresentation in restorePre…#113
Merged
simongdavies merged 2 commits intohyperlight-dev:mainfrom May 7, 2026
Merged
Conversation
…sentation When a handler is recompiled (new handler registered), ESM module-level variables reset to initial values. The shape ID counter in ooxml-core resets to 1. Previously, restorePresentation called createPresentation first, then set the counter — but any shapes created between those two calls would get IDs starting from 1, colliding with restored slides. Fix: set the shape ID counter FIRST, before createPresentation, so all subsequent shape creation uses the correct counter value. Also adds a fallback for older serialized presentations that lack shapeIdCounter: scans all restored slides for the maximum existing shape ID and sets the counter to that value, preventing collisions even without explicit counter tracking. Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes shape ID collisions when restoring serialized PPTX presentations across handler recompilations by restoring the global shape ID counter before any shape-generating work occurs, and adds a backward-compatible fallback for older serialized state that doesn’t include shapeIdCounter.
Changes:
- Restore
shapeIdCounterbefore callingcreatePresentation()to prevent newly created shapes from reusing low IDs after module-level counter resets. - Add legacy fallback: when
shapeIdCounteris missing, scan restored slide XML fragments to find the maximum existing shape ID and set the counter accordingly. - Update
builtin-modules/pptx.jsonsourceHashto reflect the module source change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| builtin-modules/src/pptx.ts | Restores the global shape ID counter earlier and introduces a legacy fallback scan to prevent ID collisions after restore. |
| builtin-modules/pptx.json | Updates module metadata hash for the modified PPTX builtin module source. |
- Validate shapeIdCounter with Number.isFinite + Number.isInteger before passing to setShapeIdCounter (rejects NaN/Infinity/floats) - Extract shared SHAPE_ID_REGEX constant and _extractShapeIds helper used by both _validatePresentation and restorePresentation - Add 2 tests for shape ID continuity across serialize/restore: 1. Normal flow: serialize → restore → addSlideNumbers → buildZip 2. Legacy fallback: missing shapeIdCounter → scan slides for max ID Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…sentation
When a handler is recompiled (new handler registered), ESM module-level variables reset to initial values. The shape ID counter in ooxml-core resets to 1. Previously, restorePresentation called createPresentation first, then set the counter — but any shapes created between those two calls would get IDs starting from 1, colliding with restored slides.
Fix: set the shape ID counter FIRST, before createPresentation, so all subsequent shape creation uses the correct counter value.
Also adds a fallback for older serialized presentations that lack shapeIdCounter: scans all restored slides for the maximum existing shape ID and sets the counter to that value, preventing collisions even without explicit counter tracking.