@skyscanner/backpack-web 42.26.0 → 42.27.1

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.
@@ -71,6 +71,19 @@ const FALLBACK_LOCALE_BY_DIRECTION = {
71
71
  // Intl.Locale.textInfo is unavailable (Node < 22, older browsers).
72
72
  const RTL_LANGUAGE_SUBTAGS = new Set(['ar', 'he', 'fa', 'ur', 'yi', 'iw', 'ps', 'sd', 'ug', 'ku']);
73
73
 
74
+ // Returns true when `locale` is a BCP 47 string that Intl.Locale accepts.
75
+ // Ark's LocaleProvider calls `new Intl.Locale(locale)` without a try/catch,
76
+ // so any value we hand it must be validated here first or it throws
77
+ // "Incorrect locale information provided".
78
+ const isValidLocale = locale => {
79
+ try {
80
+ // Reading a property on the result (rather than bare `new`) satisfies the no-new lint rule.
81
+ return Boolean(new Intl.Locale(locale).baseName);
82
+ } catch {
83
+ return false;
84
+ }
85
+ };
86
+
74
87
  // Returns the text direction implied by a BCP 47 locale string.
75
88
  // Uses Intl.Locale.textInfo when available (Chrome 99+, Safari 15.4+, Firefox 126+, Node 22+);
76
89
  // falls back to a known-RTL-subtag lookup.
@@ -88,11 +101,18 @@ const getLangDir = locale => {
88
101
  //
89
102
  // Priority rules:
90
103
  // 1. If html[dir] is explicitly set:
91
- // - Use html[lang] only when its direction is consistent with html[dir].
104
+ // - Use html[lang] only when it is a valid locale AND its direction is
105
+ // consistent with html[dir].
92
106
  // - Otherwise fall back to FALLBACK_LOCALE_BY_DIRECTION[dir].
93
107
  // This prevents an LTR html[lang] (e.g. 'en' from a page template) from
94
108
  // overriding an explicit html[dir]="rtl" signal (e.g. from a dev RTL toggle).
95
- // 2. If html[dir] is not set: use html[lang] if present, else 'en-US'.
109
+ // 2. If html[dir] is not set: use html[lang] if it is a valid locale, else 'en-US'.
110
+ //
111
+ // Every value returned here is validated with isValidLocale() because Ark's
112
+ // LocaleProvider passes it straight to `new Intl.Locale()`, which throws on
113
+ // malformed input (e.g. '', '123', 'en_US'). An unvalidated value crashes the
114
+ // provider, and when the ErrorBoundary fallback also mounts BpkProvider the same
115
+ // bad value is re-read on every remount, producing an indefinite crash loop.
96
116
  //
97
117
  // SSR-safe: returns 'en-US' when document is unavailable.
98
118
  const getArkLocale = () => {
@@ -100,17 +120,12 @@ const getArkLocale = () => {
100
120
  const explicitDir = document.documentElement.getAttribute('dir');
101
121
  const lang = document.documentElement.getAttribute('lang');
102
122
  if (explicitDir === 'rtl' || explicitDir === 'ltr') {
103
- if (lang && getLangDir(lang) === explicitDir) return lang;
104
- return FALLBACK_LOCALE_BY_DIRECTION[explicitDir];
105
- }
106
- if (lang) {
107
- try {
108
- const locale = new Intl.Locale(lang);
109
- if (locale) return lang;
110
- } catch {
111
- // Invalid locale string — fall through to default
123
+ if (lang && isValidLocale(lang) && getLangDir(lang) === explicitDir) {
124
+ return lang;
112
125
  }
126
+ return FALLBACK_LOCALE_BY_DIRECTION[explicitDir];
113
127
  }
128
+ if (lang && isValidLocale(lang)) return lang;
114
129
  return 'en-US';
115
130
  };
116
131
 
@@ -3,6 +3,19 @@ import type StackOptionKeys from './BpkStack.constant';
3
3
  import type { BpkCommonLayoutProps } from './commonProps';
4
4
  import type { BpkSpacingValue, BpkResponsiveValue, BpkBasisValue } from './tokens';
5
5
  import type { BoxProps, FlexProps, GridProps, GridItemProps, StackProps } from '@chakra-ui/react';
6
+ /**
7
+ * Layout-level event props that should not be exposed on layout components.
8
+ * onClick is handled via BpkCommonLayoutProps; onFocus/onBlur are reintroduced
9
+ * on BpkBoxProps only.
10
+ */
11
+ type LayoutEventProps = 'onMouseEnter' | 'onMouseLeave' | 'onMouseOver' | 'onMouseOut' | 'onMouseDown' | 'onMouseUp' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp' | 'onKeyPress';
12
+ /**
13
+ * Shorthand props from the underlying layout system that we do NOT expose on
14
+ * Backpack layout components. These mostly mirror longer-form spacing,
15
+ * sizing and visual props that we already model explicitly via
16
+ * BpkCommonLayoutProps and BpkFlexGridProps.
17
+ */
18
+ type DisallowedShorthandProps = 'p' | 'pt' | 'pr' | 'pb' | 'pl' | 'px' | 'py' | 'm' | 'mt' | 'mr' | 'mb' | 'ml' | 'mx' | 'my' | 'w' | 'h' | 'minW' | 'maxW' | 'minH' | 'maxH' | 'bg' | 'rounded' | 'shadow';
6
19
  /**
7
20
  * Flexbox & grid layout props that we explicitly support on Backpack layout
8
21
  * components. These are a curated subset of the underlying Box flex/grid API
@@ -66,10 +79,17 @@ type BpkBoxResponsiveLayoutProps = {
66
79
  };
67
80
  type BpkBoxResponsiveLayoutPropKeys = keyof BpkBoxResponsiveLayoutProps;
68
81
  /**
69
- * Component-specific props for BpkBox.
70
- * Explicit allowlist does NOT inherit from Chakra BoxProps.
82
+ * Base type that removes common layout props, reserved props (className,
83
+ * children) and all layout-level event props from Chakra UI props.
84
+ *
85
+ * These will be replaced with Backpack-specific types.
86
+ */
87
+ export type RemoveCommonProps<T> = Omit<T, keyof BpkCommonLayoutProps | 'className' | 'children' | LayoutEventProps | FlexGridPropKeys | DisallowedShorthandProps>;
88
+ /**
89
+ * Component-specific props for BpkBox
90
+ * Includes all Box props except those in BpkCommonLayoutProps
71
91
  */
72
- export interface BpkBoxSpecificProps extends BpkBoxResponsiveLayoutProps, Omit<BpkFlexGridProps, BpkBoxResponsiveLayoutPropKeys> {
92
+ export interface BpkBoxSpecificProps extends Omit<RemoveCommonProps<BoxProps>, BpkBoxResponsiveLayoutPropKeys>, BpkBoxResponsiveLayoutProps, Omit<BpkFlexGridProps, BpkBoxResponsiveLayoutPropKeys> {
73
93
  }
74
94
  /**
75
95
  * Props for BpkBox component
@@ -127,10 +147,10 @@ export type BpkVesselProps = {
127
147
  as?: VesselElement;
128
148
  } & HTMLAttributes<HTMLElement>;
129
149
  /**
130
- * Component-specific props for BpkFlex.
131
- * Explicit allowlist does NOT inherit from Chakra FlexProps.
150
+ * Component-specific props for BpkFlex
151
+ * Includes all Flex props except those in BpkCommonLayoutProps
132
152
  */
133
- export interface BpkFlexSpecificProps {
153
+ export interface BpkFlexSpecificProps extends RemoveCommonProps<FlexProps> {
134
154
  direction?: BpkResponsiveValue<FlexProps['flexDirection']>;
135
155
  justify?: BpkResponsiveValue<FlexProps['justifyContent']>;
136
156
  align?: BpkResponsiveValue<FlexProps['alignItems']>;
@@ -148,10 +168,10 @@ export interface BpkFlexProps extends BpkCommonLayoutProps, BpkFlexSpecificProps
148
168
  children?: ReactNode;
149
169
  }
150
170
  /**
151
- * Component-specific props for BpkGrid.
152
- * Explicit allowlist does NOT inherit from Chakra GridProps.
171
+ * Component-specific props for BpkGrid
172
+ * Includes all Grid props except those in BpkCommonLayoutProps
153
173
  */
154
- export interface BpkGridSpecificProps {
174
+ export interface BpkGridSpecificProps extends RemoveCommonProps<GridProps> {
155
175
  justify?: BpkResponsiveValue<GridProps['justifyContent']>;
156
176
  align?: BpkResponsiveValue<GridProps['alignItems']>;
157
177
  templateColumns?: BpkResponsiveValue<GridProps['gridTemplateColumns']>;
@@ -174,10 +194,10 @@ export interface BpkGridProps extends BpkCommonLayoutProps, BpkGridSpecificProps
174
194
  children?: ReactNode;
175
195
  }
176
196
  /**
177
- * Component-specific props for BpkGridItem.
178
- * Explicit allowlist does NOT inherit from Chakra GridItemProps.
197
+ * Component-specific props for BpkGridItem
198
+ * Includes all GridItem props except those in BpkCommonLayoutProps
179
199
  */
180
- export interface BpkGridItemSpecificProps {
200
+ export interface BpkGridItemSpecificProps extends RemoveCommonProps<GridItemProps> {
181
201
  area?: GridItemProps['area'];
182
202
  colEnd?: GridItemProps['colEnd'];
183
203
  colStart?: GridItemProps['colStart'];
@@ -201,17 +221,13 @@ type BpkStackOptions = {
201
221
  [K in StackOptionKeysType]?: K extends keyof StackProps ? BpkResponsiveValue<StackProps[K]> | StackProps[K] : never;
202
222
  };
203
223
  /**
204
- * Component-specific props for BpkStack.
205
- * Explicit allowlist does NOT inherit from Chakra StackProps.
224
+ * Component-specific props for BpkStack
225
+ * Includes all Stack props except those in BpkCommonLayoutProps
206
226
  * Overrides StackOptions to support BpkResponsiveValue.
207
227
  * `alignItems` and `justifyContent` are accepted as semantic aliases for `align` and `justify`.
208
228
  * If both are provided, `align`/`justify` take precedence.
209
- *
210
- * `alignItems` and `justifyContent` are explicitly omitted from `BpkFlexGridProps` here so
211
- * that the responsive alias declarations below (which match BpkStackOptions) unambiguously
212
- * replace the non-responsive `BoxProps` variants from `BpkFlexGridProps`.
213
229
  */
214
- export interface BpkStackSpecificProps extends BpkStackOptions, Omit<BpkFlexGridProps, 'alignItems' | 'justifyContent'> {
230
+ export interface BpkStackSpecificProps extends Omit<RemoveCommonProps<StackProps>, StackOptionKeysType>, BpkStackOptions, Omit<BpkFlexGridProps, 'alignItems' | 'justifyContent'> {
215
231
  /** Alias for `align`. Maps to CSS `align-items`. Responsive — replaces the non-responsive BpkFlexGridProps.alignItems. */
216
232
  alignItems?: BpkStackOptions['align'];
217
233
  /** Alias for `justify`. Maps to CSS `justify-content`. Responsive — replaces the non-responsive BpkFlexGridProps.justifyContent. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "42.26.0",
3
+ "version": "42.27.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",