chore: handle next.js build issue #48829
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
中文版模板 / Chinese template
🤔 This is a ...
🔗 Related issue link
close #48758
Reported this to Next.js repo: vercel/next.js#65512
💡 Background and solution
I do believe it's not
antd
bug. But a strange mix bug withNext.js
&babel
&Webpack
.Dig the build process of
next build
found the first compile of webpack is work as expected. But theGenerating static page
step will hang for a long time.After debug the break point or dump the memory heap, there is nothing special about this. Break point is normal for the parsing and memory heap is stable (for antd with nextjs example, it's stable between ~80MB). It takes me lots of time, sad 😅.
Since
5.16.5
works well, it can use theresolution
ofpackage.json
to check all the diff dependencies version. And finally found that lockrc-field-form
to v1 version will back of the speed.After that, check what changed in
rc-field-form
v2.0.0, and found the depsasync-validator
replaced with@rc-component/async-validator
. What change is usingfather@4
& correct the type definition.Modify the
node_modules/@rc-component/async-validator
code to check what happened:The build speed back again. But when back of the
import
, it becomes slow again:I guess it must have some dependencies cycle in it but finally get none. All the files dependencies is clear. So it have to comment code in it to check what make it slow. Skip the checking process, it comes from the follow code:
Source code:
The compiled code in
async-validator
package:The difference is the string concat replaced by babel with
.concat
function. When replace the code with the original one, Next.js fast again.I'm not sure why the long
.concat
makes Next.js slow. But for antd side, we can do the workaround:Fixed with magic code. But Next.js may need help to check on this.
📝 Changelog
Next.js
build bad perf issue.Next.js
编译性能问题。☑️ Self-Check before Merge