I’m working on a Hydrogen project and attempting to set up an event stream using remix-utils/sse/server.
However, I’m encountering a persistent issue where the promise associated with the event stream seems to hang and eventually errors out with the message while previewing npm run preview:
A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise’s I/O context have already finished.
[Error: The script will never generate a response.]
Here’s the loader function for setting the subscription routes:
import type {LoaderFunctionArgs} from '@remix-run/node';
import {eventStream} from 'remix-utils/sse/server';
import {EVENTS} from '~/lib/constants/events.contstent';
import {emitter} from '~/lib/utils/emitter.server';
export async function loader({request}: LoaderFunctionArgs) {
return eventStream(request.signal, function setup(send) {
function handle(data: { customerId: string, message: string }) {
const eventData = JSON.stringify({ customerId: data.customerId, message: data.message });
send({ event: EVENTS.LOGOUT.NAME, data: eventData });
}
emitter.on(EVENTS.LOGOUT.KEY, handle);
return function clear() {
emitter.off(EVENTS.LOGOUT.KEY, handle);
};
});
}
Any insights or suggestions on resolving this hanging promise error would be greatly appreciated!