fix(lib): restore automatic hashtag creation for unknown tags#673
Open
antontranelis wants to merge 7 commits intomainfrom
Open
fix(lib): restore automatic hashtag creation for unknown tags#673antontranelis wants to merge 7 commits intomainfrom
antontranelis wants to merge 7 commits intomainfrom
Conversation
Two issues were preventing hashtags from being automatically added to the database: 1. **useTags.tsx - Stale closure bug**: The `addTag` function was using `tags` and `api` from the closure scope, which were stale when called. Fixed by using `useRef` for both `apiRef` and `tagsRef`, ensuring the function always accesses current values. 2. **PopupView.tsx - Tag creation in render**: New tags were detected inside the render `.map()` function with side effects - an anti-pattern. Moved tag processing to a dedicated `processItemsTags` function in useTags hook, called via useEffect when items are loaded. Changes: - Added `processItemsTags(items: Item[])` function to useTags hook - Added `useProcessItemsTags` export hook - Cleaned up PopupView.tsx to use the new hook via useEffect - Removed side effects from render function Now when items are loaded, any hashtags that don't exist in the database are automatically created with a random color. Co-Authored-By: Claude Opus 4.5 <[email protected]>
e483672 to
d3e7b7a
Compare
Add comprehensive tests for the useTags hook covering: - Tag state management (initialization, adding, deduplication) - API integration (persistence, existing tag handling, stale closure fix) - Hashtag detection & auto-creation (extraction, skipping known tags, deduplication) - Tag retrieval (text matching, offers/needs tags, case-insensitive matching) 15 test cases covering the hashtag auto-creation feature addressed in PR #673.
Collaborator
|
augment review |
🤖 Augment PR SummarySummary: Restores automatic creation/persistence of unknown hashtags by fixing stale state access in the tag manager and reintroducing a missing persistence step when items/tags finish loading. Changes:
Technical Notes: Auto-created tags use 🤖 Was this summary useful? React with 👍 or 👎 |
- Fix stale tagCount in setTagApi: use result.length instead of captured tagCount to determine allTagsLoaded (removes stale closure) - Fix duplicate API calls in addTag: early-return on existing tags and eagerly update tagsRef to prevent same-tick duplicate createItem calls - Fix act() warnings in tests: use await act() for async setTagApi calls so microtasks flush within act boundary - Remove now-unused eslint-disable for react-hooks/exhaustive-deps
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
useTags.tsxthat preventedaddTagfrom accessing current stateuseEffectinPopupView.tsxto persist newly detected hashtags to the databaseProblem
Hashtags in item text that didn't exist in the database were not being automatically created. For example,
#networkingwould appear as plain black text instead of being recognized as a hashtag with a color.Root Causes
1. Stale Closure in
addTag(useTags.tsx)The
addTagfunction usedtagsandapifrom the closure scope, which were stale when the function was called:2. Missing Persistence (PopupView.tsx)
New tags were detected and collected in
newTagsToAddstate, but never actually persisted:Solution
useTags.tsx
useRefforapiRefandtagsRefto always access current valuesaddTaginuseCallbackwith empty dependenciesPopupView.tsx
useAddTaghookuseEffectthat callsaddTagfor each new tag whennewTagsToAddchangesTest plan
#testnewtag)🤖 Generated with Claude Code