Skip to content

Commit

Permalink
Tweak x-data to sometimes run while cloning a tree
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jul 28, 2023
1 parent 1396c74 commit 7043509
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/alpinejs/src/directives/x-data.js
Expand Up @@ -2,15 +2,21 @@ import { directive, prefix } from '../directives'
import { initInterceptors } from '../interceptor'
import { injectDataProviders } from '../datas'
import { addRootSelector } from '../lifecycle'
import { skipDuringClone } from '../clone'
import { isCloning } from '../clone'
import { addScopeToNode } from '../scope'
import { injectMagics, magic } from '../magics'
import { reactive } from '../reactivity'
import { evaluate } from '../evaluator'

addRootSelector(() => `[${prefix('data')}]`)

directive('data', skipDuringClone((el, { expression }, { cleanup }) => {
directive('data', ((el, { expression }, { cleanup }) => {
// If we are cloning a tree, we only want to evaluate x-data if another
// x-data context DOESN'T exist on the component.
// The reason a data context WOULD exist is that we graft root x-data state over
// from the live tree before hydrating the clone tree.
if (isCloning && el._x_dataStack) return;

expression = expression === '' ? '{}' : expression

let magicContext = {}
Expand Down

0 comments on commit 7043509

Please sign in to comment.