-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async afterEach hook breaks ready and doneEach hooks #449
Comments
It looks like neither the For example, here is a synchronous plugin using each hook (drop this in your docsify <script>
function pluginSync(hook, vm) {
hook.init(function() {
console.log('init()');
});
hook.mounted(function() {
console.log('mounted()');
});
hook.beforeEach(function(content) {
console.log('beforeEach()');
return content;
});
hook.afterEach(function(html, next) {
console.log('afterEach()');
next(html);
});
hook.doneEach(function() {
console.log('doneEach()');
});
hook.ready(function() {
console.log('ready()');
});
}
$docsify.plugins = [].concat($docsify.plugins, pluginSync);
</script> Here is the output of the synchronous plugin. The order is what one would expect.
Here is the same plugin but with async <script>
function pluginAsync(hook, vm) {
hook.init(function() {
console.log('init()');
});
hook.mounted(function() {
console.log('mounted()');
});
hook.beforeEach(function(content) {
setTimeout(function() {
console.log('beforeEach()');
return content;
}, 2000);
});
hook.afterEach(function(html, next) {
setTimeout(function() {
console.log('afterEach()');
next(html);
}, 1000);
});
hook.doneEach(function() {
console.log('doneEach()');
});
hook.ready(function() {
console.log('ready()');
});
}
$docsify.plugins = [].concat($docsify.plugins, pluginAsync);
</script> This is what I would expect:
But this is the actual result:
Summary: async afterEach() and beforeEach() don't work as they should.
|
@QingWei-Li -- Any chance we can get this marked as a bug and addressed in a future release? This behavior 1) breaks async plugins which 2) increases the likelihood of errors being thrown that break docsify. Thanks! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I would expect the output to be in the same order. Like this:
The only difference is timing (the last four happen later, but in the same order). If we do otherwise, it may break something else. But even if we make doneEach async, that might break something. Maybe we should "fix" it, then just increment the docsify version to |
I was working with the plugin system recently, so I took a some time to review the code and find the issue. Docsify supports asynchronous
The Now, let's change the sync/async
This is clearly not the intended behavior. Docsify correctly waits for all of the
Fortunately, this turned out to be a fairly easy fix once I was able to wrap my head around how the plugin system works. I will create PR shortly with the fix. FWIW, this fix should be considered a bug fix and not a breaking change as it has no effect on how content is process or rendered; it only ensures that
This fix will not break these types of workarounds. |
Async
afterEach
hooks such as:breaking
doneEach
events dependent plugins, such as zoom-image.Demo:
https://docsify-pagination-issue-1-nzhdhlzryc.now.sh/#/
Source of demo:
https://docsify-pagination-issue-1-nzhdhlzryc.now.sh/_src
(Came from imyelo/docsify-pagination#1)
I guess the
next
function in this place should run aftercallback
:https://github.com/QingWei-Li/docsify/blob/e5a263f1bb0909e1629abf76e327f7f2b50340d8/src/core/render/index.js#L149
For the current version, however, if
callback
is an asynchronous function, this assumption will be broken.The text was updated successfully, but these errors were encountered: