fix: handle null field values when pasting into empty PTE fields#2160
Closed
christianhg wants to merge 9 commits intomainfrom
Closed
fix: handle null field values when pasting into empty PTE fields#2160christianhg wants to merge 9 commits intomainfrom
christianhg wants to merge 9 commits intomainfrom
Conversation
This fixes the "Attempt to apply insert patch to non-array value" error that occurs when pasting content into a Portable Text field that has a null value (as opposed to undefined or []). The root cause was that setIfMissing only checks for undefined, treating null as "present". When the field is null, the subsequent insert patch with an index-based path fails because there's no array to insert into. Changes: - slate-plugin.patches.ts: Use atomic set() instead of insert() for empty→non-empty transitions - operation-to-patches.ts: Use atomic set() instead of setIfMissing + insert when inserting into an empty array Fixes CRX-1886 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Update test expectations in placeholder-block.test.tsx and event.patch.test.tsx to use atomic `set` patches instead of `insert(..., 'before', [0])` for empty→non-empty transitions. This aligns with the fix for null field handling - using atomic set ensures the operation works regardless of whether the field value is null, undefined, or an empty array. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update test expectations in: - event.block.set.test.tsx - event.block.unset.test.tsx - change-subject.test.tsx All tests now expect atomic `set` patches instead of `insert(..., 'before', [0])` for empty→non-empty transitions, aligning with the fix for null field handling. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update test expectations in: - event.patch.test.tsx (lines 212, 294, 424) - event.delete.backward.test.tsx (line 96) - event.delete.block.test.tsx (line 88) - event.delete.forward.test.tsx (line 92) All tests now expect atomic `set` patches instead of `insert(..., 'before', [0])` for empty→non-empty transitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- event.child.unset.test.tsx (line 384) - event.insert.block.test.tsx (lines 451, 548) - event.patches.test.tsx (both initial patch tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update two test expectations (lines 196 and 317) to expect atomic `set` operations instead of `insert(..., 'before', [0])` for empty→non-empty transitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 the "Attempt to apply insert patch to non-array value" error that occurs when pasting content into a Portable Text field that has a
nullvalue.Related issue: CRX-1886
Root Cause
The
setIfMissingpatch only checks forundefined, treatingnullas "present". When pasting into an empty PTE field:setIfMissing([], [])to ensure the array existssetIfMissingseesnullas "present" and does nothinginsertpatch with an index-based path[0]fails because there's no array to insert intoChanges
Fix 1:
slate-plugin.patches.ts:139insert(previousValue, 'before', [0])toset(previousValue, [])Fix 2:
operation-to-patches.ts:296-301insertNodePatchfallback fromsetIfMissing([], []) + insert([block], 'before', [0])to atomicset([block], [])null,undefined, or[]Test plan
null-field-bug.test.tsdemonstrating the bug and fix🤖 Generated with Claude Code