Skip to content
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

feat(remix-server-runtime): RRR 1.3 / 1.4 - handleDocumentRequest #4385

Merged
merged 32 commits into from
Nov 15, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9d0d6e3
initial work for document requests
jacob-ebey Oct 18, 2022
fccc933
Keep thrown responses on the throw path
brophdawg11 Oct 19, 2022
138222f
get headers integration tests passing
brophdawg11 Oct 19, 2022
ebcc937
temp work on error/catch boundary distinction
brophdawg11 Oct 19, 2022
0e84d2f
chore: update test to be more reliable
jacob-ebey Oct 19, 2022
52a6fc3
be more protective when accessing route module
jacob-ebey Oct 19, 2022
2b5140f
be more protective when accessing route module
jacob-ebey Oct 19, 2022
7a6045f
revert
jacob-ebey Oct 19, 2022
4a8997e
Get catch boundary integration tests passing
brophdawg11 Oct 20, 2022
af9d450
Get error boundary tests passing
brophdawg11 Oct 20, 2022
ad09bef
test: mdx test ignores non-existing asset request
jacob-ebey Oct 21, 2022
2f44df4
fix: handle no root catch boundary
jacob-ebey Oct 21, 2022
8c12f0a
remove ".only"
jacob-ebey Oct 21, 2022
8af6805
Updates
brophdawg11 Oct 21, 2022
b25d64f
Copy over latest @remix-run/router files
brophdawg11 Oct 21, 2022
32af5b6
Bring over latest router files
brophdawg11 Oct 26, 2022
01e2277
Add data request error tests
brophdawg11 Oct 26, 2022
077e9b5
Updates for catch.error boundary data responses
brophdawg11 Oct 27, 2022
194ea13
fix: ensure route modules are loaded regardless of error state
jacob-ebey Oct 27, 2022
8d7c86a
ALL GREEN BABY ✅
brophdawg11 Oct 28, 2022
b93e0c7
Fix lint issues and one broken unit test
brophdawg11 Oct 31, 2022
c1ae7a9
Fix tsc build error
brophdawg11 Oct 31, 2022
5d1c6d1
make fetcher tests more reliable
brophdawg11 Nov 1, 2022
63cf680
Merge branch 'dev' into rrr-document-requests-1
brophdawg11 Nov 1, 2022
e6e7f9d
🧹 code
brophdawg11 Nov 1, 2022
3829f50
updated to cover aborted request case
jacob-ebey Nov 2, 2022
b944b7c
chore: remove assert flow (#4554)
jacob-ebey Nov 9, 2022
5db567e
Change missing loader from 405 -> 400 error
brophdawg11 Nov 15, 2022
8a14ade
Bring over external redirect logic from react router
brophdawg11 Nov 15, 2022
3ce0ac3
add changeset
brophdawg11 Nov 15, 2022
e3c6225
Merge branch 'dev' into rrr-document-requests-1
brophdawg11 Nov 15, 2022
ccae87f
fix tsc error
brophdawg11 Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,15 @@ async function handleDocumentRequestRR(
};
break;
} else {
appState.loaderBoundaryRouteId = id;
// Only assign the boundary id if this module has a boundary. This
// should be true in almost all cases, except for cases in which no
// boundaries exist and the router "assigns" the error to the root route
// for lack of a better place to put it. If the root doesn't have an
// error boundary, then we leave loaderBoundaryId null to bubble to the
// default boundary at render time
if (build.routes[id]?.module.ErrorBoundary) {
appState.loaderBoundaryRouteId = id;
}
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
appState.trackBoundaries = false;
appState.error = await serializeError(error);
break;
Expand Down Expand Up @@ -1010,7 +1018,23 @@ async function assertResponsesMatch(_a: Response, _b: Response) {
assert(
a,
b,
(r) => r.text(),
async (r) => {
let text = await r.text();

// Strip stack trace from default error boundary HTML
if (
text.includes(">Application Error</h1>") &&
text.includes("💿 Hey developer👋")
) {
return stripStackTraceFromDefaultErrorBoundary(text);
}

if (text.includes("<script>window.__remixContext")) {
return stripStackTraceFromRemixContext(text);
}
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved

return text;
},
"Non-JSON response body did not match!\nResponse 1:\n" +
(await a.clone().text()) +
"\nResponse 2:\n" +
Expand All @@ -1019,6 +1043,39 @@ async function assertResponsesMatch(_a: Response, _b: Response) {
}
}

function stripStackTraceFromDefaultErrorBoundary(text: string) {
let openPreStart = text.indexOf("<pre ");
let openPreEnd = text.indexOf('">', openPreStart + 1);
let closePre = text.indexOf("</pre>", openPreEnd + 1);
let error = text.substring(openPreEnd + 2, closePre);
let stackStart = error.indexOf("\n");
let errorWithoutStack = error.substring(0, stackStart);
return (
text.replace(error, "ERROR REMOVED") + "\n\nError:\n" + errorWithoutStack
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
);
}

function stripStackTraceFromRemixContext(text: string) {
let scriptStart = text.indexOf("<script>window.__remixContext");
let scriptEnd = text.indexOf("</script>", scriptStart + 1);
let scriptContents = text.substring(scriptStart, scriptEnd + 9);
let remixContext = JSON.parse(
scriptContents
.replace("<script>window.__remixContext = ", "")
.replace(";</script>", "")
);
// If we didn't have an error - assert the full document
if (!remixContext?.appState?.error?.stack) {
return text;
}

// Otherwise remove the stack trace and assert the text/JSON as a
// concatenated string
remixContext.appState.error.stack = "yes";
text = text.replace(scriptContents, "CONTEXT REMOVED");
return text + "\n\nContext:\n" + JSON.stringify(remixContext);
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
}

function returnLastResortErrorResponse(error: any, serverMode?: ServerMode) {
if (serverMode !== ServerMode.Test) {
console.error(error);
Expand Down