fix: InlineTextField renders empty for nullish values#1664
Open
shiminshen wants to merge 1 commit into
Open
Conversation
Node.replaceChildren coerces non-Node arguments via String(), so a nullish value materialised as a literal "null" / "undefined" text node in the contentEditable canvas. defaultProps with subtitle: null (or server data returning a null optional field) persistently rendered "null" until the user manually selected-all and deleted. Coerce nullish to "" before replaceChildren, and widen the prop type to string | null | undefined to reflect the runtime reality at the text / textarea field transform call sites. Closes puckeditor#1639
|
@shiminshen is attempting to deploy a commit to the Puck Team on Vercel. A member of the Team first needs to authorize it. |
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.
Closes #1639
Description
InlineTextFieldwas rendering the literal text"null"(or"undefined") in the contentEditable canvas whenever atextortextareafield withcontentEditable: truereceived a nullish value. The cause isNode.replaceChildren(...nodes)coercing each non-Node argument viaString(...)—String(null) === "null"andString(undefined) === "undefined"— so a defaultProp ofsubtitle: null, or a server response returningnullfor an unfilled optional field, persistently surfaced asnulltext in the editor until the user manually selected-all and deleted.The
richtextfield type is unaffected because TipTap handles nullish content; this is specific toInlineTextFieldonly.Changes made
value ?? ""before callingreplaceChildren, in the same effect that syncs the contentEditable span's text.valueprop type fromstringtostring | null | undefinedso the type matches what thetext/textareafield transforms actually pass in (the data model allows nullish props).value={null},value={undefined}, andvalue="Hello world".How to test
Minimal repro from the issue:
Insert
MyBlockin the editor. Before: the canvas shows the textnullwhere the subtitle would be. After: empty, like an empty string.Or run
yarn test --testPathPattern=InlineTextFieldfrompackages/core— 3 new tests cover the null / undefined / string cases.