@primer/react 0.0.0-20260224134212 → 0.0.0-20260224140728

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-20260224134212
3
+ ## 0.0.0-20260224140728
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"descendant-registry.d.ts","sourceRoot":"","sources":["../../src/utils/descendant-registry.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAGd,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,4CAA4C;IAC5C,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,CAAC;0CAsCG,aAAa,CAAC,CAAC,CAAC;;mCAPrB,CAAC;mDAXe,MAAM,CAAC;EAiG9D"}
1
+ {"version":3,"file":"descendant-registry.d.ts","sourceRoot":"","sources":["../../src/utils/descendant-registry.tsx"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAGd,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,4CAA4C;IAC5C,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,CAAC;0CA4CG,aAAa,CAAC,CAAC,CAAC;;mCATrB,CAAC;mDAbe,MAAM,CAAC;EAqG9D"}
@@ -1,5 +1,5 @@
1
1
  import { c } from 'react-compiler-runtime';
2
- import { useContext, useId, useEffect, useState, useRef, useCallback, useMemo, createContext } from 'react';
2
+ import { useContext, useId, useEffect, useState, useRef, useReducer, createContext } from 'react';
3
3
  import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect.js';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
@@ -21,6 +21,7 @@ import { jsx } from 'react/jsx-runtime';
21
21
  function createDescendantRegistry() {
22
22
  const Context = /*#__PURE__*/createContext({
23
23
  register: () => () => {},
24
+ updateValue: () => {},
24
25
  key: -1
25
26
  });
26
27
 
@@ -38,34 +39,55 @@ function createDescendantRegistry() {
38
39
  return new Map();
39
40
  }
40
41
  function useRegisterDescendantCallback(valueCallback) {
41
- const $ = c(9);
42
+ const $ = c(16);
42
43
  const {
43
44
  register,
45
+ updateValue,
44
46
  key
45
47
  } = useContext(Context);
46
48
  const id = useId();
47
49
  let t0;
48
- if ($[0] !== id || $[1] !== register || $[2] !== valueCallback) {
49
- t0 = () => register(id, valueCallback());
50
+ if ($[0] !== id || $[1] !== register) {
51
+ t0 = () => register(id);
50
52
  $[0] = id;
51
53
  $[1] = register;
52
- $[2] = valueCallback;
53
- $[3] = t0;
54
+ $[2] = t0;
54
55
  } else {
55
- t0 = $[3];
56
+ t0 = $[2];
56
57
  }
57
58
  let t1;
58
- if ($[4] !== id || $[5] !== key || $[6] !== register || $[7] !== valueCallback) {
59
- t1 = [register, id, valueCallback, key];
60
- $[4] = id;
61
- $[5] = key;
62
- $[6] = register;
63
- $[7] = valueCallback;
64
- $[8] = t1;
59
+ if ($[3] !== id || $[4] !== key || $[5] !== register) {
60
+ t1 = [register, id, key];
61
+ $[3] = id;
62
+ $[4] = key;
63
+ $[5] = register;
64
+ $[6] = t1;
65
65
  } else {
66
- t1 = $[8];
66
+ t1 = $[6];
67
67
  }
68
68
  useEffect(t0, t1);
69
+ let t2;
70
+ if ($[7] !== id || $[8] !== updateValue || $[9] !== valueCallback) {
71
+ t2 = () => updateValue(id, valueCallback());
72
+ $[7] = id;
73
+ $[8] = updateValue;
74
+ $[9] = valueCallback;
75
+ $[10] = t2;
76
+ } else {
77
+ t2 = $[10];
78
+ }
79
+ let t3;
80
+ if ($[11] !== id || $[12] !== key || $[13] !== updateValue || $[14] !== valueCallback) {
81
+ t3 = [updateValue, id, valueCallback, key];
82
+ $[11] = id;
83
+ $[12] = key;
84
+ $[13] = updateValue;
85
+ $[14] = valueCallback;
86
+ $[15] = t3;
87
+ } else {
88
+ t3 = $[15];
89
+ }
90
+ useEffect(t2, t3);
69
91
  return id;
70
92
  }
71
93
 
@@ -83,87 +105,130 @@ function createDescendantRegistry() {
83
105
  const valueCallback = t0;
84
106
  return useRegisterDescendantCallback(valueCallback);
85
107
  }
108
+ const unsetValue = Symbol('unset');
86
109
 
87
110
  /** Provide context for registering descendant components. This only needs to wrap `children`. */
88
- function Provider({
89
- children,
90
- setRegistry
91
- }) {
92
- const workingRegistryRef = useRef('queued');
93
-
94
- /** State value to trigger a re-render and force all descendants to re-register. This ensures everything remains ordered. */
95
- const [key, setKey] = useState(0);
96
-
97
- /**
98
- * Tracks the `children` reference from the previous render to detect when the parent
99
- * re-renders with new children (e.g., due to a reorder), as opposed to a Provider re-render
100
- * triggered by our own `setRegistry` call (where children stay the same reference).
101
- */
102
- const prevChildrenRef = useRef(children);
103
-
104
- // Instantiate a new map before all descendants' effects run to populate it
105
- useIsomorphicLayoutEffect(function instantiateNewRegistry() {
106
- if (workingRegistryRef.current === 'queued') {
107
- workingRegistryRef.current = new Map();
108
- }
109
- });
110
-
111
- // Each descendant will register itself. Initially this will just update the map. After the initial render and
112
- // commit, any descendant updates (mounts, unmounts, or value changes) will trigger a full recalculation of the
113
- // registry. This is necessary because a descendant might mount into the middle of the tree, and the only way for
114
- // the provider to know that is to re-render the tree and listen to every descendant effect in order.
115
- const register = useCallback((id, value) => {
116
- function queueRebuild() {
117
- // If we instantiate a new map now, we'd commit it in the ensuing provider effect, which would trigger a
118
- // new state update and cause an infinite render loop. So we wait to instantiate it until the next layout effect,
119
- // which we know will happen because we update state to queue a new render.
120
- workingRegistryRef.current = 'queued';
121
- setKey(prev => prev + 1);
122
- }
123
- if (workingRegistryRef.current instanceof Map) {
124
- workingRegistryRef.current.set(id, value);
125
- } else if (workingRegistryRef.current === 'idle') {
126
- queueRebuild();
127
- }
128
- return () => {
111
+ function Provider(t0) {
112
+ const $ = c(13);
113
+ const {
114
+ children,
115
+ setRegistry
116
+ } = t0;
117
+ const workingRegistryRef = useRef("queued");
118
+ const [key, incrementKey] = useReducer(_temp2, 0);
119
+ let t1;
120
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
121
+ t1 = () => {
122
+ workingRegistryRef.current = "queued";
123
+ incrementKey();
124
+ };
125
+ $[0] = t1;
126
+ } else {
127
+ t1 = $[0];
128
+ }
129
+ const queueRebuild = t1;
130
+ let t2;
131
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
132
+ t2 = function instantiateNewRegistry() {
133
+ if (workingRegistryRef.current === "queued") {
134
+ workingRegistryRef.current = new Map();
135
+ }
136
+ };
137
+ $[1] = t2;
138
+ } else {
139
+ t2 = $[1];
140
+ }
141
+ useIsomorphicLayoutEffect(t2);
142
+ let t3;
143
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
144
+ t3 = id => {
129
145
  if (workingRegistryRef.current instanceof Map) {
130
- workingRegistryRef.current.delete(id);
131
- } else if (workingRegistryRef.current === 'idle') {
132
- queueRebuild();
146
+ workingRegistryRef.current.set(id, unsetValue);
147
+ } else {
148
+ if (workingRegistryRef.current === "idle") {
149
+ queueRebuild();
150
+ }
133
151
  }
152
+ return () => {
153
+ if (workingRegistryRef.current instanceof Map) {
154
+ workingRegistryRef.current.delete(id);
155
+ } else {
156
+ if (workingRegistryRef.current === "idle") {
157
+ queueRebuild();
158
+ }
159
+ }
160
+ };
134
161
  };
135
- }, []);
136
-
137
- // After all descendants' effects complete, commit the working registry to state. When the
138
- // registry is idle and the children reference changed (indicating the parent re-rendered with
139
- // new children, e.g., due to a reorder), queue a rebuild so all descendants re-register in
140
- // their current render order, keeping the registry accurate.
141
- //
142
- // This effect intentionally omits a dependency array so it runs after every render. Adding
143
- // deps would prevent the registry Map from being committed after rebuild cycles (where `key`
144
- // increments but `children` and `setRegistry` stay the same).
145
- // eslint-disable-next-line react-hooks/exhaustive-deps
146
- useEffect(function commitWorkingRegistry() {
147
- const childrenChanged = prevChildrenRef.current !== children;
148
- prevChildrenRef.current = children;
149
- if (workingRegistryRef.current instanceof Map) {
150
- setRegistry(workingRegistryRef.current);
151
- workingRegistryRef.current = 'idle';
152
- } else if (workingRegistryRef.current === 'idle' && childrenChanged) {
153
- // The children changed (e.g., reordering) without triggering any descendant
154
- // mount/unmount/update. Trigger a rebuild to capture the new render order.
155
- workingRegistryRef.current = 'queued';
156
- setKey(prev => prev + 1);
157
- }
158
- });
159
- const contextValue = useMemo(() => ({
160
- register,
161
- key
162
- }), [register, key]);
163
- return /*#__PURE__*/jsx(Context.Provider, {
164
- value: contextValue,
165
- children: children
166
- });
162
+ $[2] = t3;
163
+ } else {
164
+ t3 = $[2];
165
+ }
166
+ const register = t3;
167
+ let t4;
168
+ if ($[3] !== setRegistry) {
169
+ t4 = (id_0, value) => {
170
+ if (workingRegistryRef.current instanceof Map) {
171
+ workingRegistryRef.current.set(id_0, value);
172
+ } else {
173
+ if (workingRegistryRef.current === "idle") {
174
+ setRegistry(prev_0 => new Map(prev_0).set(id_0, value));
175
+ }
176
+ }
177
+ };
178
+ $[3] = setRegistry;
179
+ $[4] = t4;
180
+ } else {
181
+ t4 = $[4];
182
+ }
183
+ const updateValue = t4;
184
+ let t5;
185
+ if ($[5] !== setRegistry) {
186
+ t5 = function commitWorkingRegistry() {
187
+ if (workingRegistryRef.current instanceof Map) {
188
+ const setEntries = Array.from(workingRegistryRef.current.entries()).filter(_temp3);
189
+ setRegistry(new Map(setEntries));
190
+ workingRegistryRef.current = "idle";
191
+ }
192
+ };
193
+ $[5] = setRegistry;
194
+ $[6] = t5;
195
+ } else {
196
+ t5 = $[6];
197
+ }
198
+ useEffect(t5);
199
+ let t6;
200
+ if ($[7] !== key || $[8] !== updateValue) {
201
+ t6 = {
202
+ register,
203
+ updateValue,
204
+ key
205
+ };
206
+ $[7] = key;
207
+ $[8] = updateValue;
208
+ $[9] = t6;
209
+ } else {
210
+ t6 = $[9];
211
+ }
212
+ const contextValue = t6;
213
+ let t7;
214
+ if ($[10] !== children || $[11] !== contextValue) {
215
+ t7 = /*#__PURE__*/jsx(Context.Provider, {
216
+ value: contextValue,
217
+ children: children
218
+ });
219
+ $[10] = children;
220
+ $[11] = contextValue;
221
+ $[12] = t7;
222
+ } else {
223
+ t7 = $[12];
224
+ }
225
+ return t7;
226
+ }
227
+ function _temp3(entry) {
228
+ return entry[1] !== unsetValue;
229
+ }
230
+ function _temp2(prev) {
231
+ return prev + 1;
167
232
  }
168
233
  return {
169
234
  Provider,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260224134212",
4
+ "version": "0.0.0-20260224140728",
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",