Skip to content

fix: restore shape ID counter before createPresentation in restorePre…#113

Merged
simongdavies merged 2 commits intohyperlight-dev:mainfrom
simongdavies:fix-pptx-shape-id-serialization
May 7, 2026
Merged

fix: restore shape ID counter before createPresentation in restorePre…#113
simongdavies merged 2 commits intohyperlight-dev:mainfrom
simongdavies:fix-pptx-shape-id-serialization

Conversation

@simongdavies
Copy link
Copy Markdown
Member

…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.

…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>
Copilot AI review requested due to automatic review settings May 7, 2026 14:36
@simongdavies simongdavies added the bug Something isn't working label May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shapeIdCounter before calling createPresentation() to prevent newly created shapes from reusing low IDs after module-level counter resets.
  • Add legacy fallback: when shapeIdCounter is missing, scan restored slide XML fragments to find the maximum existing shape ID and set the counter accordingly.
  • Update builtin-modules/pptx.json sourceHash to 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.

Comment thread builtin-modules/src/pptx.ts Outdated
Comment thread builtin-modules/src/pptx.ts Outdated
Comment thread builtin-modules/src/pptx.ts
- 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>
@simongdavies simongdavies merged commit 7ef5d60 into hyperlight-dev:main May 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants