diff --git a/packages/alpinejs/src/directives/x-data.js b/packages/alpinejs/src/directives/x-data.js index ebaec0da4..e2b69f2c2 100644 --- a/packages/alpinejs/src/directives/x-data.js +++ b/packages/alpinejs/src/directives/x-data.js @@ -34,8 +34,8 @@ directive('data', skipDuringClone((el, { expression }, { cleanup }) => { reactiveData['init'] && evaluate(el, reactiveData['init']) cleanup(() => { - undo() - reactiveData['destroy'] && evaluate(el, reactiveData['destroy']) + + undo() }) })) diff --git a/tests/cypress/integration/custom-data.spec.js b/tests/cypress/integration/custom-data.spec.js index 424fbe809..53ae04da2 100644 --- a/tests/cypress/integration/custom-data.spec.js +++ b/tests/cypress/integration/custom-data.spec.js @@ -159,10 +159,38 @@ test('destroy functions inside custom datas are called automatically',
- + `, ({ get }) => { get('button').click() get('span').should(haveText('foo')) } ) + +test('destroy have access to the current scope', + html` + + +
+ +
+ baz + `, + ({ get }) => { + get('span').should(haveText('baz')) + get('button').click() + get('span').should(haveText('bar')) + } +)