Skip to content

fix: persist sticky notes cache from memory on state changes - #3083

Open
amirbiron wants to merge 1 commit into
mainfrom
claude/fix-sticky-notes-persistence-mh25Y
Open

fix: persist sticky notes cache from memory on state changes#3083
amirbiron wants to merge 1 commit into
mainfrom
claude/fix-sticky-notes-persistence-mh25Y

Conversation

@amirbiron

Copy link
Copy Markdown
Owner

✨ תיאור קצר

הוספת קריאות ל-_persistCacheFromMemory() בנקודות קריטיות בזרימת הסנכרון כדי להבטיח שהמטמון המקומי (localStorage) יישמר עם המצב הנוכחי של ההערות בזיכרון.

📦 שינויים עיקריים

  • קוד (Frontend - JavaScript)

פירוט:

  • הוספת _persistCacheFromMemory() - מתודה חדשה שמאחסנת את כל ההערות מהזיכרון ל-localStorage
  • קריאה למתודה זו ב-4 מקומות קריטיים:
    1. בסוף _addPending() - לאחר הוספת הערה חדשה
    2. בתחילת _flushPendingKeepalive() - לפני שליחת keepalive
    3. בסוף _processPendingUpdates() - לאחר עיבוד עדכונים
    4. בסוף _sendUpdate() - לאחר שליחת עדכון

🧪 בדיקות

  • CI Required Checks: 🔍 Code Quality & Security; Unit Tests (3.11); Unit Tests (3.12)
  • השינוי הוא defensive - הוספת קריאות persist בנקודות בטוחות שכבר מטפלות בשגיאות
  • כל הקריאות החדשות עטופות ב-try/catch כדי למנוע השפעה על זרימת הקוד הקיימת

📝 סוג שינוי

  • fix: תיקון באג

✅ צ'קליסט

  • הקוד עוקב אחרי הסגנון הקיים
  • אין סודות/מפתחות בקוד
  • אין מחיקות מסוכנות

🧩 השפעות/סיכונים

  • השפעה חיובית: שיפור אמינות המטמון המקומי - הערות לא יאבדו במקרה של קריסה או סגירת דפדפן בזמן סנכרון
  • סיכון: זניח - קריאות persist נוספות עלולות להוסיף עומס קל על localStorage, אך כל קריאה עטופה ב-try/catch

🔗 קישורים

  • CI Required Checks: 🔍 Code Quality & Security; Unit Tests (3.11); Unit Tests (3.12)

https://claude.ai/code/session_01UCWnSj4UYXMzYYi4UFWHBa

ה-cache ב-localStorage לא התעדכן אחרי עריכת פתק דביק, מה שגרם
לכך שאחרי ריענון הדף הפתק הוצג ריק עד שה-API הגיב.

נוספה מתודה _persistCacheFromMemory שנקראת ב-4 מקומות:
- _queueSave (מיד עם עריכה)
- _performSaveBatch (אחרי batch save)
- _flushFor (אחרי שמירה בודדת)
- _flushPendingKeepalive (לפני סגירת דף)

https://claude.ai/code/session_01UCWnSj4UYXMzYYi4UFWHBa
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

🧯 Dangerous deletes guard report

Policy: see .cursorrules — dangerous deletions are blocked unless wrapped safely.

Summary:

  • Flagged findings (blocking): 0
    0
  • Excluded matches (not blocking): 15
  • Total matches (all files): 129

Flagged findings (file:line:snippet):
(none)

Excluded matches (by path pattern)
./webapp/static/js/md_preview.bundle.js.map:4:  "sourcesContent": ["// Markdown-it plugin to render GitHub-style task lists; see\n//\n// https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments\n// https://github.com/blog/1825-t … [truncated]
./README.md:842:find . -name "__pycache__" -exec rm -rf {} +
./node_modules/mermaid/dist/mermaid.min.js:1524:`,"getStyles"),c1e=RQe});var h1e={};dr(h1e,{diagram:()=>NQe});var NQe,f1e=N(()=>{"use strict";$ge();a1e();l1e();u1e();NQe={parser:Fge,db:n1e,renderer:o1e,styles:c1e}});var m1e,g1e=N(()=>{"use  … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs:1:var r={name:"mermaid",version:"11.12.0",description:"Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graph … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequen … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm/chunk-2M32CCKP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence d … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.core/chunk-KS23V3DP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence  … [truncated]
./node_modules/mermaid/dist/mermaid.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values for tr … [truncated]
./node_modules/mermaid/dist/mermaid.min.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values fo … [truncated]
./node_modules/katex/package.json:153:    "build": "rimraf dist/ && mkdirp dist && cp README.md dist && rollup -c --failAfterWarnings && webpack && node update-sri.js package dist/README.md",
./node_modules/katex/src/fonts/Makefile:139:	rm -rf pfa ff otf ttf woff woff2
./docs/Makefile:24:	rm -rf $(BUILDDIR)
./docs/DOCUMENTATION_GUIDE.md:453:rm -rf _build
./Dockerfile:42:    rm -rf /var/lib/apt/lists/*
./Dockerfile:121:    rm -rf /var/lib/apt/lists/*

@amirbiron

Copy link
Copy Markdown
Owner Author

סיכום

מתי הבאג התחיל?

מהיום הראשון - הפיצ'ר נוסף ב-commit 8414521 ולא שונה מאז. הבאג היה מעצם העיצוב הראשוני.

מה היה הבאג?

ב-sticky-notes.js, ה-localStorage cache לא התעדכן אחרי עריכת תוכן של פתק. הזרימה הייתה:

  1. טעינת דף → cache נשמר עם נתוני API ✅
  2. משתמש עורך פתק → שמירה לשרת ✅ → cache לא מתעדכן
  3. ריענון → cache מציג תוכן ישן (ריק!) → אחרי שה-API מגיב, התוכן מופיע

אם ה-API איטי או נכשל (רשת, session פג), הפתק נשאר ריק.

מה התיקון?

נוספה מתודה _persistCacheFromMemory() שמסנכרנת את כל הפתקים מהזיכרון ל-localStorage. היא נקראת ב-4 מקומות:

  • _queueSave - מיד כשהמשתמש עורך (כדי שגם לפני תגובת השרת, ה-cache מעודכן)
  • _performSaveBatch - אחרי batch save מוצלח
  • _flushFor - אחרי שמירה בודדת (blur)
  • _flushPendingKeepalive - לפני סגירת/ריענון הדף

@github-actions

Copy link
Copy Markdown

⏱️ Performance report

(No performance test durations collected. Mark tests with @pytest.mark.performance.)

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

const nextSeq = (this._pendingSeq.get(id) || 0) + 1;
this._pendingSeq.set(id, nextSeq);
} catch(_) {}
this._persistCacheFromMemory();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unbounded localStorage writes on every keystroke

Medium Severity

_persistCacheFromMemory() is called inside _queueSave, which fires on every textarea input event (every keystroke). This synchronously iterates all notes, runs JSON.stringify on the entire collection, and writes to localStorage on the main thread — on every single character typed. The existing _saveDebounced() on the next line was intentionally debounced at 500ms to avoid this exact kind of overhead. The persist call bypasses that debouncing entirely, potentially causing noticeable input lag when many notes exist.

Fix in Cursor Fix in Web

@sentry

sentry Bot commented Feb 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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