-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
refactor(hmr): keep buffer implementation internal, expose queueUpdate #15486
Conversation
Run & review this pull request in StackBlitz Codeflow. |
packages/vite/src/shared/hmr.ts
Outdated
public addBuffer(message: string): void { | ||
this.buffer.push(message) | ||
} | ||
|
||
public sendCustomMessages(): void { | ||
if (this.connection.isReady()) { | ||
this.buffer.forEach((msg) => this.connection.send(msg)) | ||
this.buffer = [] | ||
} | ||
} |
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.
Should this be named something like queue(message)
and flush()
? And maybe also expose a send(message)
that does a queue(message); flush()
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.
From the naming side, they definitely need to have more words because HMR client is about handling module reloading as a whole, not just about communication. So I am fine with queueMessage
(especially because we have queueUpdate
), but I am not sure what is the purpose of a separate flush method
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 mean renaming sendCustomMessages()
to flush()
(or flushMessages()
). As in https://nodejs.org/api/http.html#requestflushheaders. Not having an extra method. The extra would be sendMessages()
that does a queueMessage()
then flushMessages()
. For example, here you have:
this.hmrClient.addBuffer(JSON.stringify({ type: 'custom', event, data }))
this.hmrClient.sendCustomMessages()
that could be
this.hmrClient.sendMessage(JSON.stringify({ type: 'custom', event, data }))
if we have the three methods (sendMessage
, queueMessage
, flushMessages
)
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.
Updated
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.
Updated again 😄
7eb78a9
to
a561855
Compare
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.
Looks like a clean refactor!
When implementing #12165, I noticed a lot of repetition that I thought might be an architectural problem. I am creating a separate PR to make it easier to review.
Description
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).