Complex createResource management
I'm trying to write a way to handle a specific scenario where I wanted to use something like a
- when called on the server side, initializes a WebSocket connection to another server and returns a server side wrapper to the WebSocket ~ must be waited and cached
- when called on the client side, initializes a WebSocket connection to the SolidStart server and returns a client side wrapper to the WebSocket ~ must be cached
- when the user session id changes, the connection must be closed if the id becomes undefined or create a new one if the id is not the same as the previous one
- the wrapper contains the same functions on the server side and client side, allowing it to be used inside other resources
By cached I mean using the same resource in more than a single component does not create a second connection. I know there's a package named
The ideal approach would be something exactly like an
- the resource result is transferred to the client side for hydration, therefore the client WebSocket is not initialized
- the server side data must not be transferred to the client
I'm not sure if SolidStart provides a way to do this operation or if I should study the
Any help is appreciated!
const ws = useWebSocket(); that:- when called on the server side, initializes a WebSocket connection to another server and returns a server side wrapper to the WebSocket ~ must be waited and cached
- when called on the client side, initializes a WebSocket connection to the SolidStart server and returns a client side wrapper to the WebSocket ~ must be cached
- when the user session id changes, the connection must be closed if the id becomes undefined or create a new one if the id is not the same as the previous one
- the wrapper contains the same functions on the server side and client side, allowing it to be used inside other resources
By cached I mean using the same resource in more than a single component does not create a second connection. I know there's a package named
solid-cached-resource that solves this exact problem using resourcesThe ideal approach would be something exactly like an
createResource, wich can receive a signal to refetch, stores the current fetch state (loading, error or loaded) and has a deferStream option that makes the server await until the fetch is completed but I couldn't make it work using resources due to:- the resource result is transferred to the client side for hydration, therefore the client WebSocket is not initialized
- the server side data must not be transferred to the client
I'm not sure if SolidStart provides a way to do this operation or if I should study the
createResource source code to create something alike that allows this scenario.Any help is appreciated!
