-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support multiple windows #5070
support multiple windows #5070
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @robfig! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
@@ -39,19 +39,27 @@ import { | |||
const TEXT_MUTATION_VARIANCE = 100; | |||
|
|||
let isProcessingMutations = false; | |||
let lastTextEntryTimeStamp = 0; | |||
const lastTextEntryTimeStamp_ = new WeakMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the practical use cases of tracking entry timestamp by window?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event.timeStamp
is milliseconds since the time origin of the window, as is performance.now()
, it is NOT a unix timestamp or wall time.. I found that surprising too.
Different windows have different time origins, so the timestamp of a events in different windows are not comparable, and the performance
object of the window where an event originated must be used to measure time elapsed from that timestamp. As a result, we need separate timestamps per window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zurfyx do you mind reviewing this PR? It's not so many lines of code and fixes severe bugs for us. I have our version patched but would be great to remove the patch and be able to upgrade easily again. Thanks
Thank you for the review. I will look at merging in your comments and rebasing to get it current. We have a multi-window Electron app, and we began by having each window be its own renderer process. That turned out to cause performance issues, and we found that single process + multiple windows was much faster / lighter. I'm afraid I don't have more information to share about it beyond what was in the description ^. The app I'm referring to is https://ro.am/ |
This commit fixes 3 issues 1. The lastTextInputTimeStamp was not being updated on popout windows because the listener was not being added. 2. The time origin of event.timestamp and performance.now was not the same without using the specific window. 3. Event classes (KeyboardEvent, ClipboardEvent) are defined on each window, so instanceof checks need to check against the one defined on the window where the event originates. There was an `objectKlassEquals` helper for this purpose already, so I updated a couple places to use it. I encountered these bugs in our Electron app. It opens a new window via window.open() and renders to it from the parent window. As a result, there are multiple window objects that can host Lexical editors and one JS environment. I haven't found much documentation on multi-window setups besides this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms
Thank you for iterating on this! Seems like this test is consistently failing? |
Thanks @zurfyx , it was because of a mistake I made when rebasing. Just pushed a commit which should fix the test. Thanks |
: (event as ClipboardEvent).clipboardData; | ||
if ( | ||
clipboardData != null && | ||
($isRangeSelection(selection) || $isTableSelection(selection)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to specify the type of selection now? We don't want to import @lexical/table
here, we intentionally isolated this module so that you can only pay the bundle size cost when the product needs tables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we don't. The code it was originally based on had this condition, so I kept it. I see that it was subsequently removed. Removed it from my change as well.
Hi @zurfyx , gentle ping that this PR is fully updated for all comments you've made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to Gerard and he's good with this
Woo hoo! Thanks guys |
This commit fixes 4 issues
The lastTextInputTimeStamp was not being updated on
popout windows because the listener was not being added.
The time origin of event.timestamp and performance.now
was not the same without using the specific window.
Event classes (KeyboardEvent, ClipboardEvent) are defined
on each window, so instanceof checks need to check against
the one defined on the window where the event originates.
I converted these to use e.g. "clipboardData" in event instead.
The rootElement.ownerDocument selectionchange listener
needs to be added on each distinct document.
I encountered these bugs in our Electron app. It opens a new window
via window.open() and renders to it from the parent window. As a
result, there are multiple window objects that can host Lexical
editors and one JS environment.
I haven't found much documentation on multi-window setups online
besides this:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms
Fixes #5050