-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix(remix-express,remix-vercel): fix request.signal
#3626
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8bce193
fix: fix request.signal for express/vercel
brophdawg11 317e266
fix express/vercel unit tests
brophdawg11 403c35e
add abort signals to arc/netlify requests
brophdawg11 d10b843
Merge branch 'dev' into brophdawg11/abortsignal
brophdawg11 6c158e5
Update netlify/architect tests to assert new signal
brophdawg11 e7f6509
Merge branch 'dev' into brophdawg11/abortsignal
brophdawg11 3ba6bef
add changeset
brophdawg11 70ca93c
Merge branch 'dev' into brophdawg11/abortsignal
brophdawg11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
import { PlaywrightFixture } from "./helpers/playwright-fixture"; | ||
import type { Fixture, AppFixture } from "./helpers/create-fixture"; | ||
import { createAppFixture, createFixture, js } from "./helpers/create-fixture"; | ||
|
||
let fixture: Fixture; | ||
let appFixture: AppFixture; | ||
|
||
test.beforeAll(async () => { | ||
fixture = await createFixture({ | ||
files: { | ||
"app/routes/index.jsx": js` | ||
import { json } from "@remix-run/node"; | ||
import { useActionData, useLoaderData, Form } from "@remix-run/react"; | ||
|
||
export async function action ({ request }) { | ||
console.log('action request.signal', request.signal) | ||
// New event loop causes express request to close | ||
await new Promise(r => setTimeout(r, 0)); | ||
return json({ aborted: request.signal.aborted }); | ||
} | ||
|
||
export function loader({ request }) { | ||
console.log('loader request.signal', request.signal) | ||
return json({ aborted: request.signal.aborted }); | ||
} | ||
|
||
export default function Index() { | ||
let actionData = useActionData(); | ||
let data = useLoaderData(); | ||
return ( | ||
<div> | ||
<p className="action">{actionData ? String(actionData.aborted) : "empty"}</p> | ||
<p className="loader">{String(data.aborted)}</p> | ||
<Form method="post"> | ||
<button type="submit">Submit</button> | ||
</Form> | ||
</div> | ||
) | ||
} | ||
`, | ||
}, | ||
}); | ||
|
||
// This creates an interactive app using puppeteer. | ||
appFixture = await createAppFixture(fixture); | ||
}); | ||
|
||
test.afterAll(async () => appFixture.close()); | ||
|
||
test("should not abort the request in a new event loop", async ({ page }) => { | ||
let app = new PlaywrightFixture(appFixture, page); | ||
await app.goto("/"); | ||
expect(await app.getHtml(".action")).toMatch("empty"); | ||
expect(await app.getHtml(".loader")).toMatch("false"); | ||
|
||
await app.clickElement('button[type="submit"]'); | ||
expect(await app.getHtml(".action")).toMatch("false"); | ||
expect(await app.getHtml(".loader")).toMatch("false"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ export function createRequestHandler({ | |
next: express.NextFunction | ||
) => { | ||
try { | ||
let request = createRemixRequest(req); | ||
let request = createRemixRequest(req, res); | ||
let loadContext = getLoadContext?.(req, res); | ||
|
||
let response = (await handleRequest( | ||
|
@@ -89,20 +89,21 @@ export function createRemixHeaders( | |
return headers; | ||
} | ||
|
||
export function createRemixRequest(req: express.Request): NodeRequest { | ||
export function createRemixRequest( | ||
req: express.Request, | ||
res: express.Response | ||
): NodeRequest { | ||
let origin = `${req.protocol}://${req.get("host")}`; | ||
let url = new URL(req.url, origin); | ||
|
||
// Abort action/loaders once we can no longer write a response | ||
let controller = new AbortController(); | ||
|
||
req.on("close", () => { | ||
controller.abort(); | ||
}); | ||
res.on("close", () => controller.abort()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abort on response |
||
|
||
let init: NodeRequestInit = { | ||
method: req.method, | ||
headers: createRemixHeaders(req.headers), | ||
signal: controller.signal, | ||
signal: controller.signal as AbortSignal, | ||
MichaelDeBoey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
if (req.method !== "GET" && req.method !== "HEAD") { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to the fix this would be
true