Skip to content

fix: Note is sometimes updates while opening#268

Merged
vitonsky merged 4 commits into
DeepinkApp:masterfrom
katsyuta:258-fix-note-is-sometimes-update
Apr 16, 2026
Merged

fix: Note is sometimes updates while opening#268
vitonsky merged 4 commits into
DeepinkApp:masterfrom
katsyuta:258-fix-note-is-sometimes-update

Conversation

@katsyuta

@katsyuta katsyuta commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #258

When user open note, the RichEditor component receive the note text as property.
The serializer plugin react on that as on update, and serialize the input.
In case the input and output are different the change is triggered.
The output may be different because of different implementation of markdown parser/serializer.
It happens mostly when markdown contains advanced constructions like title for link in your example.

In scope of this PR we introduce the code to prevent serialization of any input except user input via keyboard into editor component.

Technically we mark any other inputs via special tag and skip serialization for changes with that tag.


The root problem: When we receive the external value - we update editor, this trigger the OnChangePlugin witch update external value and then note updated. But value is changed not user initiated. I suggests ignore this update and not update note in this case

The current flow in MarkdownSerializePlugin:
External value update:

  • Effect triggers
  • Check if value equals local ref - if equal, early return (ignore own update)
  • Update editor

OnChangePlugin triggers:

  • Serialize markdown to string and save result to local ref
  • Update external state

User made no real changes, but the note was updated.

Fix:
Tag editor updates made by us in useEffect and ignore them in OnChangePlugin.

Updated flow in MarkdownSerializePlugin:

External value changed:

  • Effect triggers
  • Check if value equals local ref — if equal, early return
  • Update editor with special tag

OnChangePlugin triggers:

  • Check if update has special tag — if so, skip state update (not a user-initiated change)
  • Serialize editor nodes to markdown string and save result to local ref
  • Update external state

Summary by CodeRabbit

  • Bug Fixes
    • Fixed markdown editor synchronization so programmatic/internal editor updates no longer trigger the debounced sync to external state. Only direct user edits now cause markdown→prop syncing, reducing redundant updates, preventing spurious change events, and improving overall change handling and performance.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ff54826-4544-414f-acb5-7d241e7b493f

📥 Commits

Reviewing files that changed from the base of the PR and between d2724e6 and 34b863e.

📒 Files selected for processing (1)
  • src/features/NoteEditor/RichEditor/plugins/Markdown/MarkdownSerializePlugin.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/NoteEditor/RichEditor/plugins/Markdown/MarkdownSerializePlugin.tsx

📝 Walkthrough

Walkthrough

The MarkdownSerializePlugin now tags its programmatic editor.update with { tag: 'non-user-update' }. The OnChangePlugin callback was extended to receive tags and immediately ignores change events containing 'non-user-update', preventing programmatic/editor-effect updates from triggering serialization/sync.

Changes

Cohort / File(s) Summary
Markdown Serialization Update Filtering
src/features/NoteEditor/RichEditor/plugins/Markdown/MarkdownSerializePlugin.tsx
editor.update calls now include { tag: 'non-user-update' }. OnChangePlugin handler signature accepts tags and early-returns when tags contains 'non-user-update', avoiding syncValue() / debounced onChanged for programmatic updates.

Sequence Diagram(s)

sequenceDiagram
    participant UI as User
    participant Editor as Lexical Editor
    participant MDPlugin as MarkdownSerializePlugin
    participant OnChange as OnChangePlugin
    participant Sync as Serializer/onChanged

    UI->>Editor: open note (user action)
    Editor->>MDPlugin: effect triggers programmatic update
    MDPlugin->>Editor: editor.update(..., { tag: "non-user-update" })
    Editor->>OnChange: emit change event (includes tags)
    OnChange->>OnChange: sees tags.has("non-user-update")
    OnChange-->>Sync: (no call) — early return, skip syncValue/onChanged
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • vitonsky

Poem

🐰 I hop in code with a careful nudge,
I mark my moves "non-user-update" so snug,
No phantom edits topple the list,
Quiet notes stay where they sit,
A tiny hop, a tidy shrug.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main fix: preventing unintended note updates when opening notes due to serialization differences.
Linked Issues check ✅ Passed The PR implements the required fix by tagging editor updates from the external-value effect and filtering non-user-initiated changes in OnChangePlugin, directly addressing issue #258.
Out of Scope Changes check ✅ Passed All changes are focused on the MarkdownSerializePlugin to prevent unintended updates during note opening, with no extraneous modifications outside the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@katsyuta

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@katsyuta
katsyuta marked this pull request as ready for review March 24, 2026 11:47
@katsyuta
katsyuta force-pushed the 258-fix-note-is-sometimes-update branch from f51ba0a to 8147907 Compare April 11, 2026 10:52
@katsyuta
katsyuta requested a review from vitonsky April 14, 2026 14:57
Comment thread src/features/NoteEditor/RichEditor/plugins/Markdown/MarkdownSerializePlugin.tsx Outdated
@katsyuta
katsyuta force-pushed the 258-fix-note-is-sometimes-update branch from 53a897f to 34b863e Compare April 16, 2026 14:23
@vitonsky
vitonsky merged commit 492d4c6 into DeepinkApp:master Apr 16, 2026
9 checks passed
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.

Note is sometimes updates while opening

2 participants