File tree 2 files changed +26
-1
lines changed
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 {
125
125
return fetch ( request )
126
126
}
127
127
128
+ refetch ( ) {
129
+ privateData . delete ( this )
130
+ this . #handleData( )
131
+ }
132
+
128
133
#observer = new IntersectionObserver (
129
134
entries => {
130
135
for ( const entry of entries ) {
@@ -169,11 +174,17 @@ export default class IncludeFragmentElement extends HTMLElement {
169
174
const canceled = ! this . dispatchEvent (
170
175
new CustomEvent ( 'include-fragment-replace' , { cancelable : true , detail : { fragment} } )
171
176
)
172
- if ( canceled ) return
177
+ if ( canceled ) {
178
+ this . #busy = false
179
+ return
180
+ }
181
+
173
182
this . replaceWith ( fragment )
174
183
this . dispatchEvent ( new CustomEvent ( 'include-fragment-replaced' ) )
175
184
} catch {
176
185
this . classList . add ( 'is-error' )
186
+ } finally {
187
+ this . #busy = false
177
188
}
178
189
}
179
190
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ suite('include-fragment-element', function () {
97
97
teardown ( ( ) => {
98
98
document . body . innerHTML = ''
99
99
} )
100
+
100
101
test ( 'create from document.createElement' , function ( ) {
101
102
const el = document . createElement ( 'include-fragment' )
102
103
assert . equal ( 'INCLUDE-FRAGMENT' , el . nodeName )
@@ -141,6 +142,19 @@ suite('include-fragment-element', function () {
141
142
)
142
143
} )
143
144
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
+
144
158
test ( 'data with src attribute' , function ( ) {
145
159
const el = document . createElement ( 'include-fragment' )
146
160
el . setAttribute ( 'src' , '/hello' )
You can’t perform that action at this time.
0 commit comments