Commit 7ef5d60
authored
fix: restore shape ID counter before createPresentation in restorePre… (#113)
* fix: restore shape ID counter before createPresentation in restorePresentation
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>
* fix: address PR #113 review feedback
- 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>
---------
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>1 parent 09d6567 commit 7ef5d60
3 files changed
Lines changed: 111 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3916 | 3916 | | |
3917 | 3917 | | |
3918 | 3918 | | |
3919 | | - | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
3920 | 3922 | | |
3921 | 3923 | | |
3922 | 3924 | | |
| |||
4389 | 4391 | | |
4390 | 4392 | | |
4391 | 4393 | | |
| 4394 | + | |
| 4395 | + | |
| 4396 | + | |
| 4397 | + | |
| 4398 | + | |
| 4399 | + | |
| 4400 | + | |
| 4401 | + | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
4392 | 4413 | | |
4393 | 4414 | | |
4394 | 4415 | | |
| |||
4422 | 4443 | | |
4423 | 4444 | | |
4424 | 4445 | | |
4425 | | - | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
4426 | 4451 | | |
4427 | 4452 | | |
4428 | 4453 | | |
| |||
4436 | 4461 | | |
4437 | 4462 | | |
4438 | 4463 | | |
4439 | | - | |
| 4464 | + | |
4440 | 4465 | | |
4441 | | - | |
4442 | | - | |
4443 | | - | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
4444 | 4469 | | |
4445 | 4470 | | |
4446 | 4471 | | |
| |||
4449 | 4474 | | |
4450 | 4475 | | |
4451 | 4476 | | |
4452 | | - | |
| 4477 | + | |
4453 | 4478 | | |
4454 | | - | |
4455 | | - | |
| 4479 | + | |
| 4480 | + | |
4456 | 4481 | | |
4457 | 4482 | | |
4458 | 4483 | | |
4459 | 4484 | | |
4460 | | - | |
| 4485 | + | |
| 4486 | + | |
4461 | 4487 | | |
4462 | 4488 | | |
4463 | 4489 | | |
| |||
4521 | 4547 | | |
4522 | 4548 | | |
4523 | 4549 | | |
4524 | | - | |
| 4550 | + | |
| 4551 | + | |
4525 | 4552 | | |
4526 | 4553 | | |
4527 | 4554 | | |
4528 | 4555 | | |
4529 | 4556 | | |
4530 | 4557 | | |
4531 | | - | |
4532 | | - | |
| 4558 | + | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
4533 | 4563 | | |
4534 | | - | |
4535 | | - | |
4536 | | - | |
4537 | 4564 | | |
4538 | 4565 | | |
4539 | 4566 | | |
| |||
4937 | 4964 | | |
4938 | 4965 | | |
4939 | 4966 | | |
4940 | | - | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
4941 | 4970 | | |
4942 | 4971 | | |
4943 | 4972 | | |
| |||
5869 | 5898 | | |
5870 | 5899 | | |
5871 | 5900 | | |
| 5901 | + | |
| 5902 | + | |
| 5903 | + | |
| 5904 | + | |
| 5905 | + | |
| 5906 | + | |
| 5907 | + | |
| 5908 | + | |
| 5909 | + | |
| 5910 | + | |
| 5911 | + | |
| 5912 | + | |
| 5913 | + | |
| 5914 | + | |
| 5915 | + | |
| 5916 | + | |
| 5917 | + | |
| 5918 | + | |
| 5919 | + | |
| 5920 | + | |
| 5921 | + | |
| 5922 | + | |
| 5923 | + | |
5872 | 5924 | | |
5873 | 5925 | | |
5874 | 5926 | | |
| |||
5899 | 5951 | | |
5900 | 5952 | | |
5901 | 5953 | | |
5902 | | - | |
5903 | | - | |
5904 | | - | |
5905 | | - | |
5906 | | - | |
5907 | | - | |
5908 | 5954 | | |
5909 | 5955 | | |
5910 | 5956 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2464 | 2464 | | |
2465 | 2465 | | |
2466 | 2466 | | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
2467 | 2508 | | |
2468 | 2509 | | |
2469 | 2510 | | |
| |||
0 commit comments