Skip to content

Commit

Permalink
alpinejs: Remove the custom memory patch
Browse files Browse the repository at this point in the history
I have seen some rare cleanup errors that points to my patch which I consider worse than the problem the patch was supposed to solve.

Thiw commit brings AlpineJS in line with the tag v3.13.2 with no modifications.
  • Loading branch information
bep committed Nov 16, 2023
1 parent 830d00b commit 6ccb109
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 94 deletions.
16 changes: 4 additions & 12 deletions alpinejs/packages/alpinejs/dist/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,7 @@
enumerable: false
});
});
return {
obj,
cleanup: () => {
el = null;
}
};
return obj;
}

// packages/alpinejs/src/utils/error.js
Expand Down Expand Up @@ -568,8 +563,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
}
function normalEvaluator(el, expression) {
let overriddenMagics = {};
let cleanup2 = injectMagics(overriddenMagics, el).cleanup;
onAttributeRemoved(el, "evaluator", cleanup2);
injectMagics(overriddenMagics, el);
let dataStack = [overriddenMagics, ...closestDataStack(el)];
let evaluator = typeof expression === "function" ? generateEvaluatorFromFunction(dataStack, expression) : generateEvaluatorFromString(dataStack, expression, el);
return tryCatch.bind(null, el, expression, evaluator);
Expand Down Expand Up @@ -2921,22 +2915,20 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return;
expression = expression === "" ? "{}" : expression;
let magicContext = {};
let cleanup1 = injectMagics(magicContext, el).cleanup;
injectMagics(magicContext, el);
let dataProviderContext = {};
injectDataProviders(dataProviderContext, magicContext);
let data2 = evaluate(el, expression, { scope: dataProviderContext });
if (data2 === void 0 || data2 === true)
data2 = {};
let cleanup22 = injectMagics(data2, el).cleanup;
injectMagics(data2, el);
let reactiveData = reactive(data2);
initInterceptors2(reactiveData);
let undo = addScopeToNode(el, reactiveData);
reactiveData["init"] && evaluate(el, reactiveData["init"]);
cleanup2(() => {
reactiveData["destroy"] && evaluate(el, reactiveData["destroy"]);
undo();
cleanup1();
cleanup22();
});
});

Expand Down
4 changes: 2 additions & 2 deletions alpinejs/packages/alpinejs/dist/cdn.min.js

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions alpinejs/packages/alpinejs/dist/module.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,12 +1931,7 @@ function injectMagics(obj, el) {
enumerable: false
});
});
return {
obj,
cleanup: () => {
el = null;
}
};
return obj;
}

// packages/alpinejs/src/utils/error.js
Expand Down Expand Up @@ -1980,8 +1975,7 @@ function setEvaluator(newEvaluator) {
}
function normalEvaluator(el, expression) {
let overriddenMagics = {};
let cleanup = injectMagics(overriddenMagics, el).cleanup;
onAttributeRemoved(el, "evaluator", cleanup);
injectMagics(overriddenMagics, el);
let dataStack = [overriddenMagics, ...closestDataStack(el)];
let evaluator = typeof expression === "function" ? generateEvaluatorFromFunction(dataStack, expression) : generateEvaluatorFromString(dataStack, expression, el);
return tryCatch.bind(null, el, expression, evaluator);
Expand Down Expand Up @@ -3628,22 +3622,20 @@ directive("data", (el, { expression }, { cleanup }) => {
return;
expression = expression === "" ? "{}" : expression;
let magicContext = {};
let cleanup1 = injectMagics(magicContext, el).cleanup;
injectMagics(magicContext, el);
let dataProviderContext = {};
injectDataProviders(dataProviderContext, magicContext);
let data2 = evaluate(el, expression, { scope: dataProviderContext });
if (data2 === void 0 || data2 === true)
data2 = {};
let cleanup2 = injectMagics(data2, el).cleanup;
injectMagics(data2, el);
let reactiveData = reactive(data2);
initInterceptors2(reactiveData);
let undo = addScopeToNode(el, reactiveData);
reactiveData["init"] && evaluate(el, reactiveData["init"]);
cleanup(() => {
reactiveData["destroy"] && evaluate(el, reactiveData["destroy"]);
undo();
cleanup1();
cleanup2();
});
});

Expand Down
16 changes: 4 additions & 12 deletions alpinejs/packages/alpinejs/dist/module.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,7 @@ function injectMagics(obj, el) {
enumerable: false
});
});
return {
obj,
cleanup: () => {
el = null;
}
};
return obj;
}

// packages/alpinejs/src/utils/error.js
Expand Down Expand Up @@ -567,8 +562,7 @@ function setEvaluator(newEvaluator) {
}
function normalEvaluator(el, expression) {
let overriddenMagics = {};
let cleanup2 = injectMagics(overriddenMagics, el).cleanup;
onAttributeRemoved(el, "evaluator", cleanup2);
injectMagics(overriddenMagics, el);
let dataStack = [overriddenMagics, ...closestDataStack(el)];
let evaluator = typeof expression === "function" ? generateEvaluatorFromFunction(dataStack, expression) : generateEvaluatorFromString(dataStack, expression, el);
return tryCatch.bind(null, el, expression, evaluator);
Expand Down Expand Up @@ -2920,22 +2914,20 @@ directive("data", (el, { expression }, { cleanup: cleanup2 }) => {
return;
expression = expression === "" ? "{}" : expression;
let magicContext = {};
let cleanup1 = injectMagics(magicContext, el).cleanup;
injectMagics(magicContext, el);
let dataProviderContext = {};
injectDataProviders(dataProviderContext, magicContext);
let data2 = evaluate(el, expression, { scope: dataProviderContext });
if (data2 === void 0 || data2 === true)
data2 = {};
let cleanup22 = injectMagics(data2, el).cleanup;
injectMagics(data2, el);
let reactiveData = reactive(data2);
initInterceptors2(reactiveData);
let undo = addScopeToNode(el, reactiveData);
reactiveData["init"] && evaluate(el, reactiveData["init"]);
cleanup2(() => {
reactiveData["destroy"] && evaluate(el, reactiveData["destroy"]);
undo();
cleanup1();
cleanup22();
});
});

Expand Down
8 changes: 2 additions & 6 deletions alpinejs/packages/alpinejs/src/directives/x-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ directive('data', ((el, { expression }, { cleanup }) => {
expression = expression === '' ? '{}' : expression

let magicContext = {}
let cleanup1 = injectMagics(magicContext, el).cleanup
injectMagics(magicContext, el)

let dataProviderContext = {}
injectDataProviders(dataProviderContext, magicContext)
Expand All @@ -25,7 +25,7 @@ directive('data', ((el, { expression }, { cleanup }) => {

if (data === undefined || data === true) data = {}

let cleanup2 = injectMagics(data, el).cleanup
injectMagics(data, el)

let reactiveData = reactive(data)

Expand All @@ -39,9 +39,5 @@ directive('data', ((el, { expression }, { cleanup }) => {
reactiveData['destroy'] && evaluate(el, reactiveData['destroy'])

undo()

// MemLeak1: Issue #2140
cleanup1()
cleanup2()
})
}))
6 changes: 1 addition & 5 deletions alpinejs/packages/alpinejs/src/evaluator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { closestDataStack, mergeProxies } from './scope'
import { injectMagics } from './magics'
import { tryCatch, handleError } from './utils/error'
import { onAttributeRemoved } from './mutation'

let shouldAutoEvaluateFunctions = true

Expand Down Expand Up @@ -38,10 +37,7 @@ export function setEvaluator(newEvaluator) {
export function normalEvaluator(el, expression) {
let overriddenMagics = {}

let cleanup = injectMagics(overriddenMagics, el).cleanup

// MemLeak1: Issue #2140 (note: there are other uses of injectMagics)
onAttributeRemoved(el, "evaluator", cleanup)
injectMagics(overriddenMagics, el)

let dataStack = [overriddenMagics, ...closestDataStack(el)]

Expand Down
8 changes: 1 addition & 7 deletions alpinejs/packages/alpinejs/src/magics.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,5 @@ export function injectMagics(obj, el) {
})
})

return {
obj,
cleanup: () => {
// MemLeak1: Issue #2140
el = null;
}
};
return obj
}
16 changes: 4 additions & 12 deletions alpinejs/packages/csp/dist/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,7 @@
enumerable: false
});
});
return {
obj,
cleanup: () => {
el = null;
}
};
return obj;
}

// packages/alpinejs/src/utils/error.js
Expand Down Expand Up @@ -568,8 +563,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
}
function normalEvaluator(el, expression) {
let overriddenMagics = {};
let cleanup2 = injectMagics(overriddenMagics, el).cleanup;
onAttributeRemoved(el, "evaluator", cleanup2);
injectMagics(overriddenMagics, el);
let dataStack = [overriddenMagics, ...closestDataStack(el)];
let evaluator = typeof expression === "function" ? generateEvaluatorFromFunction(dataStack, expression) : generateEvaluatorFromString(dataStack, expression, el);
return tryCatch.bind(null, el, expression, evaluator);
Expand Down Expand Up @@ -2921,22 +2915,20 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return;
expression = expression === "" ? "{}" : expression;
let magicContext = {};
let cleanup1 = injectMagics(magicContext, el).cleanup;
injectMagics(magicContext, el);
let dataProviderContext = {};
injectDataProviders(dataProviderContext, magicContext);
let data2 = evaluate(el, expression, { scope: dataProviderContext });
if (data2 === void 0 || data2 === true)
data2 = {};
let cleanup22 = injectMagics(data2, el).cleanup;
injectMagics(data2, el);
let reactiveData = reactive(data2);
initInterceptors2(reactiveData);
let undo = addScopeToNode(el, reactiveData);
reactiveData["init"] && evaluate(el, reactiveData["init"]);
cleanup2(() => {
reactiveData["destroy"] && evaluate(el, reactiveData["destroy"]);
undo();
cleanup1();
cleanup22();
});
});

Expand Down
Loading

0 comments on commit 6ccb109

Please sign in to comment.