@box/blueprint-web 15.5.1 → 15.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib-esm/blueprint-configuration-context/blueprint-configuration-context.d.ts +1 -1
- package/dist/lib-esm/blueprint-configuration-context/blueprint-configuration-context.js +18 -2
- package/dist/lib-esm/blueprint-configuration-context/utils.d.ts +10 -0
- package/dist/lib-esm/blueprint-configuration-context/utils.js +10 -1
- package/package.json +3 -3
|
@@ -19,4 +19,4 @@ export declare const BlueprintConfigurationContext: import("react").Context<Blue
|
|
|
19
19
|
* <App />
|
|
20
20
|
* </BlueprintProvider>
|
|
21
21
|
*/
|
|
22
|
-
export declare const BlueprintProvider: ({ children, useTreatment, configurationOverrides }: BlueprintProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare const BlueprintProvider: ({ children, useTreatment: givenUseTreatment, configurationOverrides, }: BlueprintProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { createContext, useMemo } from 'react';
|
|
2
|
+
import { createContext, useEffect, useMemo } from 'react';
|
|
3
|
+
import { isProduction } from '../utils/isProduction.js';
|
|
3
4
|
import { useAnimationsConfiguration } from './configuration-hooks/useAnimationsConfiguration.js';
|
|
4
5
|
import { useTypographyConfiguration } from './configuration-hooks/useTypographyConfiguration.js';
|
|
6
|
+
import { isUseTreatmentHook, useNoopTreatment } from './utils.js';
|
|
5
7
|
import { BLUEPRINT_CONFIGURATION_DEFAULTS } from './consts.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -29,9 +31,23 @@ const BlueprintConfigurationContext = /*#__PURE__*/createContext({
|
|
|
29
31
|
*/
|
|
30
32
|
const BlueprintProvider = ({
|
|
31
33
|
children,
|
|
32
|
-
useTreatment,
|
|
34
|
+
useTreatment: givenUseTreatment,
|
|
33
35
|
configurationOverrides = {}
|
|
34
36
|
}) => {
|
|
37
|
+
// `useTreatment` is a required prop, but callers (or misconfigured consumers) may omit it
|
|
38
|
+
// or pass a non-callable value. Fall back to the no-op hook unless we received an actual
|
|
39
|
+
// function so the provider degrades gracefully instead of throwing at call time.
|
|
40
|
+
const isUseTreatmentValid = isUseTreatmentHook(givenUseTreatment);
|
|
41
|
+
const useTreatment = isUseTreatmentValid ? givenUseTreatment : useNoopTreatment;
|
|
42
|
+
const givenUseTreatmentType = typeof givenUseTreatment;
|
|
43
|
+
// Surface the misconfiguration to developers without breaking the app (stripped from production bundles).
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (isUseTreatmentValid || isProduction()) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.error(`BlueprintProvider: \`useTreatment\` must be a function, but received \`${givenUseTreatmentType}\`. Falling back to the no-op treatment, so all Split.io-driven configuration will resolve to its disabled default.`);
|
|
50
|
+
}, [isUseTreatmentValid, givenUseTreatmentType]);
|
|
35
51
|
const typographyConfig = useTypographyConfiguration({
|
|
36
52
|
overrides: configurationOverrides
|
|
37
53
|
});
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { type BlueprintProviderProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Runtime type guard for `BlueprintProvider`'s `useTreatment` prop.
|
|
4
|
+
*
|
|
5
|
+
* `useTreatment` is statically typed as a required function, but callers (or
|
|
6
|
+
* misconfigured consumers) can still omit it or pass a non-callable value. This
|
|
7
|
+
* guard narrows an `unknown` to the hook type so the provider can fall back to
|
|
8
|
+
* `useNoopTreatment` instead of throwing at call time.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isUseTreatmentHook: (value: unknown) => value is BlueprintProviderProps["useTreatment"];
|
|
1
11
|
export declare const isValidTreatment: (treatment: string) => boolean;
|
|
2
12
|
export declare const isTreatmentEnabled: (treatment: string) => treatment is "on";
|
|
3
13
|
export declare const getTreatmentValue: (treatment: string, defaultValue: string) => string;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { TREATMENT_STATES } from './consts.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Runtime type guard for `BlueprintProvider`'s `useTreatment` prop.
|
|
5
|
+
*
|
|
6
|
+
* `useTreatment` is statically typed as a required function, but callers (or
|
|
7
|
+
* misconfigured consumers) can still omit it or pass a non-callable value. This
|
|
8
|
+
* guard narrows an `unknown` to the hook type so the provider can fall back to
|
|
9
|
+
* `useNoopTreatment` instead of throwing at call time.
|
|
10
|
+
*/
|
|
11
|
+
const isUseTreatmentHook = value => typeof value === 'function';
|
|
3
12
|
const isTreatmentEnabled = treatment => treatment === TREATMENT_STATES.ON;
|
|
4
13
|
/**
|
|
5
14
|
* No-op `useTreatment` implementation that always resolves to
|
|
@@ -13,4 +22,4 @@ const isTreatmentEnabled = treatment => treatment === TREATMENT_STATES.ON;
|
|
|
13
22
|
*/
|
|
14
23
|
const useNoopTreatment = () => TREATMENT_STATES.CONTROL;
|
|
15
24
|
|
|
16
|
-
export { isTreatmentEnabled, useNoopTreatment };
|
|
25
|
+
export { isTreatmentEnabled, isUseTreatmentHook, useNoopTreatment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/blueprint-web",
|
|
3
|
-
"version": "15.5.
|
|
3
|
+
"version": "15.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"publishConfig": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@ariakit/react": "0.4.21",
|
|
49
49
|
"@ariakit/react-core": "0.4.21",
|
|
50
|
-
"@box/blueprint-web-assets": "^4.
|
|
50
|
+
"@box/blueprint-web-assets": "^4.123.1",
|
|
51
51
|
"@internationalized/date": "^3.12.0",
|
|
52
52
|
"@radix-ui/react-accordion": "1.1.2",
|
|
53
53
|
"@radix-ui/react-checkbox": "1.0.4",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"type-fest": "^3.2.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@box/storybook-utils": "^0.20.
|
|
80
|
+
"@box/storybook-utils": "^0.20.11",
|
|
81
81
|
"@figma/code-connect": "1.4.4",
|
|
82
82
|
"@types/react": "^18.0.0",
|
|
83
83
|
"@types/react-dom": "^18.0.0",
|