@primer/react 0.0.0-20260522133707 → 0.0.0-20260522135914

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260522133707
3
+ ## 0.0.0-20260522135914
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -8,9 +8,9 @@
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - Fake entry to force publishing
11
+ - [#7843](https://github.com/primer/react/pull/7843) [`1600cf5`](https://github.com/primer/react/commit/1600cf5e5318e626b6daa18fa2bf065a65ef3387) Thanks [@joshblack](https://github.com/joshblack)! - Update useMergedRefs so that in React 18 no warning is emitted
12
12
 
13
- - [#7847](https://github.com/primer/react/pull/7847) [`7fb2a81`](https://github.com/primer/react/commit/7fb2a81e5b34af32e4ddccd710964e7d96df23e1) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Fix PageLayout pane resize lag during fast window resizes. During an active window-resize gesture the pane now updates CSS variables and ARIA attributes via a single `requestAnimationFrame` per frame (DOM only, no React state). A single `startTransition` commit is deferred until the gesture ends, eliminating the "slowly catching up" churn caused by stacking a React render request every ~16 ms.
13
+ - Fake entry to force publishing
14
14
 
15
15
  ## 38.24.0
16
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"usePaneWidth.d.ts","sourceRoot":"","sources":["../../src/PageLayout/usePaneWidth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAQrD,KAAK,WAAW,GAAG,GAAG,MAAM,IAAI,CAAA;AAEhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,EAAE,WAAW,CAAA;IAChB,OAAO,EAAE,WAAW,CAAA;IACpB,GAAG,EAAE,WAAW,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAE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GAGG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B,6CAA6C;AAC7C,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAyC,CAAA;AAKhG,eAAO,MAAM,oBAAoB,GAAI,OAAO,cAAc,KAAG,KAAK,IAAI,kBAErE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,cAAc,KAAG,KAAK,IAAI,SAE5D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,GAAG,cAAc,KAAG,MAOvD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAGpD;AAID,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,WAAW,GAAG,IAAI,EAC1B,QAAQ;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAC,SASvD,CAAA;AA8BD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,SAAS,EACT,eAAe,EACf,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,mBAA2B,EAC3B,WAAW,EACX,YAAY,EAAE,eAAe,GAC9B,EAAE,mBAAmB,GAAG,kBAAkB,CAkR1C"}
@@ -247,8 +247,6 @@ function usePaneWidth(t0) {
247
247
  }
248
248
  const [maxPaneWidth, setMaxPaneWidth] = React.useState(t6);
249
249
  const maxPaneWidthRef = React.useRef(maxPaneWidth);
250
- const pendingMaxRef = React.useRef(maxPaneWidth);
251
- const pendingClampedRef = React.useRef(false);
252
250
  let t7;
253
251
  let t8;
254
252
  if ($[17] !== currentWidth) {
@@ -313,17 +311,47 @@ function usePaneWidth(t0) {
313
311
  let t13;
314
312
  if ($[26] !== constrainToViewport || $[27] !== contentWrapperRef || $[28] !== customMaxWidth || $[29] !== handleRef || $[30] !== minPaneWidth || $[31] !== paneRef || $[32] !== resizable) {
315
313
  t12 = () => {
316
- var _paneRef$current;
314
+ var _paneRef$current3;
317
315
  if (!resizable) {
318
316
  return;
319
317
  }
320
318
  let lastViewportWidth = window.innerWidth;
319
+ const syncAll = () => {
320
+ var _paneRef$current;
321
+ const currentViewportWidth = window.innerWidth;
322
+ const crossedBreakpoint = lastViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT || lastViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT;
323
+ lastViewportWidth = currentViewportWidth;
324
+ if (crossedBreakpoint) {
325
+ maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
326
+ }
327
+ const actualMax = getMaxPaneWidthRef.current();
328
+ (_paneRef$current = paneRef.current) === null || _paneRef$current === void 0 ? void 0 : _paneRef$current.style.setProperty("--pane-max-width", `${actualMax}px`);
329
+ const wasClamped = currentWidthRef.current > actualMax;
330
+ if (wasClamped) {
331
+ var _paneRef$current2;
332
+ currentWidthRef.current = actualMax;
333
+ (_paneRef$current2 = paneRef.current) === null || _paneRef$current2 === void 0 ? void 0 : _paneRef$current2.style.setProperty("--pane-width", `${actualMax}px`);
334
+ }
335
+ updateAriaValues(handleRef.current, {
336
+ max: actualMax,
337
+ current: currentWidthRef.current
338
+ });
339
+ const maxChanged = actualMax !== maxPaneWidthRef.current;
340
+ if (maxChanged || wasClamped) {
341
+ maxPaneWidthRef.current = actualMax;
342
+ startTransition(() => {
343
+ setMaxPaneWidth(actualMax);
344
+ if (wasClamped) {
345
+ setCurrentWidthState(actualMax);
346
+ }
347
+ });
348
+ }
349
+ };
321
350
  maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
322
351
  const initialMax = getMaxPaneWidthRef.current();
323
352
  maxPaneWidthRef.current = initialMax;
324
- pendingMaxRef.current = initialMax;
325
353
  setMaxPaneWidth(initialMax);
326
- (_paneRef$current = paneRef.current) === null || _paneRef$current === void 0 ? void 0 : _paneRef$current.style.setProperty("--pane-max-width", `${initialMax}px`);
354
+ (_paneRef$current3 = paneRef.current) === null || _paneRef$current3 === void 0 ? void 0 : _paneRef$current3.style.setProperty("--pane-max-width", `${initialMax}px`);
327
355
  updateAriaValues(handleRef.current, {
328
356
  min: minPaneWidth,
329
357
  max: initialMax,
@@ -332,71 +360,45 @@ function usePaneWidth(t0) {
332
360
  if (customMaxWidth !== null && !constrainToViewport) {
333
361
  return;
334
362
  }
363
+ let lastUpdateTime = 0;
364
+ let pendingUpdate = false;
335
365
  let rafId = null;
336
366
  let debounceId = null;
337
367
  let isResizing = false;
338
368
  const startResizeOptimizations = () => {
339
- var _paneRef$current2, _contentWrapperRef$cu;
369
+ var _paneRef$current4, _contentWrapperRef$cu;
340
370
  if (isResizing) {
341
371
  return;
342
372
  }
343
373
  isResizing = true;
344
- (_paneRef$current2 = paneRef.current) === null || _paneRef$current2 === void 0 ? void 0 : _paneRef$current2.setAttribute("data-dragging", "true");
374
+ (_paneRef$current4 = paneRef.current) === null || _paneRef$current4 === void 0 ? void 0 : _paneRef$current4.setAttribute("data-dragging", "true");
345
375
  (_contentWrapperRef$cu = contentWrapperRef.current) === null || _contentWrapperRef$cu === void 0 ? void 0 : _contentWrapperRef$cu.setAttribute("data-dragging", "true");
346
376
  };
347
377
  const endResizeOptimizations = () => {
348
- var _paneRef$current3, _contentWrapperRef$cu2;
378
+ var _paneRef$current5, _contentWrapperRef$cu2;
349
379
  if (!isResizing) {
350
380
  return;
351
381
  }
352
382
  isResizing = false;
353
- (_paneRef$current3 = paneRef.current) === null || _paneRef$current3 === void 0 ? void 0 : _paneRef$current3.removeAttribute("data-dragging");
383
+ (_paneRef$current5 = paneRef.current) === null || _paneRef$current5 === void 0 ? void 0 : _paneRef$current5.removeAttribute("data-dragging");
354
384
  (_contentWrapperRef$cu2 = contentWrapperRef.current) === null || _contentWrapperRef$cu2 === void 0 ? void 0 : _contentWrapperRef$cu2.removeAttribute("data-dragging");
355
385
  };
356
- const syncDom = () => {
357
- var _paneRef$current4;
358
- const currentViewportWidth = window.innerWidth;
359
- const crossedBreakpoint = lastViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT || lastViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT;
360
- lastViewportWidth = currentViewportWidth;
361
- if (crossedBreakpoint) {
362
- maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
363
- }
364
- const actualMax = getMaxPaneWidthRef.current();
365
- pendingMaxRef.current = actualMax;
366
- (_paneRef$current4 = paneRef.current) === null || _paneRef$current4 === void 0 ? void 0 : _paneRef$current4.style.setProperty("--pane-max-width", `${actualMax}px`);
367
- if (currentWidthRef.current > actualMax) {
368
- var _paneRef$current5;
369
- currentWidthRef.current = actualMax;
370
- pendingClampedRef.current = true;
371
- (_paneRef$current5 = paneRef.current) === null || _paneRef$current5 === void 0 ? void 0 : _paneRef$current5.style.setProperty("--pane-width", `${actualMax}px`);
372
- }
373
- updateAriaValues(handleRef.current, {
374
- max: actualMax,
375
- current: currentWidthRef.current
376
- });
377
- };
378
- const commitToReact = () => {
379
- const actualMax_0 = pendingMaxRef.current;
380
- const wasClamped = pendingClampedRef.current;
381
- pendingClampedRef.current = false;
382
- const maxChanged = actualMax_0 !== maxPaneWidthRef.current;
383
- if (maxChanged || wasClamped) {
384
- maxPaneWidthRef.current = actualMax_0;
385
- startTransition(() => {
386
- setMaxPaneWidth(actualMax_0);
387
- if (wasClamped) {
388
- setCurrentWidthState(actualMax_0);
389
- }
390
- });
391
- }
392
- };
393
386
  const handleResize = () => {
394
387
  startResizeOptimizations();
395
- if (rafId === null) {
396
- rafId = requestAnimationFrame(() => {
397
- rafId = null;
398
- syncDom();
399
- });
388
+ const now = Date.now();
389
+ if (now - lastUpdateTime >= 16) {
390
+ lastUpdateTime = now;
391
+ syncAll();
392
+ } else {
393
+ if (!pendingUpdate) {
394
+ pendingUpdate = true;
395
+ rafId = requestAnimationFrame(() => {
396
+ pendingUpdate = false;
397
+ rafId = null;
398
+ lastUpdateTime = Date.now();
399
+ syncAll();
400
+ });
401
+ }
400
402
  }
401
403
  if (debounceId !== null) {
402
404
  clearTimeout(debounceId);
@@ -404,8 +406,6 @@ function usePaneWidth(t0) {
404
406
  debounceId = setTimeout(() => {
405
407
  debounceId = null;
406
408
  endResizeOptimizations();
407
- syncDom();
408
- commitToReact();
409
409
  }, 150);
410
410
  };
411
411
  window.addEventListener("resize", handleResize);
@@ -29,7 +29,7 @@ import type { ForwardedRef, Ref as StandardRef } from 'react';
29
29
  * return <button ref={combinedRef} />
30
30
  * }
31
31
  */
32
- export declare function useMergedRefs<T>(refA: Ref<T | null>, refB: Ref<T | null>): (value: T | null) => () => void;
32
+ export declare function useMergedRefs<T>(refA: Ref<T | null>, refB: Ref<T | null>): (value: T | null) => (() => void) | undefined;
33
33
  type CleanupFunction = () => void;
34
34
  /**
35
35
  * React 19 supports callback refs that can return a cleanup function. If a cleanup function is returned, the
@@ -1 +1 @@
1
- {"version":3,"file":"useMergedRefs.d.ts","sourceRoot":"","sources":["../../src/hooks/useMergedRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,GAAG,IAAI,WAAW,EAAmB,MAAM,OAAO,CAAA;AAG7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,WAE7D,CAAC,GAAG,IAAI,gBAiBnB;AAED,KAAK,eAAe,GAAG,MAAM,IAAI,CAAA;AAEjC;;;GAGG;AAEH,KAAK,kBAAkB,CAAC,CAAC,IAAI;IAC3B,cAAc,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,eAAe,CAAA;CACpD,CAAC,gBAAgB,CAAC,CAAA;AAEnB;;;;;;;GAOG;AACH,KAAK,GAAG,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA"}
1
+ {"version":3,"file":"useMergedRefs.d.ts","sourceRoot":"","sources":["../../src/hooks/useMergedRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,GAAG,IAAI,WAAW,EAAmB,MAAM,OAAO,CAAA;AAa7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,WAE7D,CAAC,GAAG,IAAI,8BAsBnB;AAED,KAAK,eAAe,GAAG,MAAM,IAAI,CAAA;AAEjC;;;GAGG;AAEH,KAAK,kBAAkB,CAAC,CAAC,IAAI;IAC3B,cAAc,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,eAAe,CAAA;CACpD,CAAC,gBAAgB,CAAC,CAAA;AAEnB;;;;;;;GAOG;AACH,KAAK,GAAG,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA"}
@@ -1,5 +1,15 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import 'react';
3
+ import { reactMajorVersion, isExperimentalReactVersion } from '../utils/environment.js';
4
+
5
+ /**
6
+ * Cleanup functions for refs were introduced in React 19. For feature detection,
7
+ * we look to see if current version of React is >= 19 or if it is an
8
+ * experimental version of React
9
+ *
10
+ * @see https://react.dev/blog/2024/12/05/react-19
11
+ */
12
+ const supportsRefCleanup = reactMajorVersion >= 19 || isExperimentalReactVersion;
3
13
 
4
14
  /**
5
15
  * Combine two refs of matching type (typically an external or forwarded ref and an internal `useRef` object or
@@ -38,6 +48,9 @@ function useMergedRefs(refA, refB) {
38
48
  t0 = value => {
39
49
  const cleanupA = setRef(refA, value);
40
50
  const cleanupB = setRef(refB, value);
51
+ if (!supportsRefCleanup) {
52
+ return;
53
+ }
41
54
  return () => {
42
55
  if (cleanupA) {
43
56
  cleanupA();
@@ -3,5 +3,8 @@
3
3
  *
4
4
  * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
5
5
  */
6
- export const canUseDOM: boolean;
6
+ declare const canUseDOM: boolean;
7
+ declare const reactMajorVersion: number;
8
+ declare const isExperimentalReactVersion: boolean;
9
+ export { canUseDOM, reactMajorVersion, isExperimentalReactVersion };
7
10
  //# sourceMappingURL=environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gCAA8G"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,QAAA,MAAM,SAAS,SAAwF,CAAA;AAWvG,QAAA,MAAM,iBAAiB,QAAgC,CAAA;AAGvD,QAAA,MAAM,0BAA0B,SAAiD,CAAA;AAEjF,OAAO,EAAC,SAAS,EAAE,iBAAiB,EAAE,0BAA0B,EAAC,CAAA"}
@@ -1,9 +1,24 @@
1
+ import { version } from 'react';
2
+
1
3
  /**
2
4
  * Indicate whether current execution environment can access the DOM.
3
5
  *
4
6
  * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
5
7
  */
6
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
8
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,ssr-friendly/no-dom-globals-in-module-scope
7
9
  const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
8
10
 
9
- export { canUseDOM };
11
+ // Grab the major version from react. This could be formatted as any valid
12
+ // semver version, e.g.:
13
+ //
14
+ // - 19.0.0
15
+ // - 19.0.0-rc.1
16
+ // - 0.0.0-{channel}-{commit}-{time}
17
+ //
18
+ // So we only pull the first part of the version and parse it.
19
+ const reactVersion = version.split('.');
20
+ const reactMajorVersion = parseInt(reactVersion[0], 10);
21
+ const EXPERIMENTAL_REACT_VERSION_REGEX = /^0\.0\.0-experimental-[a-f0-9]{8}-\d{8}$/;
22
+ const isExperimentalReactVersion = EXPERIMENTAL_REACT_VERSION_REGEX.test(version);
23
+
24
+ export { canUseDOM, isExperimentalReactVersion, reactMajorVersion };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260522133707",
4
+ "version": "0.0.0-20260522135914",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",