Skip to content

Commit ddb0bb5

Browse files
authored
Merge pull request #8 from pheuberger/claude/fix-broken-tags-4m0s4
Fix data integrity issues in TagInput and useNostrSync
2 parents 6550a74 + ca4e0de commit ddb0bb5

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/components/ui/TagInput.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const TagInput = forwardRef(function TagInput({
1212
onFocus,
1313
onKeyDown: externalOnKeyDown,
1414
}, ref) {
15+
// Ensure value is always an array (defensive against corrupted data)
16+
const safeValue = Array.isArray(value) ? value : []
17+
1518
const [inputValue, setInputValue] = useState('')
1619
const [isOpen, setIsOpen] = useState(false)
1720
const [selectedIndex, setSelectedIndex] = useState(0)
@@ -26,14 +29,14 @@ export const TagInput = forwardRef(function TagInput({
2629
const filteredTags = useMemo(() => {
2730
const input = inputValue.toLowerCase().trim()
2831
return allTags
29-
.filter((tag) => !value.includes(tag))
32+
.filter((tag) => !safeValue.includes(tag))
3033
.filter((tag) => !input || tag.toLowerCase().includes(input))
31-
}, [inputValue, allTags, value])
34+
}, [inputValue, allTags, safeValue])
3235

3336
const normalizedInput = inputValue.trim().toLowerCase()
34-
const showCreateOption = normalizedInput &&
37+
const showCreateOption = normalizedInput &&
3538
!allTags.some((tag) => tag.toLowerCase() === normalizedInput) &&
36-
!value.includes(normalizedInput)
39+
!safeValue.includes(normalizedInput)
3740

3841
const options = useMemo(() => {
3942
const items = filteredTags.map((tag) => ({ type: 'existing', value: tag }))
@@ -57,8 +60,8 @@ export const TagInput = forwardRef(function TagInput({
5760
}, [selectedIndex, isOpen])
5861

5962
const selectTag = (tag) => {
60-
if (!value.includes(tag)) {
61-
onChange([...value, tag])
63+
if (!safeValue.includes(tag)) {
64+
onChange([...safeValue, tag])
6265
}
6366
setInputValue('')
6467
setSelectedIndex(0)
@@ -108,8 +111,8 @@ export const TagInput = forwardRef(function TagInput({
108111
}
109112
}
110113

111-
if (e.key === 'Backspace' && !inputValue && value.length > 0) {
112-
onChange(value.slice(0, -1))
114+
if (e.key === 'Backspace' && !inputValue && safeValue.length > 0) {
115+
onChange(safeValue.slice(0, -1))
113116
}
114117

115118
externalOnKeyDown?.(e)
@@ -179,7 +182,7 @@ export const TagInput = forwardRef(function TagInput({
179182
</ul>
180183
)}
181184

182-
{!isOpen && value.length === 0 && !inputValue && (
185+
{!isOpen && safeValue.length === 0 && !inputValue && (
183186
<p className="mt-1.5 text-xs text-muted-foreground">
184187
Press ↓ to see existing tags
185188
</p>

src/hooks/useNostrSync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function bookmarkDataToYMap(bookmarkData) {
6363
// Filter out any undefined/null values before pushing
6464
const validTags = bookmarkData.tags.filter(t => t != null)
6565
if (validTags.length > 0) {
66-
tagsArray.push(...validTags)
66+
tagsArray.push(validTags)
6767
}
6868
ymap.set('tags', tagsArray)
6969
} else {

0 commit comments

Comments
 (0)