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

refactor(remix-dev/vite): remove redundant jsx and typescript babel plugins #7998

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Nov 14, 2023

While investigating mdx hmr in #7954, I noticed that "remix-react-refresh-babel" plugin's transform is receiving already transpiled plain js file, so I think we don't need to add plugins: ["jsx", "typescript"] for bebel transform.

One thing to note is that this is a different from @vitejs/plugin-react, which uses enforce: "pre". In their case, they are intercepting before vite's internal transform, so jsx/typescript handling is required:
https://github.com/vitejs/vite-plugin-react/blob/0cd00a5bf59fe1b326c667efb9c340732c6b0630/packages/plugin-react/src/index.ts#L119-L120

Assuming this first idea is valid, I think remix can then remove remix-react-refresh-babel plugin from child vite compiler since the purpose of child compiler is currently only for extracting exports of route file by getRouteModuleExports and injecting HMR-related code is not necessary as long as code is transformed to plain js.
This could help perf by reducing unnecessary babel transform (though it might not be a significant gain).

Testing Strategy

I think existing tests should be enough to verify the correctness of this idea.

Copy link

changeset-bot bot commented Nov 14, 2023

⚠️ No Changeset found

Latest commit: f4f1b06

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hi-ogawa hi-ogawa changed the title refactor(remix-dev/vite): remove redundant "jsx" and "typescript" babel plugins refactor(remix-dev/vite): remove redundant "jsx" and "typescript" babel plugins + remove "remix-react-refresh-babel" plugin from child compiler Nov 14, 2023
@hi-ogawa hi-ogawa changed the title refactor(remix-dev/vite): remove redundant "jsx" and "typescript" babel plugins + remove "remix-react-refresh-babel" plugin from child compiler refactor(remix-dev/vite): remove redundant jsx and typescript babel plugins + remove remix-react-refresh-babel plugin from child vite compiler Nov 14, 2023
@hi-ogawa hi-ogawa marked this pull request as ready for review November 14, 2023 03:42
@pcattori pcattori self-assigned this Nov 14, 2023
@@ -928,7 +929,6 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
parserOpts: {
sourceType: "module",
allowAwaitOutsideFunction: true,
plugins: ["jsx", "typescript"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we still want this change. Can we reopen this PR and scope it down to just this one liner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for re-opening! I updated a PR to include only this change.

Btw, recently macos/webkit CI is often failing with vite-dotenv-test.ts but I'm not sure if it's related to my PR. Is this something I should worry about?

Copy link
Member

Choose a reason for hiding this comment

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

@hi-ogawa I'm looking into that test failure now.

Copy link
Member

Choose a reason for hiding this comment

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

This PR got the test passing: #8177. I've just merged dev into your PR.

@pcattori pcattori reopened this Nov 29, 2023
@hi-ogawa hi-ogawa changed the title refactor(remix-dev/vite): remove redundant jsx and typescript babel plugins + remove remix-react-refresh-babel plugin from child vite compiler refactor(remix-dev/vite): remove redundant jsx and typescript babel plugins Nov 29, 2023
@markdalgleish markdalgleish merged commit 8776d7f into remix-run:dev Nov 30, 2023
9 checks passed
@hi-ogawa hi-ogawa deleted the refactor-vite-remove-remix-react-refresh-babel-child-compiler branch November 30, 2023 00:49
Copy link
Contributor

github-actions bot commented Dec 5, 2023

🤖 Hello there,

We just published version 2.4.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.4.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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.

5 participants