Skip to content

Commit c06d8da

Browse files
mkg20001claude
andcommitted
fix(ui): update CURRENT_CATEGORY directly during render
Replace use_effect with direct update since use_effect captures values at creation time and doesn't re-run on prop changes. Compare category_id before writing to avoid unnecessary updates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8681cd9 commit c06d8da

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

ui/src/components/posts_view.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,24 @@ pub fn PostsView(
118118
// Get content
119119
let (categories, posts) = get_content(category_id.as_ref(), &all_messages);
120120

121-
// Set CURRENT_CATEGORY for auto-parenting posts/categories
121+
// Update CURRENT_CATEGORY for auto-parenting posts/categories
122+
// Compare before writing to avoid unnecessary updates
122123
{
123-
let current_cat = current_category.clone();
124-
use_effect(move || {
125-
if let Some(cat) = current_cat.as_ref() {
126-
*CURRENT_CATEGORY.write() = CurrentCategoryContext {
127-
category_id: Some(cat.message_id.clone()),
128-
category_name: cat.category_name.clone(),
129-
author_name: Some(cat.author_name.clone()),
130-
};
131-
} else {
132-
*CURRENT_CATEGORY.write() = CurrentCategoryContext::default();
124+
let new_context = if let Some(cat) = current_category.as_ref() {
125+
CurrentCategoryContext {
126+
category_id: Some(cat.message_id.clone()),
127+
category_name: cat.category_name.clone(),
128+
author_name: Some(cat.author_name.clone()),
133129
}
134-
});
130+
} else {
131+
CurrentCategoryContext::default()
132+
};
133+
134+
let current = CURRENT_CATEGORY.read();
135+
if current.category_id != new_context.category_id {
136+
drop(current);
137+
*CURRENT_CATEGORY.write() = new_context;
138+
}
135139
}
136140

137141
// Clear CURRENT_CATEGORY when leaving

0 commit comments

Comments
 (0)