Skip to content

Commit

Permalink
fix: Ensure list-item.checked is not set to undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
dstoc committed Oct 18, 2024
1 parent 929fab7 commit c19a5e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/markdown/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ export function normalizeTree(tree: MarkdownTree) {
}
// Collapse directly nested lists.
if (node.type === 'list-item') {
// Ensure checked is not set, rather than set to undefined
// since it could serialize as null.
if (
node.checked === null ||
(node.checked === undefined && 'checked' in node)
) {
node[viewModel].updateChecked(undefined);
}
if (
node[viewModel].firstChild?.type === 'list' &&
node.children?.length === 1
Expand Down
7 changes: 6 additions & 1 deletion src/markdown/view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ export class ViewModel {
case 'list-item': {
const oldChecked = this.self.checked;
if (oldChecked === checked) return;
(this.self as {checked?: boolean}).checked = checked;
if (checked == undefined) {
delete (this.self as {checked?: boolean}).checked;
} else {
(this.self as {checked?: boolean}).checked = checked;
}

this.signalMutation({
type: 'check',
node: this.self,
Expand Down

0 comments on commit c19a5e6

Please sign in to comment.