@domql/element 2.5.118 → 2.5.121

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/create.js CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  applyVariant,
36
36
  checkIfKeyIsComponent,
37
37
  createValidDomqlObjectFromSugar,
38
+ detectInfiniteLoop,
38
39
  isVariant
39
40
  } from './utils/component'
40
41
 
@@ -46,8 +47,6 @@ const ENV = process.env.NODE_ENV
46
47
  const create = (element, parent, key, options = OPTIONS.create || {}, attachOptions) => {
47
48
  cacheOptions(element, options)
48
49
 
49
- // if (key === 'Title') debugger
50
-
51
50
  // if element is STRING
52
51
  if (checkIfPrimitive(element)) {
53
52
  element = applyValueAsText(element, parent, key)
@@ -212,12 +211,22 @@ const addElementIntoParentChildren = (element, parent) => {
212
211
  if (parent.__ref && parent.__ref.__children) parent.__ref.__children.push(element.key)
213
212
  }
214
213
 
214
+ const visitedElements = new WeakMap()
215
215
  const renderElement = (element, parent, options, attachOptions) => {
216
+ if (visitedElements.has(element)) {
217
+ if (ENV === 'test' || ENV === 'development') console.warn('Cyclic rendering detected:', element.__ref.__path)
218
+ }
219
+
220
+ visitedElements.set(element, true)
221
+
216
222
  const { __ref: ref, key } = element
217
223
 
218
224
  // CREATE a real NODE
219
225
  try {
226
+ const isInfiniteLoopDetected = detectInfiniteLoop(ref.__path)
227
+ if (ref.__uniqId || isInfiniteLoopDetected) return
220
228
  createNode(element, options)
229
+ ref.__uniqId = Math.random()
221
230
  } catch (e) {
222
231
  if (ENV === 'test' || ENV === 'development') console.warn(element, e)
223
232
  }
@@ -167,10 +167,20 @@ const addElementIntoParentChildren = (element, parent) => {
167
167
  if (parent.__ref && parent.__ref.__children)
168
168
  parent.__ref.__children.push(element.key);
169
169
  };
170
+ const visitedElements = /* @__PURE__ */ new WeakMap();
170
171
  const renderElement = (element, parent, options, attachOptions) => {
172
+ if (visitedElements.has(element)) {
173
+ if (ENV === "test" || ENV === "development")
174
+ console.warn("Cyclic rendering detected:", element.__ref.__path);
175
+ }
176
+ visitedElements.set(element, true);
171
177
  const { __ref: ref, key } = element;
172
178
  try {
179
+ const isInfiniteLoopDetected = (0, import_component.detectInfiniteLoop)(ref.__path);
180
+ if (ref.__uniqId || isInfiniteLoopDetected)
181
+ return;
173
182
  (0, import_node.default)(element, options);
183
+ ref.__uniqId = Math.random();
174
184
  } catch (e) {
175
185
  if (ENV === "test" || ENV === "development")
176
186
  console.warn(element, e);
package/dist/cjs/node.js CHANGED
@@ -78,7 +78,9 @@ const createNode = (element, options) => {
78
78
  if (isElement) {
79
79
  const { hasDefine, hasContextDefine } = isElement;
80
80
  if (element[param] && !hasDefine && !hasContextDefine) {
81
- const createAsync = () => (0, import_create.default)((0, import_utils.exec)(value, element), element, param, options);
81
+ const createAsync = () => {
82
+ (0, import_create.default)((0, import_utils.exec)(value, element), element, param, options);
83
+ };
82
84
  if (element.props && element.props.lazyLoad || options.lazyLoad) {
83
85
  window.requestAnimationFrame(() => createAsync());
84
86
  } else
@@ -25,6 +25,7 @@ __export(component_exports, {
25
25
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
26
26
  checkIfKeyIsProperty: () => checkIfKeyIsProperty,
27
27
  createValidDomqlObjectFromSugar: () => createValidDomqlObjectFromSugar,
28
+ detectInfiniteLoop: () => detectInfiniteLoop,
28
29
  extendizeByKey: () => extendizeByKey,
29
30
  hasVariantProp: () => hasVariantProp,
30
31
  isVariant: () => isVariant,
@@ -174,3 +175,26 @@ const applyVariant = (element) => {
174
175
  });
175
176
  return element;
176
177
  };
178
+ const detectInfiniteLoop = (arr) => {
179
+ const maxRepeats = 10;
180
+ let pattern = [];
181
+ let repeatCount = 0;
182
+ for (let i = 0; i < arr.length; i++) {
183
+ if (pattern.length < 2) {
184
+ pattern.push(arr[i]);
185
+ } else {
186
+ if (arr[i] === pattern[i % 2]) {
187
+ repeatCount++;
188
+ } else {
189
+ pattern = [arr[i - 1], arr[i]];
190
+ repeatCount = 1;
191
+ }
192
+ if (repeatCount >= maxRepeats * 2) {
193
+ if (ENV === "test" || ENV === "development") {
194
+ console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
195
+ }
196
+ return true;
197
+ }
198
+ }
199
+ }
200
+ };
package/node.js CHANGED
@@ -73,7 +73,9 @@ export const createNode = (element, options) => {
73
73
  if (isElement) {
74
74
  const { hasDefine, hasContextDefine } = isElement
75
75
  if (element[param] && !hasDefine && !hasContextDefine) {
76
- const createAsync = () => create(exec(value, element), element, param, options)
76
+ const createAsync = () => {
77
+ create(exec(value, element), element, param, options)
78
+ }
77
79
 
78
80
  if ((element.props && element.props.lazyLoad) || options.lazyLoad) {
79
81
  window.requestAnimationFrame(() => createAsync())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.118",
3
+ "version": "2.5.121",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -31,7 +31,7 @@
31
31
  "@domql/state": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "984906ba70b23710f6f1a1895b41b4e8710e4c3d",
34
+ "gitHead": "5130bdaa1358d22df75746616dd3387b8a56b55b",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
package/props/create.js CHANGED
@@ -51,10 +51,6 @@ export const syncProps = (props, element) => {
51
51
  export const createProps = function (element, parent, cached) {
52
52
  const { __ref: ref } = element
53
53
 
54
- // if (element.parent.key === '0' && element.key === 'editor') {
55
- // debugger
56
- // }
57
-
58
54
  const applyProps = () => {
59
55
  const propsStack = cached || createPropsStack(element, parent)
60
56
  if (propsStack.length) {
package/update.js CHANGED
@@ -82,7 +82,6 @@ const update = function (params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
82
82
 
83
83
  const overwriteChanges = overwriteDeep(element, params, METHODS_EXL)
84
84
  const execChanges = throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
85
- // if (element.key === 'Navigation') debugger
86
85
  const definedChanges = throughUpdatedDefine(element)
87
86
 
88
87
  if (!options.isForced && !options.preventListeners) {
@@ -165,3 +165,33 @@ export const applyVariant = (element) => {
165
165
 
166
166
  return element
167
167
  }
168
+
169
+ export const detectInfiniteLoop = arr => {
170
+ const maxRepeats = 10 // Maximum allowed repetitions
171
+ let pattern = []
172
+ let repeatCount = 0
173
+
174
+ for (let i = 0; i < arr.length; i++) {
175
+ if (pattern.length < 2) {
176
+ // Build the initial pattern with two consecutive elements
177
+ pattern.push(arr[i])
178
+ } else {
179
+ // Check if the current element follows the repeating pattern
180
+ if (arr[i] === pattern[i % 2]) {
181
+ repeatCount++
182
+ } else {
183
+ // If there's a mismatch, reset the pattern and repeat counter
184
+ pattern = [arr[i - 1], arr[i]]
185
+ repeatCount = 1 // Reset to 1 because we start a new potential pattern
186
+ }
187
+
188
+ // If the pattern repeats more than `maxRepeats`, throw a warning
189
+ if (repeatCount >= maxRepeats * 2) {
190
+ if (ENV === 'test' || ENV === 'development') {
191
+ console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
192
+ }
193
+ return true
194
+ }
195
+ }
196
+ }
197
+ }