@clerk/react 6.8.0-snapshot.v20260604052353 → 6.8.0

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.
@@ -109,23 +109,45 @@ function withMaxAllowedInstancesGuard(WrappedComponent, name, error) {
109
109
  }
110
110
 
111
111
  // src/utils/useCustomElementPortal.tsx
112
- import { useState } from "react";
112
+ import { useRef, useState } from "react";
113
113
  import { createPortal } from "react-dom";
114
114
  var useCustomElementPortal = (elements) => {
115
115
  const [nodeMap, setNodeMap] = useState(/* @__PURE__ */ new Map());
116
- return elements.map((el) => ({
117
- id: el.id,
118
- mount: (node) => setNodeMap((prev) => new Map(prev).set(String(el.id), node)),
119
- unmount: () => setNodeMap((prev) => {
120
- const newMap = new Map(prev);
121
- newMap.set(String(el.id), null);
122
- return newMap;
123
- }),
124
- portal: () => {
125
- const node = nodeMap.get(String(el.id));
126
- return node ? createPortal(el.component, node) : null;
116
+ const nodeMapRef = useRef(nodeMap);
117
+ const elementsRef = useRef(/* @__PURE__ */ new Map());
118
+ const portalsRef = useRef(/* @__PURE__ */ new Map());
119
+ nodeMapRef.current = nodeMap;
120
+ elementsRef.current = new Map(elements.map((el) => [el.id, el.component]));
121
+ const elementIds = new Set(elements.map((el) => el.id));
122
+ portalsRef.current.forEach((_, id) => {
123
+ if (!elementIds.has(id)) {
124
+ portalsRef.current.delete(id);
127
125
  }
128
- }));
126
+ });
127
+ return elements.map((el) => {
128
+ const id = el.id;
129
+ const existingPortal = portalsRef.current.get(id);
130
+ if (existingPortal) {
131
+ return existingPortal;
132
+ }
133
+ const portal = () => {
134
+ const node = nodeMapRef.current.get(id);
135
+ const component = elementsRef.current.get(id);
136
+ return node ? createPortal(component, node) : null;
137
+ };
138
+ const customElementPortal = {
139
+ id: el.id,
140
+ mount: (node) => setNodeMap((prev) => new Map(prev).set(id, node)),
141
+ unmount: () => setNodeMap((prev) => {
142
+ const newMap = new Map(prev);
143
+ newMap.set(id, null);
144
+ return newMap;
145
+ }),
146
+ portal
147
+ };
148
+ portalsRef.current.set(id, customElementPortal);
149
+ return customElementPortal;
150
+ });
129
151
  };
130
152
 
131
153
  // src/utils/useCustomPages.tsx
@@ -186,6 +208,7 @@ var useCustomPages = (params, options) => {
186
208
  const { children, LinkComponent, PageComponent, MenuItemsComponent, reorderItemsLabels, componentName } = params;
187
209
  const { allowForAnyChildren = false } = options || {};
188
210
  const validChildren = [];
211
+ const portalIdCounts = /* @__PURE__ */ new Map();
189
212
  React4.Children.forEach(children, (child) => {
190
213
  if (!isThatComponent(child, PageComponent) && !isThatComponent(child, LinkComponent) && !isThatComponent(child, MenuItemsComponent)) {
191
214
  if (child && !allowForAnyChildren) {
@@ -195,11 +218,18 @@ var useCustomPages = (params, options) => {
195
218
  }
196
219
  const { props } = child;
197
220
  const { children: children2, label, url, labelIcon } = props;
221
+ const childKey = child.key;
198
222
  if (isThatComponent(child, PageComponent)) {
199
223
  if (isReorderItem(props, reorderItemsLabels)) {
200
224
  validChildren.push({ label });
201
225
  } else if (isCustomPage(props)) {
202
- validChildren.push({ label, labelIcon, children: children2, url });
226
+ validChildren.push({
227
+ label,
228
+ labelIcon,
229
+ children: children2,
230
+ url,
231
+ portalId: getCustomPagePortalId("page", props, childKey, portalIdCounts)
232
+ });
203
233
  } else {
204
234
  logErrorInDevMode(customPageWrongProps(componentName));
205
235
  return;
@@ -207,7 +237,12 @@ var useCustomPages = (params, options) => {
207
237
  }
208
238
  if (isThatComponent(child, LinkComponent)) {
209
239
  if (isExternalLink(props)) {
210
- validChildren.push({ label, labelIcon, url });
240
+ validChildren.push({
241
+ label,
242
+ labelIcon,
243
+ url,
244
+ portalId: getCustomPagePortalId("link", props, childKey, portalIdCounts)
245
+ });
211
246
  } else {
212
247
  logErrorInDevMode(customLinkWrongProps(componentName));
213
248
  return;
@@ -219,12 +254,12 @@ var useCustomPages = (params, options) => {
219
254
  const customLinkLabelIcons = [];
220
255
  validChildren.forEach((cp, index) => {
221
256
  if (isCustomPage(cp)) {
222
- customPageContents.push({ component: cp.children, id: index });
223
- customPageLabelIcons.push({ component: cp.labelIcon, id: index });
257
+ customPageContents.push({ component: cp.children, id: cp.portalId || index });
258
+ customPageLabelIcons.push({ component: cp.labelIcon, id: cp.portalId || index });
224
259
  return;
225
260
  }
226
261
  if (isExternalLink(cp)) {
227
- customLinkLabelIcons.push({ component: cp.labelIcon, id: index });
262
+ customLinkLabelIcons.push({ component: cp.labelIcon, id: cp.portalId || index });
228
263
  }
229
264
  });
230
265
  const customPageContentsPortals = useCustomElementPortal(customPageContents);
@@ -242,15 +277,15 @@ var useCustomPages = (params, options) => {
242
277
  portal: contentPortal,
243
278
  mount,
244
279
  unmount
245
- } = customPageContentsPortals.find((p) => p.id === index);
280
+ } = customPageContentsPortals.find((p) => p.id === (cp.portalId || index));
246
281
  const {
247
282
  portal: labelPortal,
248
283
  mount: mountIcon,
249
284
  unmount: unmountIcon
250
- } = customPageLabelIconsPortals.find((p) => p.id === index);
285
+ } = customPageLabelIconsPortals.find((p) => p.id === (cp.portalId || index));
251
286
  customPages.push({ label: cp.label, url: cp.url, mount, unmount, mountIcon, unmountIcon });
252
- customPagesPortals.push(contentPortal);
253
- customPagesPortals.push(labelPortal);
287
+ customPagesPortals.push({ key: `content:${cp.portalId || index}`, portal: contentPortal });
288
+ customPagesPortals.push({ key: `label:${cp.portalId || index}`, portal: labelPortal });
254
289
  return;
255
290
  }
256
291
  if (isExternalLink(cp)) {
@@ -258,14 +293,24 @@ var useCustomPages = (params, options) => {
258
293
  portal: labelPortal,
259
294
  mount: mountIcon,
260
295
  unmount: unmountIcon
261
- } = customLinkLabelIconsPortals.find((p) => p.id === index);
296
+ } = customLinkLabelIconsPortals.find((p) => p.id === (cp.portalId || index));
262
297
  customPages.push({ label: cp.label, url: cp.url, mountIcon, unmountIcon });
263
- customPagesPortals.push(labelPortal);
298
+ customPagesPortals.push({ key: `label:${cp.portalId || index}`, portal: labelPortal });
264
299
  return;
265
300
  }
266
301
  });
267
302
  return { customPages, customPagesPortals };
268
303
  };
304
+ var getCustomPagePortalId = (type, props, key, portalIdCounts) => {
305
+ var _a;
306
+ if (key != null) {
307
+ return `${type}:key:${key}`;
308
+ }
309
+ const baseId = `${type}:${props.label}:${props.url}`;
310
+ const occurrence = (_a = portalIdCounts.get(baseId)) != null ? _a : 0;
311
+ portalIdCounts.set(baseId, occurrence + 1);
312
+ return `${baseId}:${occurrence}`;
313
+ };
269
314
  var isReorderItem = (childProps, validItems) => {
270
315
  const { children, label, url, labelIcon } = childProps;
271
316
  return !children && !url && !labelIcon && validItems.some((v) => v === label);
@@ -309,6 +354,7 @@ var useCustomMenuItems = ({
309
354
  const validChildren = [];
310
355
  const customMenuItems = [];
311
356
  const customMenuItemsPortals = [];
357
+ const portalIdCounts = /* @__PURE__ */ new Map();
312
358
  React5.Children.forEach(children, (child) => {
313
359
  if (!isThatComponent(child, MenuItemsComponent) && !isThatComponent(child, UserProfileLinkComponent) && !isThatComponent(child, UserProfilePageComponent)) {
314
360
  if (child && !allowForAnyChildren) {
@@ -328,6 +374,7 @@ var useCustomMenuItems = ({
328
374
  return;
329
375
  }
330
376
  const { props: props2 } = child2;
377
+ const childKey = child2.key;
331
378
  const { label, labelIcon, href, onClick, open } = props2;
332
379
  if (isThatComponent(child2, MenuActionComponent)) {
333
380
  if (isReorderItem2(props2, reorderItemsLabels)) {
@@ -340,12 +387,14 @@ var useCustomMenuItems = ({
340
387
  if (onClick !== void 0) {
341
388
  validChildren.push({
342
389
  ...baseItem,
343
- onClick
390
+ onClick,
391
+ portalId: getCustomMenuItemPortalId("action", props2, childKey, portalIdCounts)
344
392
  });
345
393
  } else if (open !== void 0) {
346
394
  validChildren.push({
347
395
  ...baseItem,
348
- open: open.startsWith("/") ? open : `/${open}`
396
+ open: open.startsWith("/") ? open : `/${open}`,
397
+ portalId: getCustomMenuItemPortalId("action", props2, childKey, portalIdCounts)
349
398
  });
350
399
  } else {
351
400
  logErrorInDevMode2("Custom menu item must have either onClick or open property");
@@ -358,7 +407,12 @@ var useCustomMenuItems = ({
358
407
  }
359
408
  if (isThatComponent(child2, MenuLinkComponent)) {
360
409
  if (isExternalLink2(props2)) {
361
- validChildren.push({ label, labelIcon, href });
410
+ validChildren.push({
411
+ label,
412
+ labelIcon,
413
+ href,
414
+ portalId: getCustomMenuItemPortalId("link", props2, childKey, portalIdCounts)
415
+ });
362
416
  } else {
363
417
  logErrorInDevMode2(userButtonMenuItemLinkWrongProps);
364
418
  return;
@@ -370,10 +424,10 @@ var useCustomMenuItems = ({
370
424
  const customLinkLabelIcons = [];
371
425
  validChildren.forEach((mi, index) => {
372
426
  if (isCustomMenuItem(mi)) {
373
- customMenuItemLabelIcons.push({ component: mi.labelIcon, id: index });
427
+ customMenuItemLabelIcons.push({ component: mi.labelIcon, id: mi.portalId || index });
374
428
  }
375
429
  if (isExternalLink2(mi)) {
376
- customLinkLabelIcons.push({ component: mi.labelIcon, id: index });
430
+ customLinkLabelIcons.push({ component: mi.labelIcon, id: mi.portalId || index });
377
431
  }
378
432
  });
379
433
  const customMenuItemLabelIconsPortals = useCustomElementPortal(customMenuItemLabelIcons);
@@ -389,7 +443,7 @@ var useCustomMenuItems = ({
389
443
  portal: iconPortal,
390
444
  mount: mountIcon,
391
445
  unmount: unmountIcon
392
- } = customMenuItemLabelIconsPortals.find((p) => p.id === index);
446
+ } = customMenuItemLabelIconsPortals.find((p) => p.id === (mi.portalId || index));
393
447
  const menuItem = {
394
448
  label: mi.label,
395
449
  mountIcon,
@@ -401,25 +455,36 @@ var useCustomMenuItems = ({
401
455
  menuItem.open = mi.open;
402
456
  }
403
457
  customMenuItems.push(menuItem);
404
- customMenuItemsPortals.push(iconPortal);
458
+ customMenuItemsPortals.push({ key: `icon:${mi.portalId || index}`, portal: iconPortal });
405
459
  }
406
460
  if (isExternalLink2(mi)) {
407
461
  const {
408
462
  portal: iconPortal,
409
463
  mount: mountIcon,
410
464
  unmount: unmountIcon
411
- } = customLinkLabelIconsPortals.find((p) => p.id === index);
465
+ } = customLinkLabelIconsPortals.find((p) => p.id === (mi.portalId || index));
412
466
  customMenuItems.push({
413
467
  label: mi.label,
414
468
  href: mi.href,
415
469
  mountIcon,
416
470
  unmountIcon
417
471
  });
418
- customMenuItemsPortals.push(iconPortal);
472
+ customMenuItemsPortals.push({ key: `icon:${mi.portalId || index}`, portal: iconPortal });
419
473
  }
420
474
  });
421
475
  return { customMenuItems, customMenuItemsPortals };
422
476
  };
477
+ var getCustomMenuItemPortalId = (type, props, key, portalIdCounts) => {
478
+ var _a;
479
+ if (key != null) {
480
+ return `${type}:key:${key}`;
481
+ }
482
+ const target = props.href || props.open || "";
483
+ const baseId = `${type}:${props.label}:${target}`;
484
+ const occurrence = (_a = portalIdCounts.get(baseId)) != null ? _a : 0;
485
+ portalIdCounts.set(baseId, occurrence + 1);
486
+ return `${baseId}:${occurrence}`;
487
+ };
423
488
  var isReorderItem2 = (childProps, validItems) => {
424
489
  const { children, label, onClick, labelIcon } = childProps;
425
490
  return !children && !onClick && !labelIcon && validItems.some((v) => v === label);
@@ -434,7 +499,7 @@ var isExternalLink2 = (childProps) => {
434
499
  };
435
500
 
436
501
  // src/utils/useWaitForComponentMount.ts
437
- import { useEffect, useRef, useState as useState2 } from "react";
502
+ import { useEffect, useRef as useRef2, useState as useState2 } from "react";
438
503
  var createAwaitableMutationObserver = (globalOptions) => {
439
504
  const isReady = globalOptions == null ? void 0 : globalOptions.isReady;
440
505
  return (options) => new Promise((resolve, reject) => {
@@ -483,7 +548,7 @@ var waitForElementChildren = createAwaitableMutationObserver({
483
548
  }
484
549
  });
485
550
  function useWaitForComponentMount(component, options) {
486
- const watcherRef = useRef();
551
+ const watcherRef = useRef2();
487
552
  const [status, setStatus] = useState2("rendering");
488
553
  useEffect(() => {
489
554
  if (!component) {
@@ -526,16 +591,16 @@ var ClerkHostRenderer = class extends React6.PureComponent {
526
591
  this.rootRef = React6.createRef();
527
592
  }
528
593
  componentDidUpdate(_prevProps) {
529
- var _a, _b, _c, _d;
594
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
530
595
  if (!isMountProps(_prevProps) || !isMountProps(this.props)) {
531
596
  return;
532
597
  }
533
- const prevProps = without(_prevProps.props, "customPages", "customMenuItems", "children");
534
- const newProps = without(this.props.props, "customPages", "customMenuItems", "children");
535
- const customPagesChanged = ((_a = prevProps.customPages) == null ? void 0 : _a.length) !== ((_b = newProps.customPages) == null ? void 0 : _b.length);
536
- const customMenuItemsChanged = ((_c = prevProps.customMenuItems) == null ? void 0 : _c.length) !== ((_d = newProps.customMenuItems) == null ? void 0 : _d.length);
537
- const prevMenuItemsWithoutHandlers = stripMenuItemIconHandlers(_prevProps.props.customMenuItems);
538
- const newMenuItemsWithoutHandlers = stripMenuItemIconHandlers(this.props.props.customMenuItems);
598
+ const prevProps = without(_prevProps.props || {}, "customPages", "customMenuItems", "children");
599
+ const newProps = without(this.props.props || {}, "customPages", "customMenuItems", "children");
600
+ const customPagesChanged = ((_b = (_a = _prevProps.props) == null ? void 0 : _a.customPages) == null ? void 0 : _b.length) !== ((_d = (_c = this.props.props) == null ? void 0 : _c.customPages) == null ? void 0 : _d.length);
601
+ const customMenuItemsChanged = ((_f = (_e = _prevProps.props) == null ? void 0 : _e.customMenuItems) == null ? void 0 : _f.length) !== ((_h = (_g = this.props.props) == null ? void 0 : _g.customMenuItems) == null ? void 0 : _h.length);
602
+ const prevMenuItemsWithoutHandlers = stripMenuItemIconHandlers((_i = _prevProps.props) == null ? void 0 : _i.customMenuItems);
603
+ const newMenuItemsWithoutHandlers = stripMenuItemIconHandlers((_j = this.props.props) == null ? void 0 : _j.customMenuItems);
539
604
  if (!isDeeplyEqual(prevProps, newProps) || !isDeeplyEqual(prevMenuItemsWithoutHandlers, newMenuItemsWithoutHandlers) || customPagesChanged || customMenuItemsChanged) {
540
605
  if (this.rootRef.current) {
541
606
  this.props.updateProps({ node: this.rootRef.current, props: this.props.props });
@@ -605,7 +670,7 @@ var withClerk = (Component, displayNameOrOptions) => {
605
670
  // src/components/uiComponents.tsx
606
671
  var CustomPortalsRenderer = (props) => {
607
672
  var _a, _b;
608
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, (_a = props == null ? void 0 : props.customPagesPortals) == null ? void 0 : _a.map((portal, index) => createElement(portal, { key: index })), (_b = props == null ? void 0 : props.customMenuItemsPortals) == null ? void 0 : _b.map((portal, index) => createElement(portal, { key: index })));
673
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, (_a = props == null ? void 0 : props.customPagesPortals) == null ? void 0 : _a.map(({ key, portal }) => createElement(portal, { key })), (_b = props == null ? void 0 : props.customMenuItemsPortals) == null ? void 0 : _b.map(({ key, portal }) => createElement(portal, { key })));
609
674
  };
610
675
  var SignIn = withClerk(
611
676
  ({ clerk, component, fallback, ...props }) => {
@@ -1003,27 +1068,6 @@ var APIKeys = withClerk(
1003
1068
  },
1004
1069
  { component: "ApiKeys", renderWhileLoading: true }
1005
1070
  );
1006
- var ConfigureSSO = withClerk(
1007
- ({ clerk, component, fallback, ...props }) => {
1008
- const mountingStatus = useWaitForComponentMount(component);
1009
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
1010
- const rendererRootProps = {
1011
- ...shouldShowFallback && fallback && { style: { display: "none" } }
1012
- };
1013
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ React8.createElement(
1014
- ClerkHostRenderer,
1015
- {
1016
- component,
1017
- mount: clerk.mountConfigureSSO,
1018
- unmount: clerk.unmountConfigureSSO,
1019
- updateProps: clerk.__internal_updateProps,
1020
- props,
1021
- rootProps: rendererRootProps
1022
- }
1023
- ));
1024
- },
1025
- { component: "ConfigureSSO", renderWhileLoading: true }
1026
- );
1027
1071
  var OAuthConsent = withClerk(
1028
1072
  ({ clerk, component, fallback, ...props }) => {
1029
1073
  const mountingStatus = useWaitForComponentMount(component);
@@ -1413,7 +1457,6 @@ export {
1413
1457
  Waitlist,
1414
1458
  PricingTable,
1415
1459
  APIKeys,
1416
- ConfigureSSO,
1417
1460
  OAuthConsent,
1418
1461
  UserAvatar,
1419
1462
  TaskChooseOrganization,
@@ -1441,4 +1484,4 @@ export {
1441
1484
  __experimental_PaymentElementProvider,
1442
1485
  __experimental_PaymentElement
1443
1486
  };
1444
- //# sourceMappingURL=chunk-3ME65G46.mjs.map
1487
+ //# sourceMappingURL=chunk-FQVXBXXF.mjs.map