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

Warn if ssrMode or ssrForceFetchDelay are used. #358

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions integration-test/nextjs/src/app/rsc/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
import {
ApolloClient,
InMemoryCache,
registerApolloClient,
} from "@apollo/experimental-nextjs-app-support";

import { loadErrorMessages, loadDevMessages } from "@apollo/client/dev";
import { setVerbosity } from "ts-invariant";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
unwrapQueryRef,
} from "@apollo/client/react/internal";

import { TransportedQueryRef } from "@apollo/experimental-nextjs-app-support/ssr";
import { TransportedQueryRef } from "@apollo/experimental-nextjs-app-support";

declare global {
interface Window {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ type SimulatedQueryInfo = {
};

interface WrappedApolloClientOptions
extends Omit<ApolloClientOptions<NormalizedCacheObject>, "cache"> {
extends Omit<
ApolloClientOptions<NormalizedCacheObject>,
"cache" | "ssrMode" | "ssrForceFetchDelay"
> {
cache: InMemoryCache;
}

Expand All @@ -68,6 +71,19 @@ class ApolloClientBase extends OrigApolloClient<NormalizedCacheObject> {
[sourceSymbol]: string;

constructor(options: WrappedApolloClientOptions) {
const warnings: string[] = [];
if ("ssrMode" in options) {
delete options.ssrMode;
warnings.push(
"The `ssrMode` option is not supported in %s. Please remove it from your %s constructor options."
);
}
if ("ssrForceFetchDelay" in options) {
delete options.ssrForceFetchDelay;
warnings.push(
"The `ssrForceFetchDelay` option is not supported in %s. Please remove it from your %s constructor options."
);
}
super(
process.env.REACT_ENV === "rsc" || process.env.REACT_ENV === "ssr"
? {
Expand All @@ -79,6 +95,10 @@ class ApolloClientBase extends OrigApolloClient<NormalizedCacheObject> {
const info = (this.constructor as typeof ApolloClientBase).info;
this[sourceSymbol] = `${info.pkg}:ApolloClient`;

for (const warning of warnings) {
console.warn(warning, info.pkg, "ApolloClient");
}
Comment on lines +98 to +100
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is down here because we need access to info, which relies on this, which is only available after the super call - but we want to remove these options before that call.


assertInstance(
this.cache as unknown as InMemoryCache,
info,
Expand Down
Loading