@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.es.js CHANGED
@@ -293,6 +293,7 @@ async function introspect(element, client, store) {
293
293
  const tableIds = /* @__PURE__ */ new Set();
294
294
  const pageIds = /* @__PURE__ */ new Set();
295
295
  const remaining = [element];
296
+ const seen = /* @__PURE__ */ new Set();
296
297
  let current;
297
298
  while (current = remaining.pop()) {
298
299
  let getResourcesFromElementDescriptors = function(elementDescriptors2, props) {
@@ -304,7 +305,12 @@ async function introspect(element, client, store) {
304
305
  getTypographyIds(descriptor, props[propName]).forEach((typographyId) => typographyIds.add(typographyId));
305
306
  getTableIds(descriptor, props[propName]).forEach((tableId) => tableIds.add(tableId));
306
307
  getPageIds(descriptor, props[propName]).forEach((pageId) => pageIds.add(pageId));
307
- getElementChildren(descriptor, props[propName]).forEach((child) => remaining.push(child));
308
+ getElementChildren(descriptor, props[propName]).forEach((child) => {
309
+ if (!seen.has(child.key)) {
310
+ seen.add(child.key);
311
+ remaining.push(child);
312
+ }
313
+ });
308
314
  if (descriptor.type === ShapeControlType) {
309
315
  const prop = props[propName];
310
316
  if (prop == null)
@@ -972,7 +978,7 @@ class Document$1 extends NextDocument {
972
978
  });
973
979
  }
974
980
  }
975
- const version = "0.2.20";
981
+ const version = "0.2.21";
976
982
  function isErrorWithMessage(error) {
977
983
  return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
978
984
  }
@@ -3333,6 +3339,7 @@ const DocumentContext = createContext(null);
3333
3339
  function useDocumentKey() {
3334
3340
  return useContext(DocumentContext);
3335
3341
  }
3342
+ const DocumentCyclesContext = createContext([]);
3336
3343
  function useStore() {
3337
3344
  return useContext(Context);
3338
3345
  }
@@ -3410,6 +3417,9 @@ const ElementReference = memo(forwardRef(function ElementReference2({
3410
3417
  });
3411
3418
  const globalElementData = (_a = data == null ? void 0 : data.globalElement) == null ? void 0 : _a.data;
3412
3419
  const elementReferenceDocument = useDocument(elementReference.key);
3420
+ const documentKey = elementReference.key;
3421
+ const documentKeys = useContext(DocumentCyclesContext);
3422
+ const providedDocumentKeys = useMemo(() => [...documentKeys, documentKey], [documentKeys, documentKey]);
3413
3423
  if (error != null) {
3414
3424
  return /* @__PURE__ */ jsx(FallbackComponent, {
3415
3425
  ref,
@@ -3422,14 +3432,23 @@ const ElementReference = memo(forwardRef(function ElementReference2({
3422
3432
  text: "This global component doesn't exist"
3423
3433
  });
3424
3434
  }
3425
- return elementReferenceDocument != null ? /* @__PURE__ */ jsx(Document, {
3426
- document: elementReferenceDocument,
3427
- ref
3428
- }) : /* @__PURE__ */ jsx(DisableRegisterElement.Provider, {
3429
- value: true,
3430
- children: /* @__PURE__ */ jsx(ElementData, {
3431
- elementData: globalElementData,
3435
+ if (documentKeys.includes(documentKey)) {
3436
+ return /* @__PURE__ */ jsx(FallbackComponent, {
3437
+ ref,
3438
+ text: "This global component contains itself!"
3439
+ });
3440
+ }
3441
+ return /* @__PURE__ */ jsx(DocumentCyclesContext.Provider, {
3442
+ value: providedDocumentKeys,
3443
+ children: elementReferenceDocument != null ? /* @__PURE__ */ jsx(Document, {
3444
+ document: elementReferenceDocument,
3432
3445
  ref
3446
+ }) : /* @__PURE__ */ jsx(DisableRegisterElement.Provider, {
3447
+ value: true,
3448
+ children: /* @__PURE__ */ jsx(ElementData, {
3449
+ elementData: globalElementData,
3450
+ ref
3451
+ })
3433
3452
  })
3434
3453
  });
3435
3454
  }));