@domql/element 2.5.118 → 2.5.120
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 +12 -2
- package/dist/cjs/create.js +10 -0
- package/dist/cjs/node.js +3 -1
- package/dist/cjs/utils/component.js +22 -0
- package/node.js +3 -1
- package/package.json +2 -2
- package/props/create.js +0 -4
- package/update.js +0 -1
- package/utils/component.js +28 -0
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,23 @@ 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
|
+
console.warn('Cyclic rendering detected:', element)
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
visitedElements.set(element, true)
|
|
222
|
+
|
|
216
223
|
const { __ref: ref, key } = element
|
|
217
224
|
|
|
218
225
|
// CREATE a real NODE
|
|
219
226
|
try {
|
|
227
|
+
const isInfiniteLoop = detectInfiniteLoop(ref.__path)
|
|
228
|
+
if (ref.__uniqId || isInfiniteLoop) return
|
|
220
229
|
createNode(element, options)
|
|
230
|
+
ref.__uniqId = Math.random()
|
|
221
231
|
} catch (e) {
|
|
222
232
|
if (ENV === 'test' || ENV === 'development') console.warn(element, e)
|
|
223
233
|
}
|
package/dist/cjs/create.js
CHANGED
|
@@ -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
|
+
console.warn("Cyclic rendering detected:", element);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
visitedElements.set(element, true);
|
|
171
177
|
const { __ref: ref, key } = element;
|
|
172
178
|
try {
|
|
179
|
+
const isInfiniteLoop = (0, import_component.detectInfiniteLoop)(ref.__path);
|
|
180
|
+
if (ref.__uniqId || isInfiniteLoop)
|
|
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 = () =>
|
|
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,24 @@ const applyVariant = (element) => {
|
|
|
174
175
|
});
|
|
175
176
|
return element;
|
|
176
177
|
};
|
|
178
|
+
const detectInfiniteLoop = (actions) => {
|
|
179
|
+
const maxRepeats = 10;
|
|
180
|
+
let pattern = [];
|
|
181
|
+
let repeatCount = 0;
|
|
182
|
+
for (let i = 0; i < actions.length; i++) {
|
|
183
|
+
if (pattern.length < 2) {
|
|
184
|
+
pattern.push(actions[i]);
|
|
185
|
+
} else {
|
|
186
|
+
if (actions[i] === pattern[i % 2]) {
|
|
187
|
+
repeatCount++;
|
|
188
|
+
} else {
|
|
189
|
+
pattern = [actions[i]];
|
|
190
|
+
repeatCount = 0;
|
|
191
|
+
}
|
|
192
|
+
if (repeatCount > maxRepeats * 2) {
|
|
193
|
+
console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
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 = () =>
|
|
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.
|
|
3
|
+
"version": "2.5.120",
|
|
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": "
|
|
34
|
+
"gitHead": "ca99941529086268c7c106229ef1873faf5ac54c",
|
|
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) {
|
package/utils/component.js
CHANGED
|
@@ -165,3 +165,31 @@ export const applyVariant = (element) => {
|
|
|
165
165
|
|
|
166
166
|
return element
|
|
167
167
|
}
|
|
168
|
+
|
|
169
|
+
export const detectInfiniteLoop = (actions) => {
|
|
170
|
+
const maxRepeats = 10 // Maximum allowed repetitions
|
|
171
|
+
let pattern = []
|
|
172
|
+
let repeatCount = 0
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < actions.length; i++) {
|
|
175
|
+
if (pattern.length < 2) {
|
|
176
|
+
// Build the initial pattern with two consecutive elements
|
|
177
|
+
pattern.push(actions[i])
|
|
178
|
+
} else {
|
|
179
|
+
// Check if the current element follows the repeating pattern
|
|
180
|
+
if (actions[i] === pattern[i % 2]) {
|
|
181
|
+
repeatCount++
|
|
182
|
+
} else {
|
|
183
|
+
// If there's a mismatch, reset the pattern and repeat counter
|
|
184
|
+
pattern = [actions[i]]
|
|
185
|
+
repeatCount = 0
|
|
186
|
+
}
|
|
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)
|
|
191
|
+
return true
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|