Skip to content

Commit 3683980

Browse files
avoid resetting visible plugin state when explorer or history context changes (#2792)
1 parent 4270007 commit 3683980

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

.changeset/sour-kangaroos-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/react': patch
3+
---
4+
5+
Avoid resetting visible plugin state when explorer or history context changes

packages/graphiql-react/src/plugin.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ export function PluginContextProvider(props: PluginContextProviderProps) {
9797
const explorerContext = useExplorerContext();
9898
const historyContext = useHistoryContext();
9999

100+
const hasExplorerContext = Boolean(explorerContext);
101+
const hasHistoryContext = Boolean(historyContext);
100102
const plugins = useMemo(() => {
101103
const pluginList: GraphiQLPlugin[] = [];
102104
const pluginTitles: Record<string, true> = {};
103105

104-
if (explorerContext) {
106+
if (hasExplorerContext) {
105107
pluginList.push(DOC_EXPLORER_PLUGIN);
106108
pluginTitles[DOC_EXPLORER_PLUGIN.title] = true;
107109
}
108-
if (historyContext) {
110+
if (hasHistoryContext) {
109111
pluginList.push(HISTORY_PLUGIN);
110112
pluginTitles[HISTORY_PLUGIN.title] = true;
111113
}
@@ -125,7 +127,7 @@ export function PluginContextProvider(props: PluginContextProviderProps) {
125127
}
126128

127129
return pluginList;
128-
}, [explorerContext, historyContext, props.plugins]);
130+
}, [hasExplorerContext, hasHistoryContext, props.plugins]);
129131

130132
const [visiblePlugin, internalSetVisiblePlugin] =
131133
useState<GraphiQLPlugin | null>(() => {

0 commit comments

Comments
 (0)