@@ -2871,46 +2871,52 @@ var htmx = (function() {
28712871 * @param {Element|HTMLInputElement } elt
28722872 */
28732873 function initNode ( elt ) {
2874- if ( eltIsDisabled ( elt ) ) {
2875- cleanUpElement ( elt )
2876- return
2877- }
2878- // Ensure only valid Elements and not shadow DOM roots are inited
2879- if ( ! ( elt instanceof Element ) ) return
2880- const nodeData = getInternalData ( elt )
2881- const attrHash = attributeHash ( elt )
2882- if ( nodeData . initHash !== attrHash ) {
2883- // clean up any previously processed info
2884- deInitNode ( elt )
2885-
2886- nodeData . initHash = attrHash
2874+ triggerEvent ( elt , 'htmx:beforeProcessNode' )
28872875
2888- triggerEvent ( elt , 'htmx:beforeProcessNode' )
2889-
2890- const triggerSpecs = getTriggerSpecs ( elt )
2891- const hasExplicitHttpAction = processVerbs ( elt , nodeData , triggerSpecs )
2876+ const nodeData = getInternalData ( elt )
2877+ const triggerSpecs = getTriggerSpecs ( elt )
2878+ const hasExplicitHttpAction = processVerbs ( elt , nodeData , triggerSpecs )
28922879
2893- if ( ! hasExplicitHttpAction ) {
2894- if ( getClosestAttributeValue ( elt , 'hx-boost' ) === 'true' ) {
2895- boostElement ( elt , nodeData , triggerSpecs )
2896- } else if ( hasAttribute ( elt , 'hx-trigger' ) ) {
2897- triggerSpecs . forEach ( function ( triggerSpec ) {
2898- // For "naked" triggers, don't do anything at all
2899- addTriggerHandler ( elt , triggerSpec , nodeData , function ( ) {
2900- } )
2880+ if ( ! hasExplicitHttpAction ) {
2881+ if ( getClosestAttributeValue ( elt , 'hx-boost' ) === 'true' ) {
2882+ boostElement ( elt , nodeData , triggerSpecs )
2883+ } else if ( hasAttribute ( elt , 'hx-trigger' ) ) {
2884+ triggerSpecs . forEach ( function ( triggerSpec ) {
2885+ // For "naked" triggers, don't do anything at all
2886+ addTriggerHandler ( elt , triggerSpec , nodeData , function ( ) {
29012887 } )
2902- }
2888+ } )
29032889 }
2890+ }
29042891
2905- // Handle submit buttons/inputs that have the form attribute set
2906- // see https://developer.mozilla.org/docs/Web/HTML/Element/button
2907- if ( elt . tagName === 'FORM' || ( getRawAttribute ( elt , 'type' ) === 'submit' && hasAttribute ( elt , 'form' ) ) ) {
2908- initButtonTracking ( elt )
2909- }
2892+ // Handle submit buttons/inputs that have the form attribute set
2893+ // see https://developer.mozilla.org/docs/Web/HTML/Element/button
2894+ if ( elt . tagName === 'FORM' || ( getRawAttribute ( elt , 'type' ) === 'submit' && hasAttribute ( elt , 'form' ) ) ) {
2895+ initButtonTracking ( elt )
2896+ }
2897+
2898+ nodeData . firstInitCompleted = true
2899+ triggerEvent ( elt , 'htmx:afterProcessNode' )
2900+ }
29102901
2911- nodeData . firstInitCompleted = true
2912- triggerEvent ( elt , 'htmx:afterProcessNode' )
2902+ /**
2903+ * @param {Element } elt
2904+ * @returns {boolean }
2905+ */
2906+ function maybeDeInitAndHash ( elt ) {
2907+ // Ensure only valid Elements and not shadow DOM roots are inited
2908+ if ( ! ( elt instanceof Element ) ) {
2909+ return false
29132910 }
2911+
2912+ const nodeData = getInternalData ( elt )
2913+ const hash = attributeHash ( elt )
2914+ if ( nodeData . initHash !== hash ) {
2915+ deInitNode ( elt )
2916+ nodeData . initHash = hash
2917+ return true
2918+ }
2919+ return false
29142920 }
29152921
29162922 /**
@@ -2923,12 +2929,21 @@ var htmx = (function() {
29232929 function processNode ( elt ) {
29242930 elt = resolveTarget ( elt )
29252931 if ( eltIsDisabled ( elt ) ) {
2926- cleanUpElement ( elt )
29272932 return
29282933 }
2929- initNode ( elt )
2930- forEach ( findElementsToProcess ( elt ) , function ( child ) { initNode ( child ) } )
2934+
2935+ const elementsToInit = [ ]
2936+ if ( maybeDeInitAndHash ( elt ) ) {
2937+ elementsToInit . push ( elt )
2938+ }
2939+ forEach ( findElementsToProcess ( elt ) , function ( child ) {
2940+ if ( ! eltIsDisabled ( child ) && maybeDeInitAndHash ( child ) ) {
2941+ elementsToInit . push ( child )
2942+ }
2943+ } )
2944+
29312945 forEach ( findHxOnWildcardElements ( elt ) , processHxOnWildcard )
2946+ forEach ( elementsToInit , initNode )
29322947 }
29332948
29342949 //= ===================================================================
0 commit comments