Skip to content

Commit

Permalink
Trim children string inspector inputs (#5874)
Browse files Browse the repository at this point in the history
**Problem:**

Children text string inputs in the inspector can contain non-trimmed
strings.

**Fix:**

Trim them if defined.

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode

Fixes #5871
  • Loading branch information
ruggi authored Jun 10, 2024
1 parent 782b54e commit 21fc7ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function useChildrenPropOverride(
? props.controlDescription
: {
control: 'string-input',
label: 'hey',
label: 'children',
}
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,19 @@ export const StringInputPropertyControl = React.memo(
element.element.value.children.length > 0
) {
const child = element.element.value.children[0]
switch (child.type) {
case 'ATTRIBUTE_OTHER_JAVASCRIPT':
return child.originalJavascript
case 'JSX_TEXT_BLOCK':
return child.text
function getChildText(): string | null {
switch (child.type) {
case 'ATTRIBUTE_OTHER_JAVASCRIPT':
return child.originalJavascript
case 'JSX_TEXT_BLOCK':
return child.text
default:
return null
}
}
const maybeText = getChildText()
if (maybeText != null) {
return maybeText.trim()
}
}
return undefined
Expand Down

0 comments on commit 21fc7ec

Please sign in to comment.