File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -207,11 +207,18 @@ export function MarkdownHooks(options) {
207
207
208
208
useEffect (
209
209
function ( ) {
210
+ let cancelled = false
210
211
const file = createFile ( options )
211
212
processor . run ( processor . parse ( file ) , file , function ( error , tree ) {
212
- setError ( error )
213
- setTree ( tree )
213
+ if ( ! cancelled ) {
214
+ setError ( error )
215
+ setTree ( tree )
216
+ }
214
217
} )
218
+
219
+ return ( ) => {
220
+ cancelled = true
221
+ }
215
222
} ,
216
223
[
217
224
options . children ,
Original file line number Diff line number Diff line change @@ -1165,6 +1165,27 @@ test('MarkdownHooks', async function (t) {
1165
1165
} )
1166
1166
assert . equal ( container . innerHTML , 'Error: rejected' )
1167
1167
} )
1168
+
1169
+ await t . test ( 'should support `MarkdownHooks` rerenders' , async function ( ) {
1170
+ const pluginA = deferPlugin ( )
1171
+ const pluginB = deferPlugin ( )
1172
+
1173
+ const result = render (
1174
+ < MarkdownHooks children = { 'a' } rehypePlugins = { [ pluginA . plugin ] } />
1175
+ )
1176
+
1177
+ result . rerender (
1178
+ < MarkdownHooks children = { 'b' } rehypePlugins = { [ pluginB . plugin ] } />
1179
+ )
1180
+
1181
+ assert . equal ( result . container . innerHTML , '' )
1182
+ pluginB . resolve ( )
1183
+ pluginA . resolve ( )
1184
+ await waitFor ( ( ) => {
1185
+ assert . notEqual ( result . container . innerHTML , '' )
1186
+ } )
1187
+ assert . equal ( result . container . innerHTML , '<p>b</p>' )
1188
+ } )
1168
1189
} )
1169
1190
1170
1191
/**
You can’t perform that action at this time.
0 commit comments