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

Provider.disconnect prevents subsequent provider.connect from working #782

Closed
jamesopti opened this issue Jan 27, 2024 · 1 comment · Fixed by #783
Closed

Provider.disconnect prevents subsequent provider.connect from working #782

jamesopti opened this issue Jan 27, 2024 · 1 comment · Fixed by #783
Assignees
Labels
bug Something isn't working

Comments

@jamesopti
Copy link
Collaborator

jamesopti commented Jan 27, 2024

Description
To manually want to close the websocket provider connection to Hocuspocus, you can call provider.disconnect

However, subsequently calling provider.connect does not properly reconnect the provider instance to the websocket instance and send the edits over the wire.

This appears to have been introduced in #727

Context/Questions

We've long used provider.disconnect() when a TipTap client backgrounds their browser tab so that our Hocuspocus instance doesn't end up with dozens or more unused websocket connections open for long periods of time. When the tab is foregrounded again, we call provider.connect()

Is there a better way to achieve this behavior?

Steps to reproduce the bug
Steps to reproduce the behavior:

  1. Setup a HocuspocusProvider instance
  2. Connect to Hocuspocus Server
  3. Make edits successfully
  4. Invoke providerInstance.disconnect()
  5. Wait a second
  6. Invoke providerInstance.connect()
  7. Make edits to document

Expected behavior
The edits are captured by the server

Actual behavior
The edits do not get sent

Environment?

  • Hocuspocus version: Since 2.7.0

Additional context
It appears you can workaround this by calling provider.configuration.websocket.attach(provider) instead (which calls provider.connect internally), but its a little yucky:

provider.configuration.websocketProvider.shouldConnect = true
provider.configuration.websocketProvider.attach(provider)

Possibly related to #594

@jamesopti
Copy link
Collaborator Author

I opened #783 to propose a fix for this. I don't LOVE it but I think it works. Open to other ideas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants