@domql/element 2.5.120 → 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
@@ -214,8 +214,7 @@ const addElementIntoParentChildren = (element, parent) => {
214
214
  const visitedElements = new WeakMap()
215
215
  const renderElement = (element, parent, options, attachOptions) => {
216
216
  if (visitedElements.has(element)) {
217
- console.warn('Cyclic rendering detected:', element)
218
- return
217
+ if (ENV === 'test' || ENV === 'development') console.warn('Cyclic rendering detected:', element.__ref.__path)
219
218
  }
220
219
 
221
220
  visitedElements.set(element, true)
@@ -224,8 +223,8 @@ const renderElement = (element, parent, options, attachOptions) => {
224
223
 
225
224
  // CREATE a real NODE
226
225
  try {
227
- const isInfiniteLoop = detectInfiniteLoop(ref.__path)
228
- if (ref.__uniqId || isInfiniteLoop) return
226
+ const isInfiniteLoopDetected = detectInfiniteLoop(ref.__path)
227
+ if (ref.__uniqId || isInfiniteLoopDetected) return
229
228
  createNode(element, options)
230
229
  ref.__uniqId = Math.random()
231
230
  } catch (e) {
@@ -170,14 +170,14 @@ const addElementIntoParentChildren = (element, parent) => {
170
170
  const visitedElements = /* @__PURE__ */ new WeakMap();
171
171
  const renderElement = (element, parent, options, attachOptions) => {
172
172
  if (visitedElements.has(element)) {
173
- console.warn("Cyclic rendering detected:", element);
174
- return;
173
+ if (ENV === "test" || ENV === "development")
174
+ console.warn("Cyclic rendering detected:", element.__ref.__path);
175
175
  }
176
176
  visitedElements.set(element, true);
177
177
  const { __ref: ref, key } = element;
178
178
  try {
179
- const isInfiniteLoop = (0, import_component.detectInfiniteLoop)(ref.__path);
180
- if (ref.__uniqId || isInfiniteLoop)
179
+ const isInfiniteLoopDetected = (0, import_component.detectInfiniteLoop)(ref.__path);
180
+ if (ref.__uniqId || isInfiniteLoopDetected)
181
181
  return;
182
182
  (0, import_node.default)(element, options);
183
183
  ref.__uniqId = Math.random();
@@ -175,22 +175,24 @@ const applyVariant = (element) => {
175
175
  });
176
176
  return element;
177
177
  };
178
- const detectInfiniteLoop = (actions) => {
178
+ const detectInfiniteLoop = (arr) => {
179
179
  const maxRepeats = 10;
180
180
  let pattern = [];
181
181
  let repeatCount = 0;
182
- for (let i = 0; i < actions.length; i++) {
182
+ for (let i = 0; i < arr.length; i++) {
183
183
  if (pattern.length < 2) {
184
- pattern.push(actions[i]);
184
+ pattern.push(arr[i]);
185
185
  } else {
186
- if (actions[i] === pattern[i % 2]) {
186
+ if (arr[i] === pattern[i % 2]) {
187
187
  repeatCount++;
188
188
  } else {
189
- pattern = [actions[i]];
190
- repeatCount = 0;
189
+ pattern = [arr[i - 1], arr[i]];
190
+ repeatCount = 1;
191
191
  }
192
- if (repeatCount > maxRepeats * 2) {
193
- console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
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
+ }
194
196
  return true;
195
197
  }
196
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.120",
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": "ca99941529086268c7c106229ef1873faf5ac54c",
34
+ "gitHead": "5130bdaa1358d22df75746616dd3387b8a56b55b",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
@@ -166,28 +166,30 @@ export const applyVariant = (element) => {
166
166
  return element
167
167
  }
168
168
 
169
- export const detectInfiniteLoop = (actions) => {
169
+ export const detectInfiniteLoop = arr => {
170
170
  const maxRepeats = 10 // Maximum allowed repetitions
171
171
  let pattern = []
172
172
  let repeatCount = 0
173
173
 
174
- for (let i = 0; i < actions.length; i++) {
174
+ for (let i = 0; i < arr.length; i++) {
175
175
  if (pattern.length < 2) {
176
176
  // Build the initial pattern with two consecutive elements
177
- pattern.push(actions[i])
177
+ pattern.push(arr[i])
178
178
  } else {
179
179
  // Check if the current element follows the repeating pattern
180
- if (actions[i] === pattern[i % 2]) {
180
+ if (arr[i] === pattern[i % 2]) {
181
181
  repeatCount++
182
182
  } else {
183
183
  // If there's a mismatch, reset the pattern and repeat counter
184
- pattern = [actions[i]]
185
- repeatCount = 0
184
+ pattern = [arr[i - 1], arr[i]]
185
+ repeatCount = 1 // Reset to 1 because we start a new potential pattern
186
186
  }
187
187
 
188
- // If the pattern has repeated more than `maxRepeats` times, throw a warning
189
- if (repeatCount > maxRepeats * 2) { // *2 because it increments for both "Hgroup" and "content"
190
- console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
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
+ }
191
193
  return true
192
194
  }
193
195
  }