diff --git a/.changeset/renovate-446b7ad.md b/.changeset/renovate-446b7ad.md new file mode 100644 index 000000000..7fc1ee6a3 --- /dev/null +++ b/.changeset/renovate-446b7ad.md @@ -0,0 +1,5 @@ +--- +'@scaleway/use-growthbook': patch +--- + +Updated dependency `@growthbook/growthbook-react` to `0.24.0`. diff --git a/package.json b/package.json index 6ff7978d1..cb3810308 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "type": "module", "packageManager": "pnpm@8.15.4", "engines": { - "node": ">=18.x", - "pnpm": ">=7.x" + "node": ">=20.x", + "pnpm": ">=8.x" }, "devDependencies": { "@babel/core": "7.24.0", diff --git a/packages/use-growthbook/package.json b/packages/use-growthbook/package.json index b98fe294f..57992052a 100644 --- a/packages/use-growthbook/package.json +++ b/packages/use-growthbook/package.json @@ -25,7 +25,7 @@ "feature flags" ], "dependencies": { - "@growthbook/growthbook-react": "0.21.0" + "@growthbook/growthbook-react": "0.24.0" }, "devDependencies": { "react": "18.2.0" diff --git a/packages/use-growthbook/src/AbTestProvider.tsx b/packages/use-growthbook/src/AbTestProvider.tsx index f4aadc248..e992ccad8 100644 --- a/packages/use-growthbook/src/AbTestProvider.tsx +++ b/packages/use-growthbook/src/AbTestProvider.tsx @@ -72,12 +72,14 @@ export const AbTestProvider = ({ useEffect(() => { const currentAttributes = growthbook.getAttributes() if (currentAttributes !== attributes) { - growthbook.setAttributes({ - ...currentAttributes, - ...attributes, - }) + growthbook + .setAttributes({ + ...currentAttributes, + ...attributes, + }) + .catch(errorCallback) } - }, [attributes, growthbook]) + }, [attributes, growthbook, errorCallback]) return ( {children} diff --git a/packages/use-growthbook/src/__mocks__/@growthbook/growthbook-react.tsx b/packages/use-growthbook/src/__mocks__/@growthbook/growthbook-react.tsx index f041595e1..b4c4cd248 100644 --- a/packages/use-growthbook/src/__mocks__/@growthbook/growthbook-react.tsx +++ b/packages/use-growthbook/src/__mocks__/@growthbook/growthbook-react.tsx @@ -1,10 +1,11 @@ +import type { GrowthBook as GBType } from '@growthbook/growthbook-react' import { jest } from '@jest/globals' import type { ReactNode } from 'react' const GrowthBook = jest.fn(() => ({ - loadFeatures: jest.fn(), - getAttributes: jest.fn(), - setAttributes: jest.fn(), + loadFeatures: jest.fn(), + getAttributes: jest.fn(), + setAttributes: jest.fn(() => Promise.resolve()), })) const GrowthBookProvider = ({ children }: { children: ReactNode }) => children diff --git a/packages/use-growthbook/src/__tests__/AbTestProvider.tsx b/packages/use-growthbook/src/__tests__/AbTestProvider.tsx index 1022891fb..5cbfef2aa 100644 --- a/packages/use-growthbook/src/__tests__/AbTestProvider.tsx +++ b/packages/use-growthbook/src/__tests__/AbTestProvider.tsx @@ -11,11 +11,10 @@ type TrackingCallback = ComponentProps< type ErrorCallback = ComponentProps['errorCallback'] describe('AbTestProvider', () => { - let trackingCallback: TrackingCallback - let errorCallback: ErrorCallback + const trackingCallback = jest.fn() + const errorCallback: ErrorCallback = () => null beforeEach(() => { - trackingCallback = jest.fn() jest.clearAllMocks() }) it('should init GrowthBook once', () => { diff --git a/packages/use-growthbook/src/__tests__/useAbTestAttributes.ts b/packages/use-growthbook/src/__tests__/useAbTestAttributes.ts index 0184141d1..8caa4a0da 100644 --- a/packages/use-growthbook/src/__tests__/useAbTestAttributes.ts +++ b/packages/use-growthbook/src/__tests__/useAbTestAttributes.ts @@ -8,13 +8,12 @@ jest.mock('@growthbook/growthbook-react') describe('useAbTestAttributes', () => { let getAttributes: () => Attributes - let setAttributes: (attributes: Attributes) => null | undefined + let setAttributes: (attributes: Attributes) => Promise beforeEach(() => { - getAttributes = jest - .fn() - .mockReturnValue({ foo: 'bar' }) as () => Attributes - setAttributes = jest.fn() as (attributes: Attributes) => null | undefined + getAttributes = jest.fn<() => Attributes>().mockReturnValue({ foo: 'bar' }) + setAttributes = jest.fn(() => Promise.resolve()) + jest.spyOn(growthbook, 'useGrowthBook').mockReturnValue({ getAttributes, setAttributes, diff --git a/packages/use-growthbook/src/types.ts b/packages/use-growthbook/src/types.ts index 8ad52fa08..d5cd82ff5 100644 --- a/packages/use-growthbook/src/types.ts +++ b/packages/use-growthbook/src/types.ts @@ -1,4 +1,4 @@ -import type { Context } from '@growthbook/growthbook-react' +import type { Context, GrowthBook } from '@growthbook/growthbook-react' export type Attributes = Record @@ -7,11 +7,7 @@ export type Attributes = Record * @param {number} [timeout] - 500. * @param {boolean} [skipCache] - false. */ -export type LoadConfig = { - autoRefresh: boolean - timeout: number - skipCache: boolean -} +export type LoadConfig = NonNullable[0]> export type ToolConfig = Pick< Context, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69b7ba15a..0ea2b11cf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,8 +245,8 @@ importers: packages/use-growthbook: dependencies: '@growthbook/growthbook-react': - specifier: 0.21.0 - version: 0.21.0(react@18.2.0) + specifier: 0.24.0 + version: 0.24.0(react@18.2.0) devDependencies: react: specifier: 18.2.0 @@ -2361,18 +2361,18 @@ packages: tslib: 2.5.3 dev: false - /@growthbook/growthbook-react@0.21.0(react@18.2.0): - resolution: {integrity: sha512-LM4jG9xThSYCMfRQECeLtTr8sYyiAxC5NLmT4U3uxKyvVUCB+s0k/vdKrvHcv3YXNJ37mW3VtK9XkNSuW16mcw==} + /@growthbook/growthbook-react@0.24.0(react@18.2.0): + resolution: {integrity: sha512-7Nz8FIc5PPlCXbRzv9GyY/86hmDytJ84ZCtLBuOt/Bna/MsuJlh/TXUg6eF4OFeRN039FhgyapBJ4hC4Mqt+Qw==} engines: {node: '>=10'} peerDependencies: react: ^16.8.0-0 || ^17.0.0-0 || ^18.0.0-0 || 18 dependencies: - '@growthbook/growthbook': 0.31.0 + '@growthbook/growthbook': 0.34.0 react: 18.2.0 dev: false - /@growthbook/growthbook@0.31.0: - resolution: {integrity: sha512-VtI5IibZHhvtrlZhfopGYhVXZ++FewgY0BtQQyEqFSrhCYFvEEtq+GkuSm4GcC0JxNuHiYJr9/R3GpffJV/T4Q==} + /@growthbook/growthbook@0.34.0: + resolution: {integrity: sha512-3K5JL8QftX7y77EpieYg9anXVYb6+ZafTsrNCWp0HOdmtf4lxHOzCUYwuYDaS3bvmaeIUWJ5hYcOTc6WhNbfJw==} engines: {node: '>=10'} dependencies: dom-mutator: 0.6.0