File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,11 @@ export default class IncludeFragmentElement extends HTMLElement {
125125 return fetch ( request )
126126 }
127127
128+ refetch ( ) {
129+ privateData . delete ( this )
130+ this . #handleData( )
131+ }
132+
128133 #observer = new IntersectionObserver (
129134 entries => {
130135 for ( const entry of entries ) {
@@ -169,11 +174,17 @@ export default class IncludeFragmentElement extends HTMLElement {
169174 const canceled = ! this . dispatchEvent (
170175 new CustomEvent ( 'include-fragment-replace' , { cancelable : true , detail : { fragment} } )
171176 )
172- if ( canceled ) return
177+ if ( canceled ) {
178+ this . #busy = false
179+ return
180+ }
181+
173182 this . replaceWith ( fragment )
174183 this . dispatchEvent ( new CustomEvent ( 'include-fragment-replaced' ) )
175184 } catch {
176185 this . classList . add ( 'is-error' )
186+ } finally {
187+ this . #busy = false
177188 }
178189 }
179190
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ suite('include-fragment-element', function () {
9797 teardown ( ( ) => {
9898 document . body . innerHTML = ''
9999 } )
100+
100101 test ( 'create from document.createElement' , function ( ) {
101102 const el = document . createElement ( 'include-fragment' )
102103 assert . equal ( 'INCLUDE-FRAGMENT' , el . nodeName )
@@ -141,6 +142,19 @@ suite('include-fragment-element', function () {
141142 )
142143 } )
143144
145+ test ( 'skips cache when using refetch' , async function ( ) {
146+ const el = document . createElement ( 'include-fragment' )
147+ el . src = '/count'
148+
149+ let data = await el . data
150+ assert . equal ( '1' , data )
151+
152+ el . refetch ( )
153+
154+ data = await el . data
155+ assert . equal ( '2' , data )
156+ } )
157+
144158 test ( 'data with src attribute' , function ( ) {
145159 const el = document . createElement ( 'include-fragment' )
146160 el . setAttribute ( 'src' , '/hello' )
You can’t perform that action at this time.
0 commit comments