perf: skip es-module-lexer if have no dynamic imports#12732
Conversation
|
|
|
Sadly this is a required runtime check that is required to solve all the HMR edge cases for React. This regex could be done by the React plugin before injecting the hmr code and if no match also inject something like |
patak-cat
left a comment
There was a problem hiding this comment.
Nice! It is incredible we still have these unguarded operations to optimize.
That could work. Or maybe the react plugin could use a virtual module to expose the dynamic import too 🤔 import { __hmr_import } from 'virtual:react-hmr-utils'
__hmr_import(import.meta.url).then((currentExports) => {
// ...I think either ways it would be nice to take advantage of the optimization. |
|
Yeah I can even put this small wrapper in the RefreshRuntime modules. I will try it |
Description
Do a quick regex check for dynamic imports before using es-module-lexer to parse for dynamic import vars.
Additional context
I'm testing with https://github.com/sapphi-red/performance-compare, but it doesn't yield much improvements because React's HMR code has this: cc @ArnaudBarre
But for other cases, less files will be transformed with es-module-lexer now, which should make things faster.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).