fix: Google Docs bridge and replaceText issue for the popup suggestion - #3847
Open
Yuvi-raj-P wants to merge 3 commits into
Open
fix: Google Docs bridge and replaceText issue for the popup suggestion#3847Yuvi-raj-P wants to merge 3 commits into
Yuvi-raj-P wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issues
Hopefully should close #2995
Description
Problem: When you click a linted word on google docs, the suggestions and the grammar check works however when you go to the popup to replace the error with harper suggestion the error does not get replaced.
Solution:
From @abhishekDeshmukh74, initially thought race conditions are what causing the issue. So I went towards the direction of race condition and though applySuggestion is called then immediately followed by close() with no waiting is the problem. I developed a fix which fell short and of course did not work. Later I found that popup closes before the replacing even happens and though that was the race condition because if popover has already closed focus will be moved off the docs iframe which resulted in for activeElement therefore insertText and synthetic paste event did nothing (cherry on top, all errors were silently dying as nothing was being reported). Was still thinking about race conditions so continued to develop a promise chain to await all the way until replacement was done. But it was not the solution. However, the promise chain was left as it's good to have and minimizes any race happening making the process more consistent.
With race conditions not the main issue, I later went towards the null issue with the active element. With a decent amount of debugging and Claude, I came to the conclusion that the active element was not the right element we needed for the replacement. This was due to the clicking function of the suggestion button in the popup using the native browser’s button click method. Chrome's default mousedown behavior focuses the clicked button before the onclick handler runs which pulls the page focus off the iframe to popup button (the suggestion). By the time replaceTextRequest reads the activeElement it could not find the right element to dispatch the replacement to as it fell back to the replacement silently died. The execCommand and the paste dispatch however reported success with no errors which led to this whole rabbit hole of a problem from a simple button click.
td;lr:
Please let me know if issues presist, it did work on my instance (Chrome/Apple silicon), i am just too lazy to record a demo and convert it and all that. First pr on the repo :) and please let me know of any silly comments on repo files those are for me.
How Has This Been Tested?
Build test. Built the Chrome Extension onto chrome and tested it against some text in google docs.
Since the test was purely done with chrome, I am not sure if this works with, for example, Firefox please someone let me know.
AI Disclosure
Checklist