diff --git a/sdk/nextjs/src/client/internal/InternalDevCycleClientsideProvider.tsx b/sdk/nextjs/src/client/internal/InternalDevCycleClientsideProvider.tsx index 8a0ea77db..45c53d125 100644 --- a/sdk/nextjs/src/client/internal/InternalDevCycleClientsideProvider.tsx +++ b/sdk/nextjs/src/client/internal/InternalDevCycleClientsideProvider.tsx @@ -66,13 +66,7 @@ export const InternalDevCycleClientsideProvider = ({ context const revalidateConfig = (lastModified?: number) => { - invalidateConfig( - clientSDKKey, - !!context.options.enableObfuscation, - lastModified, - ).finally(() => { - router.refresh() - }) + invalidateConfig(clientSDKKey) } let resolvedServerData = serverData diff --git a/sdk/nextjs/src/client/internal/useRerenderOnVariableChange.ts b/sdk/nextjs/src/client/internal/useRerenderOnVariableChange.ts index ab61c4f4f..67b0f9ac3 100644 --- a/sdk/nextjs/src/client/internal/useRerenderOnVariableChange.ts +++ b/sdk/nextjs/src/client/internal/useRerenderOnVariableChange.ts @@ -7,7 +7,6 @@ export const useRerenderOnVariableChange = (key?: string): void => { const client = useDevCycleClient() const variableKey = key ?? '*' - useEffect(() => { client.subscribe( `variableUpdated:${variableKey}`, diff --git a/sdk/nextjs/src/common/invalidateConfig.ts b/sdk/nextjs/src/common/invalidateConfig.ts index 0f6aae4d3..15ea8652a 100644 --- a/sdk/nextjs/src/common/invalidateConfig.ts +++ b/sdk/nextjs/src/common/invalidateConfig.ts @@ -1,12 +1,7 @@ 'use server' -import { fetchCDNConfig } from '../server/requests' import { revalidateTag } from 'next/cache' -export const invalidateConfig = async ( - sdkToken: string, - obfuscated: boolean, - lastModified?: number, -): Promise => { +export const invalidateConfig = async (sdkToken: string): Promise => { if (typeof window != 'undefined') { console.error( 'DevCycle realtime updates are only available in Next.js 14.0.5 and above. Please update your version ' + @@ -14,29 +9,6 @@ export const invalidateConfig = async ( ) return } - await invalidateConfigCache(sdkToken, obfuscated, lastModified) -} - -export const invalidateConfigCache = async ( - sdkKey: string, - obfuscated: boolean, - lastModified?: number, -): Promise => { - const response = await fetchCDNConfig(sdkKey, { - enableObfuscation: obfuscated, - }) - - const lastModifiedHeader = response.headers.get('last-modified') - - const lastModifiedCache = new Date(lastModifiedHeader ?? 0) - const lastModifiedClient = new Date(lastModified ?? 0) - - if ( - lastModifiedHeader && - lastModified && - lastModifiedClient > lastModifiedCache - ) { - console.log('Invalidating old DevCycle cached config') - revalidateTag(sdkKey) - } + console.log('Invalidating old DevCycle cached config') + revalidateTag(sdkToken) } diff --git a/sdk/nextjs/src/pages/appWithDevCycle.tsx b/sdk/nextjs/src/pages/appWithDevCycle.tsx index 990a2130b..e445da1e4 100644 --- a/sdk/nextjs/src/pages/appWithDevCycle.tsx +++ b/sdk/nextjs/src/pages/appWithDevCycle.tsx @@ -30,7 +30,6 @@ export const appWithDevCycle = ( ._devcycleSSR as SSRProps['_devcycleSSR'] const onServerside = typeof window === 'undefined' - if (!devcycleSSR) { return } diff --git a/sdk/nextjs/src/server/bucketing.ts b/sdk/nextjs/src/server/bucketing.ts index 4c4f3268e..d1e4b477e 100644 --- a/sdk/nextjs/src/server/bucketing.ts +++ b/sdk/nextjs/src/server/bucketing.ts @@ -23,7 +23,6 @@ const generateBucketedConfigCached = cache( undefined, userAgent ?? undefined, ) - return { config: { ...generateBucketedConfig({ user: populatedUser, config }), @@ -44,12 +43,13 @@ const generateBucketedConfigCached = cache( */ export const getBucketedConfig = async ( sdkKey: string, + clientSDKKey: string, user: DevCycleUser, options: DevCycleNextOptions, userAgent?: string, ): Promise => { // this request will be cached by Next - const cdnConfig = await fetchCDNConfig(sdkKey, options) + const cdnConfig = await fetchCDNConfig(sdkKey, clientSDKKey, options) if (!cdnConfig.ok) { const responseText = await cdnConfig.text() throw new Error('Could not fetch config: ' + responseText) diff --git a/sdk/nextjs/src/server/initialize.ts b/sdk/nextjs/src/server/initialize.ts index cb4bb8c79..ec28ccfcf 100644 --- a/sdk/nextjs/src/server/initialize.ts +++ b/sdk/nextjs/src/server/initialize.ts @@ -25,6 +25,7 @@ const cachedUserGetter = cache( export const initialize = async ( sdkKey: string, + clientSDKKey: string, userGetter: () => DevCycleUser | Promise, options: DevCycleNextOptions = {}, ): Promise => { @@ -51,7 +52,13 @@ export const initialize = async ( let config = null try { - config = await getBucketedConfig(sdkKey, user, options, userAgent) + config = await getBucketedConfig( + sdkKey, + clientSDKKey, + user, + options, + userAgent, + ) } catch (e) { console.error('Error fetching DevCycle config', e) } diff --git a/sdk/nextjs/src/server/requests.ts b/sdk/nextjs/src/server/requests.ts index 88b62c134..e4014bd8b 100644 --- a/sdk/nextjs/src/server/requests.ts +++ b/sdk/nextjs/src/server/requests.ts @@ -7,6 +7,7 @@ const getFetchUrl = (sdkKey: string, obfuscated: boolean) => export const fetchCDNConfig = async ( sdkKey: string, + clientSDKKey: string, options: DevCycleNextOptions, ): Promise => { return await fetch( @@ -15,7 +16,7 @@ export const fetchCDNConfig = async ( { next: { revalidate: 60, - tags: [sdkKey], + tags: [sdkKey, clientSDKKey], }, }, ) diff --git a/sdk/nextjs/src/server/setupDevCycle.tsx b/sdk/nextjs/src/server/setupDevCycle.tsx index b358e85a7..f6855ba41 100644 --- a/sdk/nextjs/src/server/setupDevCycle.tsx +++ b/sdk/nextjs/src/server/setupDevCycle.tsx @@ -32,22 +32,27 @@ export const setupDevCycle = ({ key, defaultValue, ) => { - await initialize(serverSDKKey, userGetter, options) + await initialize(serverSDKKey, clientSDKKey, userGetter, options) return getVariableValue(key, defaultValue) } const _getAllVariables: typeof getAllVariables = async () => { - await initialize(serverSDKKey, userGetter, options) + await initialize(serverSDKKey, clientSDKKey, userGetter, options) return getAllVariables() } const _getAllFeatures: typeof getAllFeatures = async () => { - await initialize(serverSDKKey, userGetter, options) + await initialize(serverSDKKey, clientSDKKey, userGetter, options) return getAllFeatures() } const _getClientContext = () => { - const serverDataPromise = initialize(serverSDKKey, userGetter, options) + const serverDataPromise = initialize( + serverSDKKey, + clientSDKKey, + userGetter, + options, + ) const { enableStreaming, enableObfuscation, ...otherOptions } = options