-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
π fix: topic renaming input focus issue in context menu #11323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "lobe-2838-contextmenu-\u7EC4\u4EF6\u91CD\u547D\u540D\u4E0D\u751F\u6548"
Conversation
Fixes LOBE-2838 This commit resolves the issue where the input field wasn't properly focused when renaming topics through the context menu. Changes: - Created FocusableInput component that ensures input focus using queueMicrotask - Replaced autoFocus prop with proper ref-based focus management - Simplified onBlur handler logic - Removed duplicate toggleEditing call from handleUpdate The queueMicrotask approach ensures the focus happens after the Popover has fully rendered and positioned itself.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the topic renaming popover to use a new ref-based FocusableInput component with microtask-scheduled focusing, simplifies blur/update handling, and centralizes the toggleEditing lifecycle around popover open state. Sequence diagram for topic renaming popover focus and lifecyclesequenceDiagram
actor User
participant TopicItem
participant Editing
participant Popover
participant FocusableInput
participant EventLoop
participant ChatStore
User->>TopicItem: Open context menu and click Rename
TopicItem->>Editing: set editing true
Editing->>Popover: render with open true
Popover->>FocusableInput: render input
FocusableInput->>EventLoop: queueMicrotask(focusInput)
EventLoop->>FocusableInput: run focusInput()
FocusableInput->>FocusableInput: ref.current.input.focus()
User->>FocusableInput: Type new title
FocusableInput->>Editing: onChange(newValue)
Editing->>Editing: setNewTitle(newValue)
User->>Popover: Close popover or click outside
Popover->>Editing: onOpenChange(false)
Editing->>Editing: handleUpdate()
alt title changed
Editing->>ChatStore: updateTopicTitle(id, newTitle)
end
Editing->>Editing: toggleEditing(false)
Class diagram for FocusableInput and Editing componentsclassDiagram
class FocusableInput {
+InputProps props
-InputRef ref
+useEffectFocusWithQueueMicrotask()
}
class Editing {
+string id
+string title
+function toggleEditing(visible)
-string newTitle
-boolean editing
-function setNewTitle(value)
-function handleUpdate()
}
class ChatStore {
+function updateTopicTitle(id, newTitle)
}
class Popover {
+boolean open
+function onOpenChange(open)
+FocusableInput content
}
class Input {
+function focus()
}
FocusableInput --> Input : wraps
Editing --> FocusableInput : renders
Editing --> Popover : configures
Editing --> ChatStore : uses
Popover o--> FocusableInput : content
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
TestGru AssignmentSummary
Tip You can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- In
FocusableInput, youβre unconditionally settingref={ref}, which means anyrefpassed in viaInputPropswill be ignored; if you intend this to be reusable, consider usingforwardRefand focusing the forwarded ref instead so callers can still access the input ref. - The
handleUpdatecallback still liststoggleEditingin its dependency array even though it no longer uses it; you can safely remove that dependency to avoid unnecessary re-creations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `FocusableInput`, youβre unconditionally setting `ref={ref}`, which means any `ref` passed in via `InputProps` will be ignored; if you intend this to be reusable, consider using `forwardRef` and focusing the forwarded ref instead so callers can still access the input ref.
- The `handleUpdate` callback still lists `toggleEditing` in its dependency array even though it no longer uses it; you can safely remove that dependency to avoid unnecessary re-creations.
## Individual Comments
### Comment 1
<location> `src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Editing.tsx:64-67` </location>
<code_context>
- handleUpdate();
- toggleEditing(false);
- }}
+ onBlur={handleUpdate}
onChange={(e) => setNewTitle(e.target.value)}
onClick={(e) => e.stopPropagation()}
</code_context>
<issue_to_address>
**issue (bug_risk):** `handleUpdate` is now invoked from both `onBlur` and `onOpenChange`, which can lead to duplicated updates.
When the input blurs, the popover will likely close and fire `onOpenChange(false)`, causing `handleUpdate` to run twice while `editing` is still `true`. This can result in duplicate `updateTopicTitle` calls for a single edit. To avoid this, either restore `toggleEditing(false)` inside `handleUpdate`, remove the `handleUpdate` call from `onOpenChange` and rely solely on `onBlur`, or make `handleUpdate` idempotent for a given `newTitle` (e.g., by updating local `editing` state or memoizing).
</issue_to_address>Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an input focus issue when renaming topics through the context menu by implementing a custom FocusableInput component that uses queueMicrotask to ensure focus is applied after the Popover has fully rendered.
- Created
FocusableInputcomponent with ref-based focus management usingqueueMicrotask - Simplified event handlers by removing duplicate
toggleEditing(false)calls - Cleaned up the
onBlurhandler to only callhandleUpdate
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
| toggleEditing(false); | ||
| }, [newTitle, title, id, updateTopicTitle, toggleEditing]); |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toggleEditing is included in the dependency array but is never used within the handleUpdate function. This can be removed from the dependency array to avoid unnecessary re-creation of the callback.
| }, [newTitle, title, id, updateTopicTitle, toggleEditing]); | |
| }, [newTitle, title, id, updateTopicTitle]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ff461bef2
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <FocusableInput | ||
| defaultValue={title} | ||
| onBlur={() => { | ||
| handleUpdate(); | ||
| toggleEditing(false); | ||
| }} | ||
| onBlur={handleUpdate} | ||
| onChange={(e) => setNewTitle(e.target.value)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close rename popover on blur to avoid stuck editing
In Editing.tsx, onBlur now only runs handleUpdate without closing editing. If the user tabs away or focus is moved programmatically (no outside click), onOpenChange wonβt fire and topicRenamingId stays set, leaving the Popover open and the item disabled until a click occurs. This is a regression from the previous blur behavior and is especially noticeable for keyboard users; consider calling toggleEditing(false) on blur or otherwise closing on focus loss.
Useful? React with πΒ / π.
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #11323 +/- ##
=========================================
Coverage 76.10% 76.10%
=========================================
Files 1128 1128
Lines 86332 86332
Branches 12138 9784 -2354
=========================================
Hits 65699 65699
Misses 20557 20557
Partials 76 76
Flags with carried forward coverage won't be shown. Click here to find out more.
π New features to boost your workflow:
|
|
β€οΈ Great PR @Innei β€οΈ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world. |
## [Version 2.0.0-next.238](v2.0.0-next.237...v2.0.0-next.238) <sup>Released on **2026-01-08**</sup> #### β¨ Features - **misc**: Change the klavis Linear to LobeHub oauth Linear. #### π Bug Fixes - **misc**: Topic renaming input focus issue in context menu. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Change the klavis Linear to LobeHub oauth Linear, closes [#11339](#11339) ([ec8ff26](ec8ff26)) #### What's fixed * **misc**: Topic renaming input focus issue in context menu, closes [#11323](#11323) ([dd065fc](dd065fc)) </details> <div align="right"> [](#readme-top) </div>
|
π This PR is included in version 2.0.0-next.238 π The release is available on: Your semantic-release bot π¦π |
## [Version 1.150.0](v1.149.0...v1.150.0) <sup>Released on **2026-01-08**</sup> #### β» Code Refactoring - **memory-user-memory**: Migrated to use typescript module for prompts. #### β¨ Features - **image**: Improve image generation with new models and bug fixes. - **notebook**: Add i18n, Inspector and Streaming components. - **ui**: Move new topic button to navigation panel. - **misc**: Add browser compatibility detection and fallback page, add the lobehub market tools servers, add the twitter lobehub skill, change the klavis Linear to LobeHub oauth Linear. #### π Bug Fixes - **editor**: Fix slash command codeblock not working. - **onboarding**: Prevent step overflow and misc improvements. - **provider-config**: Update isFetchOnClient Switch component. - **misc**: Add separate border-radius for bottom-right corner on macOS 26 Chrome, correct BrandTextLoading position after removing SSG CSS-in-JS injection, fix edit rich render codeblock, topic renaming input focus issue in context menu, update desktop onboarding privacy description, update mobile topicRouter import path to lambda directory. #### π Styles - **misc**: Update i18n. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **memory-user-memory**: Migrated to use typescript module for prompts, closes [lobehub#11344](https://github.com/jaworldwideorg/OneJA-Bot/issues/11344) ([902cfe5](902cfe5)) #### What's improved * **image**: Improve image generation with new models and bug fixes, closes [lobehub#11311](https://github.com/jaworldwideorg/OneJA-Bot/issues/11311) ([4fc03bb](4fc03bb)) * **notebook**: Add i18n, Inspector and Streaming components, closes [lobehub#11212](https://github.com/jaworldwideorg/OneJA-Bot/issues/11212) ([f7dc54f](f7dc54f)) * **ui**: Move new topic button to navigation panel, closes [lobehub#11325](https://github.com/jaworldwideorg/OneJA-Bot/issues/11325) ([3d6b399](3d6b399)) * **misc**: Add browser compatibility detection and fallback page, closes [lobehub#11309](https://github.com/jaworldwideorg/OneJA-Bot/issues/11309) ([8be32c2](8be32c2)) * **misc**: Add the lobehub market tools servers, closes [lobehub#11315](https://github.com/jaworldwideorg/OneJA-Bot/issues/11315) ([a4003a3](a4003a3)) * **misc**: Add the twitter lobehub skill, closes [lobehub#11342](https://github.com/jaworldwideorg/OneJA-Bot/issues/11342) ([503acb3](503acb3)) * **misc**: Change the klavis Linear to LobeHub oauth Linear, closes [lobehub#11339](https://github.com/jaworldwideorg/OneJA-Bot/issues/11339) ([ec8ff26](ec8ff26)) #### What's fixed * **editor**: Fix slash command codeblock not working, closes [lobehub#11321](https://github.com/jaworldwideorg/OneJA-Bot/issues/11321) ([f9a35eb](f9a35eb)) * **onboarding**: Prevent step overflow and misc improvements, closes [lobehub#11322](https://github.com/jaworldwideorg/OneJA-Bot/issues/11322) ([8586fd4](8586fd4)) * **provider-config**: Update isFetchOnClient Switch component, closes [lobehub#11215](https://github.com/jaworldwideorg/OneJA-Bot/issues/11215) ([5bb038b](5bb038b)) * **misc**: Add separate border-radius for bottom-right corner on macOS 26 Chrome, closes [lobehub#11287](https://github.com/jaworldwideorg/OneJA-Bot/issues/11287) ([544931a](544931a)) * **misc**: Correct BrandTextLoading position after removing SSG CSS-in-JS injection, closes [lobehub#11312](https://github.com/jaworldwideorg/OneJA-Bot/issues/11312) ([0de4eb8](0de4eb8)) * **misc**: Fix edit rich render codeblock, closes [lobehub#11303](https://github.com/jaworldwideorg/OneJA-Bot/issues/11303) ([5338170](5338170)) * **misc**: Topic renaming input focus issue in context menu, closes [lobehub#11323](https://github.com/jaworldwideorg/OneJA-Bot/issues/11323) ([dd065fc](dd065fc)) * **misc**: Update desktop onboarding privacy description, closes [lobehub#11307](https://github.com/jaworldwideorg/OneJA-Bot/issues/11307) [lobehub#11308](https://github.com/jaworldwideorg/OneJA-Bot/issues/11308) ([58b10a2](58b10a2)) * **misc**: Update mobile topicRouter import path to lambda directory, closes [lobehub#11261](https://github.com/jaworldwideorg/OneJA-Bot/issues/11261) ([f591b77](f591b77)) #### Styles * **misc**: Update i18n, closes [lobehub#11297](https://github.com/jaworldwideorg/OneJA-Bot/issues/11297) ([4705abf](4705abf)) </details> <div align="right"> [](#readme-top) </div>
Fixes LOBE-2838 This commit resolves the issue where the input field wasn't properly focused when renaming topics through the context menu. Changes: - Created FocusableInput component that ensures input focus using queueMicrotask - Replaced autoFocus prop with proper ref-based focus management - Simplified onBlur handler logic - Removed duplicate toggleEditing call from handleUpdate The queueMicrotask approach ensures the focus happens after the Popover has fully rendered and positioned itself.
## [Version 2.0.0-next.238](lobehub/lobehub@v2.0.0-next.237...v2.0.0-next.238) <sup>Released on **2026-01-08**</sup> #### β¨ Features - **misc**: Change the klavis Linear to LobeHub oauth Linear. #### π Bug Fixes - **misc**: Topic renaming input focus issue in context menu. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Change the klavis Linear to LobeHub oauth Linear, closes [lobehub#11339](lobehub#11339) ([ec8ff26](lobehub@ec8ff26)) #### What's fixed * **misc**: Topic renaming input focus issue in context menu, closes [lobehub#11323](lobehub#11323) ([dd065fc](lobehub@dd065fc)) </details> <div align="right"> [](#readme-top) </div>
π Summary
Fixes the issue where the input field wasn't properly focused when renaming topics through the context menu.
Resolves LOBE-2838
π Changes
FocusableInputcomponent that ensures input focus usingqueueMicrotaskautoFocusprop with proper ref-based focus managementonBlurhandler logictoggleEditingcall fromhandleUpdateπ‘ Technical Details
The
queueMicrotaskapproach ensures the focus happens after the Popover has fully rendered and positioned itself, which is necessary for the input to receive focus correctly in the context menu scenario.β Test Plan
Summary by Sourcery
Ensure topic rename inputs in the sidebar context menu receive focus reliably and streamline the editing lifecycle handling.
Bug Fixes:
Enhancements: