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

feat(ssr): reusing imported imports #14456

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Sep 24, 2023

Description

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

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

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title 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.

@stackblitz
Copy link

stackblitz bot commented Sep 24, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@Dunqing Dunqing marked this pull request as ready for review September 24, 2023 10:00
@@ -125,6 +126,7 @@ async function ssrTransformScript(
// import * as ok from 'foo' --> ok -> __import_foo__
if (node.type === 'ImportDeclaration') {
const importId = defineImport(node.source.value as string)
importIdMap.set(node.source.value as string, importId)
Copy link
Member

Choose a reason for hiding this comment

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

Nice optimization! Should we move this importIdMap cache inside defineImport instead? So that defineImport handles the caching by itself and the consumer doesn't have to check manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, we can do it. But #14441 may break this change

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah I guess it conflicts a bit, but I assume it should be safe to share the cache still for different index? Since the first call would always execute first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just imports need hoisting, but exports do not need to. If this PR merged first. We may need to process all imports first In #14441.

Copy link
Member

Choose a reason for hiding this comment

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

I ran some tests and now I'm confused if this is safe. https://stackblitz.com/edit/node-muh71q?file=index.js

Looks like #14441 affects the execution order of imports too, but it was also wrong before anyways. SSR transform has always been head-banging 😵

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Let's fix it.

@bluwy bluwy added p2-nice-to-have Not breaking anything but nice to have (priority) performance Performance related enhancement feat: ssr labels Sep 25, 2023
bluwy
bluwy previously approved these changes Sep 25, 2023
@bluwy bluwy dismissed their stale review October 5, 2023 08:55

Removing approval for now there's PRs like #14521 that might affect this. Would be better evaluating this again after they are merged.

@bluwy bluwy added the on hold label Oct 5, 2023
@Dunqing
Copy link
Contributor Author

Dunqing commented Oct 19, 2023

#14468 had merged, Can we go forward now?

Comment on lines 135 to +136
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers\\":[\\"createApp\\"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"vue\\", {\\"isExportAll\\":true});
__vite_ssr_exportAll__(__vite_ssr_import_1__);
__vite_ssr_exportAll__(__vite_ssr_import_0__);
Copy link
Member

Choose a reason for hiding this comment

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

This change was what I'm most concern of with my PR before. Besides isExportAll missing here (actually it seems like we don't need the property at all, I'll fix that), this PR would break something like:

import { someApi } from 'lib'
import { anotherApi } from 'lib'

Where the namedImportSpecifiers won't be merged. Even if we solved this by merging implicitly, I'm still a bit concern if we have to add more metadata in the future, plus the execution order is already incorrect and fixing it might be harder after this PR 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, You have a point. This PR looks worthless currently.

Copy link
Member

Choose a reason for hiding this comment

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

Well it's great that we explore this though, so not worthless! But it might only be an optimization for a later time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr on hold p2-nice-to-have Not breaking anything but nice to have (priority) performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants