Skip to content

Resolve paths for views asynchronously #2653

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aredridel
Copy link
Contributor

This eliminates the only post-startup synchronous I/O in Express.

In addition, this makes the view.lookup method non-private, intended to be used
by view engines to resolve paths to partials, and, if the View class is
extended, could be used for other resources such as internationalized messages.

@dougwilson
Copy link
Contributor

Nice! Anyway we can add to this a way to prevent stampeding (which the sync version protected from) to the default lookup implementation?

@aredridel
Copy link
Contributor Author

Oh, yes! I think I could work that in.

@aredridel
Copy link
Contributor Author

Updated.

@aredridel aredridel force-pushed the async-view-resolve branch 4 times, most recently from a048a24 to 4de612f Compare May 19, 2015 21:28
@dougwilson dougwilson self-assigned this May 20, 2015
@dougwilson dougwilson force-pushed the master branch 2 times, most recently from 5f268a4 to 9848645 Compare July 31, 2015 20:58
@gabrielcsapo
Copy link

👍

@bjohansebas
Copy link
Member

Hey, @aredridel could you rebase this PR, please?

@bjohansebas bjohansebas removed the pr label Mar 27, 2025
@aredridel
Copy link
Contributor Author

Will do later today hopefully

@wesleytodd
Copy link
Member

It is just lovely when a 10 year old PR with value is revived! This might not make it into the 5.1.0 release, but we will be sure to review and merge it ASAP after. Thank you for being patient and then responsive after so long!

@aredridel aredridel force-pushed the async-view-resolve branch from 4de612f to 747869f Compare March 28, 2025 00:38
@aredridel
Copy link
Contributor Author

Isn't it just? I get so mad when projects close things after 30 or 180 days as stale. Sometimes we should take our time!

Anyway, rebased. I did not keep the view options being passed to the lookup function. That's a little useful, I guess, but not really needed.

@aredridel aredridel force-pushed the async-view-resolve branch from 747869f to ffeab94 Compare March 28, 2025 00:44
@wesleytodd
Copy link
Member

wesleytodd commented Mar 28, 2025

I just merged the last required change we needed to land before cutting the 5.1.0 release branch. If this is ready now I can review it and see if landing it for the release is an option.

@wesleytodd
Copy link
Member

The fact that we have no direct coverage for the View class makes me concerned. The changes here, if made to a public api, would be breaking. The only ways this is exposed to consumers is via the view setting, which is not documented, or via a deep import to lib/view.js. In theory someone could do:

const View = app.get('view');
const view = new View();
const path = view.lookup('name');

And this would break with this change. In some past cases we have been careful enough to avoid even this internal concealed breakage. That said, I am actually a fan of us moving a bit toward keeping our internals safe and then breaking them more often. That is one of the only ways to really prevent folks from coupling to them. So with that in mind I personally would love to land this for the 5.1.0 release but will need to get more consensus before we do. This might mean it doesn't make the timeline, but 🤷 what's another 10 years?

Either way, pinging in @expressjs/express-tc just in case anyone has an immediate and strong opinion.

Copy link
Member

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

LGTM!

@bjohansebas
Copy link
Member

bjohansebas commented Mar 28, 2025

The only ways this is exposed to consumers is via the view setting, which is not documented,

I don't have a strong opinion on this, I'd rather not say anything.

via a deep import to lib/view.js

If someone is doing this, they really should stop. The location of that file could be deleted or moved, which would affect their application, and I don’t think we should worry about that.

By the way, we should start testing the views whenever possible.

@dpopp07
Copy link
Contributor

dpopp07 commented Mar 28, 2025

That said, I am actually a fan of us moving a bit toward keeping our internals safe and then breaking them more often. That is one of the only ways to really prevent folks from coupling to them. So with that in mind I personally would love to land this for the 5.1.0 release

Agreed. This would focus compatibility with the contract, which I think is good. Users can always figure out creative ways to use the library in ways it wasn't intended to be used (like deep imports) 🙂 but I'm fine with breaking those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants