@@ -2,24 +2,27 @@ import compile from '../../core/compile';
2
2
import { directives } from '../../core/directive' ;
3
3
import render from '../../core/render' ;
4
4
import { COMPONENT_FLAG } from '../../models/generics' ;
5
- import { DirectiveProps } from '../../models/structs' ;
5
+ import { ASTNode , DirectiveProps } from '../../models/structs' ;
6
6
import adjustDeps from '../utils/adjustDeps' ;
7
7
import { getElementCustomProp , setElementCustomProp } from '../utils/elementCustomProp' ;
8
+ import { hasDirectiveRE } from '../utils/patterns' ;
8
9
9
10
export const htmlDirective = ( { el, data, state, node } : DirectiveProps ) : void => {
10
11
node = node ! ;
11
- const marker = getElementCustomProp ( el , COMPONENT_FLAG ) ;
12
+ const marker = getElementCustomProp ( el , COMPONENT_FLAG ) as ASTNode [ ] ;
12
13
const ret = data . compute ( state ) ?? data . value ;
13
14
14
15
if ( ret !== el . innerHTML ) {
15
16
el . innerHTML = ret ;
16
17
17
- const ast = compile ( el , state , true ) ;
18
+ if ( hasDirectiveRE ( ) . test ( ret ) ) {
19
+ const ast = marker ?? compile ( el , state , true ) ;
18
20
19
- if ( ! marker ) adjustDeps ( ast , data . deps , node , 'html' ) ;
21
+ if ( ! marker ) adjustDeps ( ast , data . deps , node , 'html' ) ;
20
22
21
- render ( ast , directives , state , data . deps ) ;
23
+ render ( ast , directives , state , data . deps ) ;
22
24
23
- setElementCustomProp ( el , COMPONENT_FLAG , true ) ;
25
+ setElementCustomProp ( el , COMPONENT_FLAG , ast ) ;
26
+ }
24
27
}
25
28
} ;
0 commit comments