File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,13 @@ async function handleData(el: IncludeFragmentElement) {
10
10
// eslint-disable-next-line github/no-then
11
11
return getData ( el ) . then (
12
12
function ( html : string ) {
13
- const parentNode = el . parentNode
14
- if ( parentNode ) {
15
- el . insertAdjacentHTML ( 'afterend' , html )
16
- parentNode . removeChild ( el )
17
- }
13
+ const template = document . createElement ( 'template' )
14
+ template . innerHTML = html
15
+ const fragment = document . importNode ( template . content , true )
16
+ const canceled = ! el . dispatchEvent ( new CustomEvent ( 'include-fragment-replace' , { cancelable : true , detail : { fragment} } ) )
17
+ if ( canceled ) return
18
+ el . replaceWith ( fragment )
19
+ el . dispatchEvent ( new CustomEvent ( 'include-fragment-replaced' ) )
18
20
} ,
19
21
function ( ) {
20
22
el . classList . add ( 'is-error' )
You can’t perform that action at this time.
0 commit comments