-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SWC Wasm Plugin #3589
Comments
the biggest amount of work would be to rewrite our ICU message parser in Rust, which we've tried and the performance difference is negligible so we dropped it |
Is that prototype code still available somewhere? I've never worked with the ICU spec myself and am wondering what that would look like. |
cc @pyrocat101 ^^ |
Was looking for the older parser implementation in Rust but unfortunately I think I might have deleted the repo from Github :(
The current JavaScript parser is actually ported from my earlier Rust implementation, with very similar program structure. If I were you, I would start extracting the existing test cases (message text, parser options, expected parser result) into serialized files that can be reused between the JS version and the Rust version, and then start modeling the Rust version after the JS version. |
Thanks, I think that's all the pointers we need. By the way, I'm happy to report that Vercel seems pretty close now to enabling SWC plugin support in Next.js itself. On our side we're still considering whether we actually need to write this particular plugin or if our own tooling works as is. I'm going to close this issue until we know more, will reopen it if we go ahead. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
short update - next.js added WASM plugin support to their latest canary |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Looks like Next.js |
I tried experimental: {
swcPlugins: [['@formatjs/swc-plugin']],
}, it lead to this error:
for info, my current {
"presets": ["next/babel"],
"plugins": [
[
"formatjs",
{
"idInterpolationPattern": "[sha512:contenthash:base64:6]",
"ast": true
}
]
]
} Someone has a successfull implementation of the SWC plugin with Next.js ? |
@aurelien-gaillard the current formatjs swc plugin is no longer compatible with the latest swc plugin system for more details please read the comments above |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
until someone provides a codesandbox or a repro repo I can't really look into this |
@longlho I believe this issue isn't reporting a bug in the existing plugin but rather asking for a new WASM plugin. https://swc.rs/docs/plugin/ecmascript/getting-started Next.js now supports this WASM plugins but doesn't support JS plugins like |
Right I get that but there seems to be reports that the current one doesn't work w/ next.js? |
Not that I'm aware of, at least not directly. Next.js will still fall back to using Babel in the presence of |
|
@longlho true - Next.js SWC plugins only support WASM plugins and not JS plugins (in fact, there was never an option to customize |
It works now, thanks a lot. But I noticed one exception is using intl.formatMessage({ defaultMessage: "xx" }) within useMemo, in this case if not set ID, the require ID error will show, simply remove useMemo block and then it works again. |
Using the
Can confirm that removing |
I further notice can't even put in a array to loop on, will also causing the missing id error.
|
Do u have a repro codesandbox or something? |
Im trying on it, my original project is a Monorepo setup with many pacakges, FormatteedMesage been used from local dependency, not sure wether can reproduce it in Simple set up. In my case I notice at least in my Monorepo project, fall back to use Babel plugin not only do not have all issue above but also even much faster than SWC, so I just switched back to use babel instead. I think might because of Monorepo, from time to time I see this error during page navigation with SWC plugin (Babel also works all fine without any issue)
|
Here's a repro: https://github.com/jvmiert/formatjs-swc-issue On these lines: https://github.com/jvmiert/formatjs-swc-issue/blob/main/pages/index.tsx#L47 This breaks on Windows with: I didn't test it yet on Linux. |
Thanks @pyrocat101 for helping me get this into a project that's using @vitejs/plugin-react-swc! @longlho any chance of a major version bump on the officially sanctioned plugin (or event a next/alpha tag in npm?) |
@pyrocat101 mind taking a look? |
@jvmiert I am inclined to believe that this is a bug in SWC's visitor. I took your example and added some logging to My repro scratchpad is here: main...swcVisitorBugRepro3589 Running Consider filing a bug upstream? |
Thank you for checking it out @pyrocat101! I will file an issue in the coming days. I'm not super familiar with SWC or Rust but will try nevertheless |
I took a look at your branch @pyrocat101. Please correct me if I'm wrong but I don't think this is an issue with SWC. The elements show up when you add the same logging to this function: formatjs/rust/swc-formatjs-visitor/src/lib.rs Line 1150 in a127d79
So I'm guessing the plugin is currently not yet properly processing JSX inside expressions? This is a little bit out of my depth but I might have a look at it when I have more time later this week. |
@jvmiert Ah I figured it out. The original implementation missed a |
…all expression (#4111) The original Rust implementation does not visit the children of the call expression, as was discovered in #3589 (comment). This PR fixes that.
Just wanted to share that this fixed all the issues I was seeing. Thanks for looking into this and fixing it, much appreciated. |
…swc 1.3.56 (formatjs#4090) For formatjs#3589 Update `swc_core` Rust crate and the `swc` NPM package used in the Node.js test. This PR should fix the crash that are reported on the latest version of next.js. I have tested the following combination: - plugin built from this PR - next 13.3.2 - swc 1.3.56
…all expression (formatjs#4111) The original Rust implementation does not visit the children of the call expression, as was discovered in formatjs#3589 (comment). This PR fixes that.
@pyrocat101 does this mean we can now omit specifying IDs in a |
That should be the case. Try out |
Using the latest plugin and nextjs 13.4.5 I still get errors. Here is my nextjs config :
And here are the errors :
|
@fdecampredon See #3589 (comment) 0.3.7 is built against swc_core 0.75.42, so the supported nextjs version is here: https://swc.rs/docs/plugin/selecting-swc-core#v075x |
After decreasing the next version to 13.4.2, I got this error :
|
It's been working alright so far, which is wonderful! Sorry I just wanted a bit of confirmation. Thank you! |
I tried to make a fresh project with:
and config:
and I'm still getting this error:
|
I noticed that
|
is this still being worked on / prioritized? |
|
I am currently able to make it work with Here's my next.config
|
Hi @longlho
maybe you saw that the next community likes formatjs a lot and for some it's kind of blocking that nextjs does not allow to use your SWC plugin:
vercel/next.js#30174 (comment)
vercel/next.js#35502
vercel/next.js#33698
Vercel has been asked several times about their plan about SWC plugins but unfortunately the only feedback is that they are still looking into it:
vercel/next.js#30212
vercel/next.js#34384
In the meantime SWC (the compiler used to replace Babel in NextJs) added experimental plugin support for a new API which is way faster than their previous plugin system and will replace the current plugin system:
swc-project/swc#3540
Right now @martindisch and me are porting some babel plugins and experimenting with a hacked @next/swc version on our quite large codebase to learn more about potential performance gains.
Because of the great demand we are considering to port FormatJs to a Rust SWC plugin.
But before we start we would love to hear your feedback first - so please let us know what you think about all that :)
The text was updated successfully, but these errors were encountered: