fix: ensure numbered list start property always present (#2241) #2242
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.
Summary
Fixes #2241 - RangeError when parsing markdown with numbered lists.
The
parse()method inNumberedListItemblock now always returns an object with thestartproperty, eliminating the RangeError that occurred when ProseMirror expected all schema-defined attributes to be present.Rationale
When parsing markdown with numbered lists, the old code would sometimes return an object without the
startproperty (returning onlydefaultProps). While this worked in some code paths due to ProseMirror automatically filling defaults, it caused aRangeError: No value supplied for attribute startin other scenarios where nodes were created more directly.The fix normalizes the return value to always include the
startproperty, ensuring consistency across all code paths.Changes
Modified:
packages/core/src/blocks/ListItem/NumberedListItem/block.ts- Changed parse method to always return object withstartpropertyAdded:
tests/src/unit/core/blocks/NumberedListItem.test.ts- Unit test that directly tests the parse() functiontests/src/unit/core/formatConversion/parse/parseTestInstances.ts- Integration test for numbered list markdown parsingtests/src/unit/core/formatConversion/parse/__snapshots__/markdown/issue2241NumberedListStartProperty.json- Test snapshotCode change:
Impact
start: undefinedis semantically identical to implicit undefined from schema defaultTesting
Unit Test (catches the bug):
NumberedListItem.test.tswith 5 test cases{ textAlignment: undefined }(missingstart)startpropertyIntegration Test:
issue2241NumberedListStartPropertytest caseAll Tests:
Screenshots/Video
N/A - This is a bug fix for an internal parser issue with no visual changes.
Checklist
Additional Notes
Why the integration test doesn't catch the old bug:
The existing integration tests use
markdownToBlocks()which goes through ProseMirror's full parsing pipeline. ProseMirror automatically fills in missing attributes with schema defaults, so the RangeError doesn't occur in that code path.The unit test catches the bug:
The new unit test directly tests the
parse()function's return value, which reveals that the old code returned an object missing thestartproperty. This test ensures the fix works correctly and prevents regression.