remix
remix copied to clipboard
Node Fetch: Cannot cancel a stream that already has a reader
Reproduction
export const loader: LoaderFunction = async ({ context, request }) => {
const controller = new AbortController()
fetch('http://google/api.com', {
signal: controller.signal,
})
controller.abort()
return defer({
})
}
System Info
node v18.12.0
remix-run/node 1.15.0
Used Package Manager
pnpm
Expected Behavior
The fetch request can be cancelled normally, but an error was caught in the catch.
Actual Behavior
I used fetch in Remix, but encountered the following issue:
I'm not sure how I should use fetch on the server to initiate request processing and interrupt requests after timeout.
export const loader: LoaderFunction = async ({ context, request }) => {
const controller = new AbortController()
fetch('http://google/api.com', {
signal: controller.signal,
})
controller.abort()
return defer({
})
}
This may seem like a bug, but I do need to retrieve some data through fetch on the server. Is there no other way for Remix to do this?
see here on the tag of feat, would like to ask the next question for the time being no hack ending plan ?
I am not sure about the current progress of this issue, but I have used a hack approach to address it
const nodeFetch = require("node-fetch");
let fetchOverlay = false;
export function setupFetch() {
if (!fetchOverlay) {
globalThis.fetch = nodeFetch as any;
fetchOverlay = true;
}
}
I am not sure about the current progress of this issue, but I have used a hack approach to address it
const nodeFetch = require("node-fetch"); let fetchOverlay = false; export function setupFetch() { if (!fetchOverlay) { globalThis.fetch = nodeFetch as any; fetchOverlay = true; } }
I'm not sure what problem this will bring, but it did solve the problem temporarily