From a0d90d4587454fb95e595b72533bf0932a95a1fc Mon Sep 17 00:00:00 2001 From: Giovanni-Schroevers Date: Wed, 11 Mar 2026 09:47:09 +0100 Subject: [PATCH 1/3] feat(graphqlSsrClient): add instantiation with timestamp to apollo shared client --- .../lib/graphql/graphqlSsrClient.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts index d1d6549a43..75cef1093e 100644 --- a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts +++ b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts @@ -12,6 +12,7 @@ import { import { MeshApolloLink, getBuiltMesh } from '@graphcommerce/graphql-mesh' import { storefrontConfig, storefrontConfigDefault } from '@graphcommerce/next-ui' import type { GetStaticPropsContext } from 'next' +import fs from 'fs' import { i18nSsrLoader } from '../i18n/I18nProvider' function client(context: GetStaticPropsContext, fetchPolicy: FetchPolicy = 'no-cache') { @@ -53,7 +54,7 @@ export function graphqlSharedClient(context: GetStaticPropsContext) { } const ssrClient: { - [locale: string]: ApolloClient + [locale: string]: { instancedAt: number; client: ApolloClient } } = {} export function graphqlSsrClient(context: GetStaticPropsContext) { @@ -62,8 +63,24 @@ export function graphqlSsrClient(context: GetStaticPropsContext) { if (context.preview || context.draftMode) return client(context, 'no-cache') + try { + const instancedAt = Number(fs.readFileSync('renew-all-pages-query.txt', 'utf8')) + + if (ssrClient[locale]?.instancedAt < instancedAt) { + delete ssrClient[locale] + } + } catch (error) { + if (error instanceof Error && (error as NodeJS.ErrnoException).code !== 'ENOENT') { + console.error(error) + } + } + // Create a client if it doesn't exist for the locale. - if (!ssrClient[locale]) ssrClient[locale] = client(context, 'no-cache') + if (!ssrClient[locale]) + ssrClient[locale] = { + instancedAt: new Date().getTime(), + client: client(context, 'no-cache'), + } - return ssrClient[locale] + return ssrClient[locale].client } From 96f648fd26241bf81eaa6de4abc32e7b4a9d6b76 Mon Sep 17 00:00:00 2001 From: Giovanni-Schroevers Date: Fri, 13 Mar 2026 13:19:38 +0100 Subject: [PATCH 2/3] feat: check if renew-all-pages-query file exists before reading it --- examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts index 75cef1093e..09b7359631 100644 --- a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts +++ b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts @@ -63,16 +63,14 @@ export function graphqlSsrClient(context: GetStaticPropsContext) { if (context.preview || context.draftMode) return client(context, 'no-cache') - try { + const shouldCheckCache = fs.existsSync('renew-all-pages-query.txt') + + if (shouldCheckCache) { const instancedAt = Number(fs.readFileSync('renew-all-pages-query.txt', 'utf8')) if (ssrClient[locale]?.instancedAt < instancedAt) { delete ssrClient[locale] } - } catch (error) { - if (error instanceof Error && (error as NodeJS.ErrnoException).code !== 'ENOENT') { - console.error(error) - } } // Create a client if it doesn't exist for the locale. From 2267b495471c86f3eff2ace8f50a5a62c7fad760 Mon Sep 17 00:00:00 2001 From: Giovanni-Schroevers Date: Fri, 13 Mar 2026 13:50:10 +0100 Subject: [PATCH 3/3] feat: update path of renew-all-pages-query file --- examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts index 09b7359631..38a52d8fa7 100644 --- a/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts +++ b/examples/magento-graphcms/lib/graphql/graphqlSsrClient.ts @@ -63,10 +63,12 @@ export function graphqlSsrClient(context: GetStaticPropsContext) { if (context.preview || context.draftMode) return client(context, 'no-cache') - const shouldCheckCache = fs.existsSync('renew-all-pages-query.txt') + const dir = './tmp' + + const shouldCheckCache = fs.existsSync(`${dir}/renew-all-pages-query.txt`) if (shouldCheckCache) { - const instancedAt = Number(fs.readFileSync('renew-all-pages-query.txt', 'utf8')) + const instancedAt = Number(fs.readFileSync(`${dir}/renew-all-pages-query.txt`, 'utf8')) if (ssrClient[locale]?.instancedAt < instancedAt) { delete ssrClient[locale]