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(ssr): avoid transforming json file in ssrTransform #6597

Merged
merged 15 commits into from May 10, 2022

Conversation

poyoho
Copy link
Member

@poyoho poyoho commented Jan 22, 2022

Description

fix: #6154

Additional context

  • `filter json file transform in ssrTransform.
  • need to filter json tree shaking in runtime phase?

In the transform phase of the plugin, dataToEsm is called for tree shaking, but I think that in the runtime phase, there should be no need to shake the json tree, and it may directly return a string. I am not sure whether this point needs to be changed.

feat json ignore named export option in ssr.


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

@poyoho poyoho marked this pull request as draft January 22, 2022 15:32
@Niputi Niputi added feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority) labels Jan 22, 2022
@poyoho poyoho marked this pull request as ready for review January 22, 2022 15:36
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

In the transform phase of the plugin, dataToEsm is called for tree shaking, but I think that in the runtime phase, there should be no need to shake the json tree, and it may directly return a string. I am not sure whether this point needs to be changed.

Good point. I think in dev it's fine to not treeshake as bundle size is not a concern, plus the issues showed that Node parses it fairly faster as well. In build we can treeshake the JSON (which I believe is handled separately).

Also, the PR title ssrTransfrom -> ssrTransform 😬

packages/vite/src/node/ssr/ssrTransform.ts Outdated Show resolved Hide resolved
@poyoho poyoho changed the title fix(ssr): ssrTransfrom unneed transform json file fix(ssr): ssrTransform unneed transform json file Jan 23, 2022
@poyoho
Copy link
Member Author

poyoho commented Jan 24, 2022

@bluwy I found out why I need to call datatoesm. Not only for tree sharking, but also for named exports I think we can only optimize the situation where named exports is not required. 😂

@poyoho poyoho requested a review from bluwy January 25, 2022 01:40
bluwy
bluwy previously approved these changes Jan 25, 2022
bluwy
bluwy previously approved these changes Feb 6, 2022
@poyoho poyoho requested a review from ygj6 February 8, 2022 04:19
ygj6
ygj6 previously approved these changes Feb 10, 2022
@bluwy
Copy link
Member

bluwy commented Apr 1, 2022

I think we missed out on merging this. It looks good to me, but the PR now needs a rebase.

@poyoho poyoho dismissed stale reviews from ygj6 and bluwy via 7aad7bc April 2, 2022 00:53
@poyoho
Copy link
Member Author

poyoho commented Apr 2, 2022

done. the unit test meeting a common mistake.

bluwy
bluwy previously approved these changes Apr 2, 2022
@patak-dev patak-dev changed the title fix(ssr): ssrTransform unneed transform json file fix(ssr): avoid transforming json file in ssrTransform May 10, 2022
@patak-dev patak-dev merged commit a709440 into vitejs:main May 10, 2022
@poyoho poyoho deleted the fix(ssr)/slow-file branch May 10, 2022 13:38
@fi3ework fi3ework mentioned this pull request May 4, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow JSON imports in SSR dev mode
6 participants