Hi all,
I'm hoping to use @clear bane 's awesome remix utils Server Sent Events flow for this.
How would this flow be implemented at a high level?
- User submits form
- Form object payload is sent in some API request that starts a stream
- UI using server sent events to stream the results from the API
Question
The key difference here vs. the examples I've seen on the docs is that I'm not sure **how we send the UI form payload to the server sent event to initiate it. ** Each eventStream's setup function can send an event with a string event key, but what if you want to pass a payload to the loader with the eventStream?
export async function loader({ request }: LoaderFunctionArgs) {
const formPayloadFromUI = ...// where would we get this from?
return eventStream(request.signal, function setup(send) {
async function run() {
someApi(formPayloadFromUI, (results) => {
results.on('data', (data) => {
send({event: 'someStream' /* if we have multiple streams, how would we keep track of them on the UI if the event key needs to match? */, data: JSON.stringify(data) })
})
})
}
run();
return () => {};
});
}
Once the server sent event begins the stream, I understand that you can just stringify the object response to return to the client and parse it there. Hoping I won't run into any stringify over the wire limits with that.