From 61bef0dcf151202c0fa3553465dd86cfb991046c Mon Sep 17 00:00:00 2001 From: Byron Anderson Date: Fri, 21 Apr 2023 12:55:10 -0600 Subject: [PATCH 01/11] Attempt memory leak fix from using magics (#2832) * Attempt memory leak fix from using magics * another potential fix for memory leak with magics maybe safer for some types of consumption --------- Co-authored-by: Byron Anderson --- packages/alpinejs/src/magics.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/alpinejs/src/magics.js b/packages/alpinejs/src/magics.js index 9a11c1374..da41a7ad9 100644 --- a/packages/alpinejs/src/magics.js +++ b/packages/alpinejs/src/magics.js @@ -11,17 +11,24 @@ export function magic(name, callback) { export function injectMagics(obj, el) { Object.entries(magics).forEach(([name, callback]) => { - Object.defineProperty(obj, `$${name}`, { - get() { + let memoizedUtilities = null; + function getUtilities() { + if (memoizedUtilities) { + return memoizedUtilities; + } else { let [utilities, cleanup] = getElementBoundUtilities(el) - utilities = {interceptor, ...utilities} + memoizedUtilities = {interceptor, ...utilities} onElRemoved(el, cleanup) - - return callback(el, utilities) + return memoizedUtilities; + } + } + + Object.defineProperty(obj, `$${name}`, { + get() { + return callback(el, getUtilities()); }, - enumerable: false, }) }) From 5b88c86e9e8f6a46dad9ab63efb531b4fead7edb Mon Sep 17 00:00:00 2001 From: cemrehancavdar <50503448+cemrehancavdar@users.noreply.github.com> Date: Wed, 10 May 2023 16:22:49 +0300 Subject: [PATCH 02/11] fix: typo on alt "component" (#3541) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4eba19018..8af2480c0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Stay here for contribution-related information. > Looking for V2 docs? [here they are](https://github.com/alpinejs/alpine/tree/v2.8.2) -

Alpine Compoenent Patterns

+

Alpine Component Patterns

## Contribution Guide: From 8d2339822314fd29c0085ae00cbdede4fa1c2590 Mon Sep 17 00:00:00 2001 From: Eric Kwoka <43540491+ekwoka@users.noreply.github.com> Date: Wed, 10 May 2023 17:23:35 +0400 Subject: [PATCH 03/11] :white_check_mark: Fixes duplicate/inaccurate test (#3520) --- tests/cypress/integration/directives/x-bind.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cypress/integration/directives/x-bind.spec.js b/tests/cypress/integration/directives/x-bind.spec.js index a722b75cf..7b95c3ad9 100644 --- a/tests/cypress/integration/directives/x-bind.spec.js +++ b/tests/cypress/integration/directives/x-bind.spec.js @@ -391,8 +391,8 @@ test('x-bind object syntax event handlers defined as functions receive the event +
+ + thing +
+ `, + ({ get }) => + { + get('span').should(beVisible()) + get('span').should(beVisible()) + } + +); \ No newline at end of file From 3a75b62dd1438f6b14c33ecd345ec261cbae9590 Mon Sep 17 00:00:00 2001 From: Caleb Porzio Date: Wed, 10 May 2023 10:42:01 -0400 Subject: [PATCH 07/11] Add warning to prevent Alpine from being loaded twice on the same page (#3565) --- packages/alpinejs/src/lifecycle.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/alpinejs/src/lifecycle.js b/packages/alpinejs/src/lifecycle.js index 7a6f93551..6a62a61ab 100644 --- a/packages/alpinejs/src/lifecycle.js +++ b/packages/alpinejs/src/lifecycle.js @@ -4,7 +4,13 @@ import { dispatch } from './utils/dispatch' import { walk } from "./utils/walk" import { warn } from './utils/warn' +let started = false + export function start() { + if (started) warn('Alpine has already been initialized on this page. Calling Alpine.start() more than once can cause problems.') + + started = true + if (! document.body) warn('Unable to initialize. Trying to load Alpine before `` is available. Did you forget to add `defer` in Alpine\'s `