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

Update single fetch headers approach to use response stub API #9142

Merged
merged 12 commits into from
Mar 27, 2024
Prev Previous commit
Next Next commit
Few more E2E fixes
  • Loading branch information
brophdawg11 committed Mar 27, 2024
commit 309a4983209aaee49868c3edf91e7fa2e64790c6
6 changes: 3 additions & 3 deletions integration/revalidate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ test.describe("single fetch", () => {
<li><Link to="/">/</Link></li>
<li><Link to="/parent">/parent</Link></li>
<li><Link to="/parent/child">/parent/child</Link></li>
<li><Link to="/parent/child?revalidate=parent">/parent/child</Link></li>
<li><Link to="/parent/child?revalidate=child">/parent/child</Link></li>
<li><Link to="/parent/child?revalidate=parent,child">/parent/child</Link></li>
<li><Link to="/parent/child?revalidate=parent">/parent/child?revalidate=parent</Link></li>
<li><Link to="/parent/child?revalidate=child">/parent/child?revalidate=child</Link></li>
<li><Link to="/parent/child?revalidate=parent,child">/parent/child?revalidate=parent,child</Link></li>
</ul>
</nav>
<Outlet />
Expand Down
27 changes: 19 additions & 8 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ function getSingleFetchDataStrategy(
responseStub.status = result.result.status;
}
for (let [k, v] of result.result.headers) {
if (k !== "Set-Cookie") {
if (k.toLowerCase() !== "set-cookie") {
responseStub.headers.set(k, v);
}
}
Expand Down Expand Up @@ -949,35 +949,46 @@ function mergeResponseStubs(
) {
let statusCode: number | undefined = undefined;
let headers = new Headers();

// Action followed by top-down loaders
let actionStub = responseStubs[ResponseStubActionSymbol];
let stubs = [
actionStub,
...context.matches.map((m) => responseStubs[m.route.id]),
].filter((stub) => stub) as ResponseStub[];
stubs.forEach((stub: ResponseStub) => {

for (let stub of stubs) {
// Take the highest error/redirect, or the lowest success value - preferring
// action 200's over loader 200s
if (
(statusCode === undefined || statusCode < 300) &&
stub.status &&
statusCode !== actionStub?.status
// first status found on the way down
(statusCode === undefined && stub.status) ||
// deeper 2xx status found while not overriding the action status
(statusCode !== undefined &&
statusCode < 300 &&
stub.status &&
statusCode !== actionStub?.status)
) {
statusCode = stub.status;
}

// Replay headers operations in order
let ops = stub[ResponseStubOperationsSymbol];
// @ts-expect-error
ops.forEach(([op, ...args]) => headers[op](...args));
});
for (let [op, ...args] of ops) {
// @ts-expect-error
headers[op](...args);
}
}

// If no response stubs set it, use whatever we got back from the router
// context which handles internal ErrorResponse cases like 404/405's where
// we may never run a loader/action
if (statusCode === undefined) {
statusCode = context.statusCode;
}
if (statusCode === undefined) {
statusCode = 200;
}

return { statusCode, headers };
}
Expand Down
Loading