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

Support WebSockets (as an alternative to SSE) #1028

Open
wwwillchen opened this issue Oct 13, 2024 · 0 comments
Open

Support WebSockets (as an alternative to SSE) #1028

wwwillchen opened this issue Oct 13, 2024 · 0 comments

Comments

@wwwillchen
Copy link
Collaborator

wwwillchen commented Oct 13, 2024

Context

Right now Mesop uses Server-sent Events (SSEs) which have been good, as they are widely supported and relatively straightforward implementation-wise, however there's some limitations with more advanced use cases.

Motivation

There's a key problem here which is that our core rendering loop in handling long user interactions (via generator) assumes that you can generate tree diffs from the previous tree in your context (i.e. SSE request).

Example use case

With concurrent updates, you can run into strange bugs like the following:

  • SSE Request 1 (long) - after 4 seconds, it tries to update the tree by adding component A
  • SSE request 2 (short) - after 1 second, it tries to update the tree by adding component A

In this case you will end up erroneously adding component A twice because the first SSE request (which takes longer) still sent a component tree diff to add component A even though it was added by another request (that completed sooner). I ran into this issue in my personal app and it's not very intuitive to debug and points to a core issue which is that concurrent updates across multiple stateless server instances is bound to be problematic. Instead, I think having a model where there's multiple concurrent updates getting funneled into the same stateful server instance is more robust.

Implementation plan

I have a PR #1027 which prototypes support but it's failing many of the test cases. Once I take a closer look and can get most/if not all of them passing, I think we can add a new mode to Mesop, e.g. MESOP_WEB_SOCKETS_ENABLED. I think this will always be an opt-in because our current setup (SSE) is quite robust and works for most use cases.

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

No branches or pull requests

1 participant