Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Move assets plugin registration to after app-level plugins #742

Merged
merged 2 commits into from
Mar 21, 2019

Conversation

angus-c
Copy link
Contributor

@angus-c angus-c commented Mar 20, 2019

We want the response to be sent as early as possible so other middlewares can react to ctx.status

@mlmorg
Copy link

mlmorg commented Mar 20, 2019

Can you include a description of the reasoning for this change? Also, can we add a regression test, if this is fixing a bug?

@angus-c angus-c added the bugfix label Mar 20, 2019
reverseRegister(app, ContextPlugin);
app.register(app, AssetsPlugin);
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work™

Copy link
Contributor

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

Copy link
Contributor

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)?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch

@angus-c angus-c force-pushed the move-assets-plugin branch from ab2ea98 to 813fed6 Compare March 20, 2019 20:39
@rtsao
Copy link
Member

rtsao commented Mar 20, 2019

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.)

@ganemone
Copy link
Contributor

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.

@rtsao
Copy link
Member

rtsao commented Mar 20, 2019

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?

@ganemone
Copy link
Contributor

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).

@rtsao
Copy link
Member

rtsao commented Mar 20, 2019

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?

@angus-c
Copy link
Contributor Author

angus-c commented Mar 21, 2019

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 opts.defer is false. As of several months ago its been true, which I think means it is set on the upstream
See: https://github.com/koajs/static/blob/master/index.js

@angus-c angus-c changed the title Register AssetsPlugin after app-level plugins Move assets plugin registration to after app-level plugins Mar 21, 2019
@angus-c
Copy link
Contributor Author

angus-c commented Mar 21, 2019

test added. @rtsao do you still have qualms? See my opts.defer true/false comment above.

@angus-c angus-c force-pushed the move-assets-plugin branch from ef92064 to f138713 Compare March 21, 2019 21:55
@angus-c angus-c merged commit 3e95fde into master Mar 21, 2019
@old-fusion-bot
Copy link

Triggered Fusion.js build verification: https://buildkite.com/uberopensource/fusion-release-verification/builds/1772

@old-fusion-bot old-fusion-bot bot deleted the move-assets-plugin branch March 21, 2019 22:17
This was referenced Apr 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants