thepassle / app-tools

129 stars 8 forks source link

Lazy doesn't return promise #11

Closed JudahGabriel closed 1 year ago

JudahGabriel commented 1 year ago

I believe I've found a bug in the lazy plugin:

https://github.com/thepassle/app-tools/blob/53784beeae2ab311f6355280fe5c0a93de138d1c/router/plugins/lazy.js#L9-L11

This function doesn't return the result of fn. This is important, as the result can be a promise, which is awaited later in the router code:

https://github.com/thepassle/app-tools/blob/53784beeae2ab311f6355280fe5c0a93de138d1c/router/index.js#L175-L178

The simple fix would be to return the result inside lazy:

beforeNavigation: {
   return fn();
}

Would you accept a PR for this?

thepassle commented 1 year ago

This was intentional, imports can potentially be large and take a while to load, so in the meantime we can already complete the navigation and update the browser url bar etc while the promise resolves. Is this leading to anything specific for your use case?

JudahGabriel commented 1 year ago

Ah, by design then. My code was assuming it would await the promise and I discovered it wasn't doing that.

The issue is my code then, I was operating under a false assumption. I'll just create a new plugin for my project that awaits the result. Thanks!