Skip to content

fix: keep empty sequence items when reading (port of #608) - #660

Merged
wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-608-empty-items
Nov 25, 2026
Merged

wayfarer3130 merged 1 commit into
1.0-betafrom
fix/1.0-beta-port-608-empty-items

Conversation

@wayfarer3130

Copy link
Copy Markdown
Contributor

This PR is the 1.0 port of #608 from 0.x.

Summary

The sync reader dropped an empty item of a sequence. Thus, the later items moved to a lower index. This PR keeps each empty item as {} in its position. The PR also adds tests for all four 1.x readers.

Cause

SequenceOfItems.readBytes in packages/core/src/ValueRepresentation.js calls readOptions.readItem only when the item has bytes. When the item had no bytes, the method pushed nothing. #606 reported the same bug in 0.x.

Changes

  • packages/core/src/ValueRepresentation.js: SequenceOfItems.readBytes pushes {} for an empty item (else { elements.push({}); }). This is the same fix as fix: preserve empty sequence items when reading #608.
  • test/SequenceOfItems.test.js: the port of the fix: preserve empty sequence items when reading #608 tests. The tests read the items [{}, item, {}] in explicit and implicit VR, with defined and undefined lengths for the sequence and for the items (8 cases). The old test "returns an empty elements array sinnce the item is empty" expected the reader to drop the empty item. Now the test expects [{}], as in fix: preserve empty sequence items when reading #608.
  • test/sync-async-parser-equivalency.test.js: a new test writes a Part 10 file that has the same sequence. The test reads the file with the sync reader (DicomMessage.readFile), the async reader (AsyncDicomReader), fromPart10 and fromPart10Stream (32 cases).
  • test/helper/sequenceItems.js: a new helper that writes the bytes of the sequence for the two test files.

Verified

  • Before the fix, 17 tests failed:
    • the 8 ported readBytes cases: "Expected length: 3, Received length: 1";
    • the changed old test;
    • the 8 cases of the sync reader in the new reader test.
  • Before the fix, the 24 cases of the async reader, fromPart10 and fromPart10Stream passed. Thus, only the sync reader had the bug in 1.x.
  • After the fix, these test files pass with npx jest --runInBand (121 tests): SequenceOfItems, sync-async-parser-equivalency, defined-length-sequence, async-data, eventStream/fromPart10, readBufferStream. lossless-read-write and data-encoding also pass (84 tests).
  • test/bundle-size.test.js passes with a new build. dcmjs.es.js is 1445632 bytes, and the ceiling is 1445650 bytes. The PR does not change the limit. The fix has no inline comment, because the ESM consumer bundle keeps the source comments and a comment put the bundle over the limit.
  • eslint, the prettier check and pnpm run build pass.
  • I did not run the full jest suite locally. CI runs the full suite.

Release note

The sync reader now keeps an empty sequence item. An empty item now comes back as {} in its position, and the later items keep their index. Before this change, the reader dropped the empty item. Code that expected the shorter array must change.

Not ported, and why

🤖 Generated with Claude Code

SequenceOfItems.readBytes skipped an item with no bytes, so later items
moved to a lower index. It now pushes {} for an empty item. The async
reader, fromPart10 and fromPart10Stream already kept empty items; a new
test checks all four readers in both VR modes with defined and
undefined lengths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…662

The combined build measures x1.0841 (dcmjs.js) and x1.0665 (dcmjs.es.js).
The ceiling comment is now one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 25, 2026 14:05
@wayfarer3130
wayfarer3130 merged commit bfb5448 into 1.0-beta Nov 25, 2026
4 checks passed
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…oups (port of #603) (#662)

* fix(normalizers): normalize multiframe datasets missing functional groups (port of #603)

normalizeMultiframe dereferenced a missing SharedFunctionalGroupsSequence
and threw a TypeError. When the groups are missing, fill the shared
PlaneOrientationSequence / PixelMeasuresSequence and the per-frame
PlanePositionSequence from the top-level attributes, through the static
ImageNormalizer.sharedImagePlaneGroups and planePositionGroup that
convertToMultiframe now also uses. Lower NumberOfFrames to the whole
frames PixelData holds (never raise it), with a warning. A per-frame
sequence that is already an array is no longer wrapped again, so a
one-frame item is an object and not [[item]]. log.error becomes log.warn.

Raise the bundle-size ceilings to 1.084 and 1.067 for the ~1.7 KB added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(normalizers): keep the declared NumberOfFrames when functional groups are missing

The normalizer no longer lowers NumberOfFrames to the frames that PixelData
appears to hold. Encapsulated PixelData can have more or fewer fragments than
frames, so a byte count says nothing about the frame count. framesInPixelData
is removed.

A dataset with no PerFrameFunctionalGroupsSequence now gets one per-frame item
for each declared frame, each with PlanePositionSequence from the top-level
ImagePositionPatient and its own FrameContentSequence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(bundle-size): set the ceilings from a build with #660, #659 and #662

The combined build measures x1.0841 (dcmjs.js) and x1.0665 (dcmjs.es.js).
The ceiling comment is now one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant