Skip to content
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

fix: update SSR externals only when SSR is enabled (fix #6478) #6492

Merged

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Jan 13, 2022

Description

Fixes #6478

What is the purpose of this pull request?

  • Bug fix

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@vursen
Copy link
Contributor Author

vursen commented Jan 13, 2022

Correct me if I'm wrong, but there seems to be a complete absence of tests that would make sure SSR externals get updated in the case when Vite optimizes deps after a missing one has been discovered (see node/optimizer/registerMissing.ts). The related logic has not been tested since its introduction in 92934d4.

I don't have enough time right now to add them from scratch, maybe someone could help me? Or could we consider merging this PR without tests since the fix is rather trivial?

@vursen vursen changed the title fix: update SSR externals only when SSR is enabled fix: update SSR externals only when SSR is enabled (fixes #6478) Jan 13, 2022
@vursen vursen changed the title fix: update SSR externals only when SSR is enabled (fixes #6478) fix: update SSR externals only when SSR is enabled (fix #6478) Jan 13, 2022
@Shinigami92 Shinigami92 added feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority) labels Jan 13, 2022
bluwy
bluwy previously approved these changes Jan 14, 2022
@vursen
Copy link
Contributor Author

vursen commented Jan 24, 2022

Hey, are there any updates about this PR? Could it be merged?

server.config,
Object.keys(knownOptimized)
)
if (server.config.ssr) {
Copy link
Member

Choose a reason for hiding this comment

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

The ssr param in rerun is what indicates if the server is running in ssr mode. @bluwy could you confirm this, I see that you approved this one

Suggested change
if (server.config.ssr) {
if (ssr) {

Copy link
Contributor Author

@vursen vursen Jan 25, 2022

Choose a reason for hiding this comment

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

Actually, I'm not sure if they are entirely interchangeable and will work exactly the same way. As far as I get this, tryNodeResolve is the only invoker of registerMissing. An important detail about tryNodeResolve is that this function is not always called with ssr === true even when SSR is enabled. See how ssrModuleLoader calls tryNodeResolve as an example:

const resolved = tryNodeResolve(id, importer, options, false)

I don't know 100% how it is intended to work since there are no tests so I just tried to be as close to the original implementation as possible.

Maybe it will be indeed sufficient to call resolveSSRExternal only depending on the ssr param. I would just like to get an additional confirmation before updating this place.

Copy link
Member

Choose a reason for hiding this comment

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

@aleclarson could you help us checking this one?

Copy link
Member

Choose a reason for hiding this comment

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

My bad. I think you're right @patak-dev, that slipped off my mind. @vursen regarding your concern, that seems like it should be a true instead, I'm not sure why it's false since it's used by hookNodeResolve. But yes, we do lack tests for this case, and @aleclarson may know more about it.

Copy link
Member

Choose a reason for hiding this comment

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

The ssr argument is actually undefined in the call above, not false. The false value is for the targetWeb argument. :)

I think we can use ssr instead of server.config.ssr (as suggested by @patak-dev), since the tryNodeResolve call will be removed in #6591.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, updated this line. Please, take a look.

@patak-dev patak-dev merged commit 28d1e7e into vitejs:main Jan 26, 2022
@vursen vursen deleted the fix/dont-resove-ssr-externals-when-disabled branch January 26, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should not update missing SSR external dependencies when SSR is not enabled
5 participants