Skip to content

fix(schema): remove map paths cleanly, including maps under nested paths (backport to 8.x) - #16625

Merged
vkarpov15 merged 2 commits into
Automattic:8.xfrom
mrityunjay-pandey:backport-8x/schema-remove-maps
Oct 21, 2026
Merged

vkarpov15 merged 2 commits into
Automattic:8.xfrom
mrityunjay-pandey:backport-8x/schema-remove-maps

Conversation

@mrityunjay-pandey

Copy link
Copy Markdown

Summary

Backport of #16457 and its follow-up #16461 to 8.x. Both fix Schema#remove() for map paths, in the same function, so they're backported together.

On 8.x:

const schema = new Schema({ n: { m: { type: Map, of: Number } } });
schema.remove('n');
// TypeError: Cannot convert undefined or null to object

Both commits cherry-pick cleanly onto 8.x, in upstream order (git cherry-pick -x 1be9b7b5f 2095a35c5), no changes needed.

Examples

The tests added in #16457 and #16461 are included. On current 8.x both fail; with these changes test/schema.test.js passes (213 tests).

Ran locally on Node 24: test/schema.test.js, the full npm test suite (4057 passing; the one failure, an undoReset() test, hit its 2s timeout during the full run on this machine and passes when run alone, on plain 8.x as well), and ESLint on the changed files.

Schema#remove() walks the subpaths of a nested branch and calls
_deletePath on each. A map registers its values under `<path>.$*`, which
has no branch of its own in the tree, and by the time that subpath is
reached its parent has already been deleted in the same pass, so the walk
lands on undefined and the delete throws.

_deletePath now stops when a piece along the way is missing, and the
nested branch filters mapPaths the way the flat branch already does, so
the schema stops answering pathType() for a path it removed.

Follow up to Automattic#16457, which covered the flat case.

(cherry picked from commit 2095a35)
@vkarpov15 vkarpov15 added this to the 8.24.7 milestone Oct 21, 2026

@vkarpov15 vkarpov15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks 👍

@vkarpov15
vkarpov15 merged commit e3ca215 into Automattic:8.x Oct 21, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants