diff --git a/lib/index.js b/lib/index.js index c606747..42fbe58 100644 --- a/lib/index.js +++ b/lib/index.js @@ -207,11 +207,18 @@ export function MarkdownHooks(options) { useEffect( function () { + let cancelled = false const file = createFile(options) processor.run(processor.parse(file), file, function (error, tree) { - setError(error) - setTree(tree) + if (!cancelled) { + setError(error) + setTree(tree) + } }) + + return () => { + cancelled = true + } }, [ options.children, diff --git a/test.jsx b/test.jsx index 8bbf4f7..12b6caa 100644 --- a/test.jsx +++ b/test.jsx @@ -1165,6 +1165,27 @@ test('MarkdownHooks', async function (t) { }) assert.equal(container.innerHTML, 'Error: rejected') }) + + await t.test('should support `MarkdownHooks` rerenders', async function () { + const pluginA = deferPlugin() + const pluginB = deferPlugin() + + const result = render( + + ) + + result.rerender( + + ) + + assert.equal(result.container.innerHTML, '') + pluginB.resolve() + pluginA.resolve() + await waitFor(() => { + assert.notEqual(result.container.innerHTML, '') + }) + assert.equal(result.container.innerHTML, '

b

') + }) }) /**