Skip to content

[WIKI-331] fix: editor ref issues while locking/unlocking page#6965

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
fix/editor-ref
Apr 24, 2025
Merged

[WIKI-331] fix: editor ref issues while locking/unlocking page#6965
sriramveeraghanta merged 1 commit intopreviewfrom
fix/editor-ref

Conversation

@Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Apr 24, 2025

Description

Fixes the editor ref issue with toolbar when locking/unlocking/performing other actions that change the editable state of the editor.

Summary by CodeRabbit

  • Bug Fixes
    • Improved synchronization of the editor reference to ensure it updates correctly when editability or related settings change.
    • Adjusted timing of internal page data assignment to enhance consistency when fetching page details.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 24, 2025

Walkthrough

The changes introduce a new useEffect hook in the editor page root component to ensure that the editor reference is updated asynchronously whenever relevant dependencies change. Additionally, the assignment of the pageInstance variable within the fetchPageDetails method in the project page store has been relocated to occur inside the runInAction block, slightly altering the timing of the assignment without affecting the method's logic or public interfaces.

Changes

File(s) Change Summary
web/core/components/pages/editor/page-root.tsx Added a useEffect hook to asynchronously update the editor reference when dependencies change.
web/core/store/pages/project-page.store.ts Moved pageInstance assignment inside the runInAction block in fetchPageDetails for scoping clarity.

Poem

A hop, a skip, a reference set anew,
With timing tweaked and actions in view.
The editor listens, the store aligns,
Rabbits rejoice in asynchronous signs!
With every change, the garden grows,
Code flows smoother—onward it goes!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dff176b and 31eab26.

📒 Files selected for processing (2)
  • web/core/components/pages/editor/page-root.tsx (1 hunks)
  • web/core/store/pages/project-page.store.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/core/components/pages/editor/page-root.tsx (1)
web/core/store/pages/project-page.ts (1)
  • isContentEditable (167-177)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
web/core/store/pages/project-page.store.ts (1)

254-264: Moving pageInstance assignment inside runInAction improves state consistency

This change properly moves the pageInstance variable assignment inside the runInAction block, ensuring that it's part of the same atomic transaction with the subsequent state updates. This helps prevent potential race conditions where the page instance might be stale if it was retrieved before entering the reactive context.

web/core/components/pages/editor/page-root.tsx (2)

77-81: Good solution for updating editor references during editability state changes

The added useEffect hook ensures that the editor reference is updated asynchronously whenever isContentEditable or setEditorRef changes. Using setTimeout with zero delay is a smart approach to defer the update to the next event loop, avoiding potential issues with component re-rendering cycles that might occur during lock/unlock operations.

This effectively solves the issue where the editor reference might become inconsistent when the page transitions between editable and non-editable states.


66-75: Existing editor reference init logic works well with the new effect

The handleEditorReady callback which sets the editor reference during initialization now works in tandem with the new useEffect. This ensures appropriate reference handling in both scenarios:

  1. Initial editor setup (through this callback)
  2. Re-establishing references during editability state changes (through the new effect)

The dependencies array [page.editorRef, setEditorRef] ensures this callback is recreated only when necessary.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Palanikannan1437 Palanikannan1437 changed the title fix: editor ref issues while locking/unlocking page [WIKI 331] fix: editor ref issues while locking/unlocking page Apr 24, 2025
@Palanikannan1437 Palanikannan1437 changed the title [WIKI 331] fix: editor ref issues while locking/unlocking page [WIKI-331] fix: editor ref issues while locking/unlocking page Apr 24, 2025
@makeplane
Copy link

makeplane bot commented Apr 24, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@sriramveeraghanta sriramveeraghanta merged commit 797f150 into preview Apr 24, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/editor-ref branch April 24, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants