Fix: Force cache refresh for advanced text editors #347
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Bug
I found that GhostText doesn't update text boxes correctly after the first edit. After debugging with Emacs atomic-chrome, I discovered GhostText was sending cached/stale text instead of reading the current text box content.
What Happens
Example from my debugging
I spent hours debugging this with Emacs atomic-chrome and found two critical issues:
Experiment 1 - Manual Edit Detection:
text=[this is second string](its cached value)text=[this is second string, this is my manual added string outside atomic](actual content)Experiment 2 - State Divergence:
text=[this is third string]to Emacs!This proved GhostText has internal state ("third string") that's completely disconnected from Chrome's actual DOM content ("second string"). After the first edit, GhostText loses its ability to update Chrome but doesn't know it, and keeps using its stale cached values.
WebSocket debugging showed:
The only workaround was refreshing the page between edits, which resets GhostText's connection to the DOM.
The Fix
For advanced editors (like CodeMirror, iPython notebooks, etc.), GhostText needs to request fresh content before sending. I added code to:
gt:getevent to refresh the cached valueTesting
I tested this with:
Now it correctly reads the current content every time instead of using stale cache.
Why This Matters
Without this fix, you have to refresh the page between edits when using GhostText with any JavaScript-enhanced text editor. Super annoying when you're trying to quickly edit notebook cells or code comments.
The debugging process with Emacs atomic-chrome helped identify that the issue was GhostText sending wrong data, not a problem with the editor connection.
Fix stale cache issue for advanced text editors
GhostText was sending cached values instead of current text box
content on reconnection. Added cache refresh for AdvancedTextWrapper
to request fresh values before sending.
Tested with iPython notebooks where the bug was most noticeable.