[WIKI-770] fix: update editor ref after editor ready
Description
improve how the editor reference (editorRef) is managed and initialized, especially when the editor is ready.
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
Screenshots and Media (if applicable)
https://github.com/user-attachments/assets/fe2cca22-0821-416b-8ebf-29fc321e84ac
Test Scenarios
References
Summary by CodeRabbit
-
Refactor
- Enhanced editor reference management and command execution in the text editor component to improve toolbar interaction handling.
Walkthrough
The editor reference handling is refactored from relying on a forwarded ref to using local state. A handleEditorReady callback initializes the local editorRef state when the editor mounts, which is then used by toolbar components to execute commands instead of accessing the forwarded ref directly.
Changes
| Cohort / File(s) | Summary |
|---|---|
Editor Reference State Management apps/web/core/components/editor/lite-text/editor.tsx |
Introduces local editorRef state initialized to null and adds handleEditorReady callback to populate it when the editor is ready; replaces forwarded ref access with local state in toolbar command execution flows via LiteToolbar and IssueCommentToolbar |
Sequence Diagram(s)
sequenceDiagram
participant Editor as LiteTextEditorWithRef
participant Handler as handleEditorReady
participant State as editorRef State
participant Toolbar as Toolbar Components
Editor->>Editor: Component mounts
Editor->>Handler: Editor ready event fires
Handler->>State: Set editorRef with editor instance
State->>Toolbar: editorRef state available
Toolbar->>Toolbar: User triggers toolbar action
Toolbar->>State: Access editorRef
State->>Toolbar: Return editor reference
Toolbar->>Editor: executeMenuItemCommand()
Estimated Code Review Effort
π― 2 (Simple) | β±οΈ ~10 minutes
- Single file with focused state management refactor
- Clear pattern: forwarded ref β local state initialization
- Primary concern: verify toolbar interactions work correctly with the new state dependency; ensure no race conditions between editor ready callback and toolbar access
Poem
π° A hop and a state, the ref finds its place,
No longer adrift in the forwarded space,
When editors wake, the commands take flight,
Local state captures the moment just right!
Pre-merge checks and finishing touches
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
β Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The title clearly and concisely summarizes the main change: updating the editor ref after the editor is ready. |
| Description check | β Passed | The description covers the main change and includes type of change checkbox, but lacks test scenarios and issue references despite template sections for these. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
fix-comment_cta
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.