Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Feb 7, 2025
1 parent 063fe79 commit df02b49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
3 changes: 2 additions & 1 deletion integration-test/nextjs/src/app/cc/dynamic/dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const regex_connection_closed_early =
/streaming connection closed before server query could be fully transported, rerunning/i;
const regex_query_error_restart =
/query failed on server, rerunning in browser/i;
const reactErr419 = /(Minified React error #419|Switched to client rendering)/;

test.describe("CC dynamic", () => {
test.describe("useSuspenseQuery", () => {
Expand Down Expand Up @@ -40,7 +41,7 @@ test.describe("CC dynamic", () => {
return regex_query_error_restart.test(message.text());
});
await page.waitForEvent("pageerror", (error) => {
return error.message.includes("Minified React error #419");
return reactErr419.test(error.message);
});

await hydrationFinished;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from "@playwright/test";
import { test } from "../../../../../fixture";

const reactErr419 = /(Minified React error #419|Switched to client rendering)/;

test.describe("PreloadQuery", () => {
for (const [description, path] of [
["with useSuspenseQuery", "useSuspenseQuery"],
Expand Down Expand Up @@ -37,10 +39,7 @@ test.describe("PreloadQuery", () => {
await expect(page).toBeInitiallyLoading(true);

await page.waitForEvent("pageerror", (error) => {
return (
/* prod */ error.message.includes("Minified React error #419") ||
/* dev */ error.message.includes("Query failed upstream.")
);
return reactErr419.test(error.message);
});

await expect(page.getByText("loading")).not.toBeVisible();
Expand Down Expand Up @@ -94,10 +93,7 @@ test.describe("PreloadQuery", () => {
await expect(page).toBeInitiallyLoading(true);

await page.waitForEvent("pageerror", (error) => {
return (
/* prod */ error.message.includes("Minified React error #419") ||
/* dev */ error.message.includes("Query failed upstream.")
);
return reactErr419.test(error.message);
});

await expect(page.getByText("loading")).not.toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,9 @@ class ApolloClientClientBaseImpl extends ApolloClientBase {
TransportIdentifier,
SimulatedQueryInfo
>();
private transportedQueryOptions = new Map<
TransportIdentifier,
WatchQueryOptions
>();

onQueryStarted({ options, id }: Extract<QueryEvent, { type: "started" }>) {
const hydratedOptions = deserializeOptions(options);
this.transportedQueryOptions.set(id, hydratedOptions);

const [controller, stream] = getInjectableEventStream();

Expand Down Expand Up @@ -166,36 +161,36 @@ class ApolloClientClientBaseImpl extends ApolloClientBase {
const queryInfo = this.simulatedStreamingQueries.get(event.id);
if (!queryInfo) return;

if (event.type === "next") {
queryInfo.controller.enqueue(event);
} else if (event.type === "error") {
if (
event.type === "error" ||
(event.type === "next" && event.value.errors)
) {
/**
* At this point we're not able to correctly serialize the error over the wire
* so we do the next-best thing: restart the query in the browser as soon as it
* failed on the server.
* This matches up with what React will be doing (abort hydration and rerender)
* See https://github.com/apollographql/apollo-client-nextjs/issues/52
*/
if (queryInfo) {
this.simulatedStreamingQueries.delete(event.id);
if (process.env.REACT_ENV === "browser") {
invariant.debug(
"Query failed on server, rerunning in browser:",
queryInfo.options
);
this.rerunSimulatedQuery(queryInfo);
} else if (process.env.REACT_ENV === "ssr") {
invariant.debug(
"Query failed upstream, will fail it during SSR and rerun it in the browser:",
queryInfo.options
);
queryInfo.controller.enqueue(event); // TODO? new Error("Query failed upstream.")
}
this.simulatedStreamingQueries.delete(event.id);
if (process.env.REACT_ENV === "browser") {
invariant.debug(
"Query failed on server, rerunning in browser:",
queryInfo.options
);
this.rerunSimulatedQuery(queryInfo);
} else if (process.env.REACT_ENV === "ssr") {
invariant.debug(
"Query failed upstream, will fail it during SSR and rerun it in the browser:",
queryInfo.options
);
queryInfo.controller.error(new Error("Query failed upstream."));
}
this.transportedQueryOptions.delete(event.id);
} else if (event.type === "completed") {
this.simulatedStreamingQueries.delete(event.id);
queryInfo.controller.enqueue(event);
} else if (event.type === "next") {
queryInfo.controller.enqueue(event);
this.transportedQueryOptions.delete(event.id);
}
};

Expand Down

0 comments on commit df02b49

Please sign in to comment.