@octanejs/base-ui 0.1.26 → 0.1.28

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/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@octanejs/base-ui",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "engines": {
7
8
  "node": ">=22.22.2"
8
9
  },
@@ -41,10 +42,10 @@
41
42
  "@floating-ui/utils": "^0.2.12",
42
43
  "aria-hidden": "^1.2.6",
43
44
  "tabbable": "^6.5.0",
44
- "@octanejs/floating-ui": "0.1.27"
45
+ "@octanejs/floating-ui": "0.1.29"
45
46
  },
46
47
  "peerDependencies": {
47
- "octane": "0.1.28"
48
+ "octane": "0.1.30"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@base-ui/react": "^1.6.0",
@@ -53,7 +54,7 @@
53
54
  "react": "^19.2.7",
54
55
  "react-dom": "^19.2.7",
55
56
  "vitest": "^4.1.10",
56
- "octane": "0.1.28"
57
+ "octane": "0.1.30"
57
58
  },
58
59
  "scripts": {
59
60
  "test": "vitest run"
@@ -1,25 +1,33 @@
1
1
  // Ported from .base-ui/packages/utils/src/usePreviousValue.ts. Returns the argument's previous
2
- // value (null before there is one), updating during render rather than in an effect so the
3
- // previous value is available on the same render the current one changes.
2
+ // value (null before there is one). Linked state makes the previous committed value available
3
+ // on the same render the current one changes without publishing abandoned render history.
4
4
  //
5
5
  // SLOT: plain-`.ts` hook; the trailing arg is the caller's slot.
6
- import { useState } from 'octane';
6
+ import { type LinkedStatePrevious, useLinkedState } from 'octane';
7
7
 
8
8
  import { S, splitSlot, subSlot } from '../internal';
9
9
 
10
+ function previousCommittedValue<Value>(
11
+ _current: Value,
12
+ previous: LinkedStatePrevious<Value, Value | null> | undefined,
13
+ ): Value | null {
14
+ return previous === undefined ? null : previous.source;
15
+ }
16
+
17
+ const PREVIOUS_VALUE_OPTIONS = {
18
+ sourceEqual: <Value>(previous: Value, next: Value) => previous === next,
19
+ };
20
+
10
21
  export function usePreviousValue<T>(...args: any[]): T | null {
11
22
  const [user, slotArg] = splitSlot(args);
12
23
  const slot = slotArg ?? S('usePreviousValue');
13
24
  const value = user[0] as T;
14
25
 
15
- const [state, setState] = useState<{ current: T; previous: T | null }>(
16
- { current: value, previous: null },
26
+ const [previous] = useLinkedState<T, T | null>(
27
+ value,
28
+ previousCommittedValue,
29
+ PREVIOUS_VALUE_OPTIONS,
17
30
  subSlot(slot, 'st'),
18
31
  );
19
-
20
- if (value !== state.current) {
21
- setState({ current: value, previous: state.current });
22
- }
23
-
24
- return state.previous;
32
+ return previous;
25
33
  }