@makeswift/runtime 0.2.20 → 0.2.21

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/dist/index.cjs.js CHANGED
@@ -328,6 +328,7 @@ async function introspect(element, client2, store) {
328
328
  const tableIds = /* @__PURE__ */ new Set();
329
329
  const pageIds = /* @__PURE__ */ new Set();
330
330
  const remaining = [element];
331
+ const seen = /* @__PURE__ */ new Set();
331
332
  let current;
332
333
  while (current = remaining.pop()) {
333
334
  let getResourcesFromElementDescriptors = function(elementDescriptors2, props) {
@@ -339,7 +340,12 @@ async function introspect(element, client2, store) {
339
340
  reactPage.getTypographyIds(descriptor, props[propName]).forEach((typographyId) => typographyIds.add(typographyId));
340
341
  reactPage.getTableIds(descriptor, props[propName]).forEach((tableId) => tableIds.add(tableId));
341
342
  reactPage.getPageIds(descriptor, props[propName]).forEach((pageId) => pageIds.add(pageId));
342
- reactPage.getElementChildren(descriptor, props[propName]).forEach((child) => remaining.push(child));
343
+ reactPage.getElementChildren(descriptor, props[propName]).forEach((child) => {
344
+ if (!seen.has(child.key)) {
345
+ seen.add(child.key);
346
+ remaining.push(child);
347
+ }
348
+ });
343
349
  if (descriptor.type === control.ShapeControlType) {
344
350
  const prop = props[propName];
345
351
  if (prop == null)
@@ -1007,7 +1013,7 @@ class Document$1 extends NextDocument__default["default"] {
1007
1013
  });
1008
1014
  }
1009
1015
  }
1010
- const version = "0.2.20";
1016
+ const version = "0.2.21";
1011
1017
  function isErrorWithMessage(error) {
1012
1018
  return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
1013
1019
  }
@@ -3396,6 +3402,7 @@ const DocumentContext = React.createContext(null);
3396
3402
  function useDocumentKey() {
3397
3403
  return React.useContext(DocumentContext);
3398
3404
  }
3405
+ const DocumentCyclesContext = React.createContext([]);
3399
3406
  function useStore() {
3400
3407
  return React.useContext(Context);
3401
3408
  }
@@ -3473,6 +3480,9 @@ const ElementReference = React.memo(React.forwardRef(function ElementReference2(
3473
3480
  });
3474
3481
  const globalElementData = (_a = data == null ? void 0 : data.globalElement) == null ? void 0 : _a.data;
3475
3482
  const elementReferenceDocument = useDocument(elementReference.key);
3483
+ const documentKey = elementReference.key;
3484
+ const documentKeys = React.useContext(DocumentCyclesContext);
3485
+ const providedDocumentKeys = React.useMemo(() => [...documentKeys, documentKey], [documentKeys, documentKey]);
3476
3486
  if (error != null) {
3477
3487
  return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
3478
3488
  ref,
@@ -3485,14 +3495,23 @@ const ElementReference = React.memo(React.forwardRef(function ElementReference2(
3485
3495
  text: "This global component doesn't exist"
3486
3496
  });
3487
3497
  }
3488
- return elementReferenceDocument != null ? /* @__PURE__ */ jsxRuntime.jsx(Document, {
3489
- document: elementReferenceDocument,
3490
- ref
3491
- }) : /* @__PURE__ */ jsxRuntime.jsx(DisableRegisterElement.Provider, {
3492
- value: true,
3493
- children: /* @__PURE__ */ jsxRuntime.jsx(ElementData, {
3494
- elementData: globalElementData,
3498
+ if (documentKeys.includes(documentKey)) {
3499
+ return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
3500
+ ref,
3501
+ text: "This global component contains itself!"
3502
+ });
3503
+ }
3504
+ return /* @__PURE__ */ jsxRuntime.jsx(DocumentCyclesContext.Provider, {
3505
+ value: providedDocumentKeys,
3506
+ children: elementReferenceDocument != null ? /* @__PURE__ */ jsxRuntime.jsx(Document, {
3507
+ document: elementReferenceDocument,
3495
3508
  ref
3509
+ }) : /* @__PURE__ */ jsxRuntime.jsx(DisableRegisterElement.Provider, {
3510
+ value: true,
3511
+ children: /* @__PURE__ */ jsxRuntime.jsx(ElementData, {
3512
+ elementData: globalElementData,
3513
+ ref
3514
+ })
3496
3515
  })
3497
3516
  });
3498
3517
  }));