-
Notifications
You must be signed in to change notification settings - Fork 37
Move assets plugin registration to after app-level plugins #742
Conversation
Can you include a description of the reasoning for this change? Also, can we add a regression test, if this is fixing a bug? |
entries/server-entry.js
Outdated
reverseRegister(app, ContextPlugin); | ||
app.register(app, AssetsPlugin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration order doesn't affect order in which plugins run. If you want to add the AssetsPlugin last, you need to modify the underlying array like reverseRegister does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration order absolutely does determine the order in which plugins are run. This code is correct as far as I can tell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it going to get shuffled with the other ones once the depedency graph is resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work™
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any two apps that don't depend on one another will be ordered respectively based on registration order. So this is what we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sounds good. On a separate note, should it be app.register(AssetsPlugin)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yea it should be. This might be working technically because fusion would be treating app
as a token lol. However I'm surprised this passes flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good catch
ab2ea98
to
813fed6
Compare
I'm a bit confused by this, I think the asset plugin should go before any user/app plugins. The disk asset serving should succeed/fail early on the downstream so that any user plugins can respond appropriately based on this (e.g S3 fallback, custom headers, etc.) |
The reason we don't register this first is so the user can have middleware that run before. This allows the user to compose with the assets middleware to do things like add headers. |
The asset plugin doesn't await next? |
It does, and that is exactly why it needs to be registered last. Otherwise it will be the last thing to run, and we wont be able to have fallback mechanisms (such as s3). |
The asset plugin should set the response body on the downstream though, right? |
Only if |
test added. @rtsao do you still have qualms? See my |
ef92064
to
f138713
Compare
Triggered Fusion.js build verification: https://buildkite.com/uberopensource/fusion-release-verification/builds/1772 |
We want the response to be sent as early as possible so other middlewares can react to
ctx.status