Skip to content
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

afterUnloadDocument hook #656

Merged
merged 3 commits into from
Jul 29, 2023

Conversation

georeith
Copy link
Collaborator

@georeith georeith commented Jul 20, 2023

This PR adds an afterUnloadDocument hook that runs whenever a previously loaded document is removed by the server, for any reason.

The motivation for adding this feature is because I monitor documents being opened and closed in a load balancer that speaks to an extension and I noticed the load balancer was not removing all documents for some reason when I listen to it like this:

{
  async afterLoadDocument({
    documentName,
  }: onLoadDocumentPayload): Promise<void> {
   addToLoadBalancer(documentName);
  }

  async onDisconnect({
    documentName,
    clientsCount,
  }: onDisconnectPayload): Promise<void> {
    if (clientsCount === 0) {
      removeFromLoadBalancer(documentName);
    }
  }
}

I also fixed up the type of the hooks function so that you can no longer pass an incorrect payload that does not match the exact one for that hook specified in the types. There were a couple of cases where they didn't match and I had to fix those. This was to prevent issues such as #641 in the future.

@georeith
Copy link
Collaborator Author

@janthurau just bringing to your attention.

Copy link
Collaborator

@janthurau janthurau left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this!! :-)

@janthurau janthurau merged commit 508e92e into ueberdosis:main Jul 29, 2023
3 checks passed
janthurau pushed a commit to YousefED/hocuspocus that referenced this pull request Aug 12, 2023
* add after-unload-document hook

* test

* fix URLSearchParams type
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.

None yet

2 participants