Skip to content

Commit

Permalink
fix: Less Maximum call stack size exceeded error (#32063)
Browse files Browse the repository at this point in the history
* chore: create additional entry

* fix: rm recv call

* chore: Add default.less as index.less

* chore: update entry

* fix: row should also translate

* chore: rename index-default to index and add index-pure instead

* fix: missing transfer customize styl
  • Loading branch information
zombieJ authored Sep 7, 2021
1 parent 0f47b50 commit e13c4d4
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 51 deletions.
57 changes: 42 additions & 15 deletions .antd-tools.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function finalizeCompile() {
componentsLessContent += `@import "../${path.posix.join(
file,
'style',
'index.less',
'index-pure.less',
)}";\n`;
}
});
Expand All @@ -35,6 +35,24 @@ function finalizeCompile() {
);
});
}

// Create entry for babel plugin import
function patchEntry(styleEntry) {
if (fs.existsSync(styleEntry)) {
fs.writeFileSync(
path.join(styleEntry, 'style', 'index-default.less'),
[
// Inject variable
'@root-entry-name: default;',
// Point to origin file
"@import './index';",
].join('\n'),
);
}
}

patchEntry(path.join(process.cwd(), 'lib'));
patchEntry(path.join(process.cwd(), 'es'));
}

function buildThemeFile(theme, vars) {
Expand Down Expand Up @@ -78,7 +96,7 @@ function finalizeDist() {
// Build less entry file: dist/antd.less
fs.writeFileSync(
path.join(process.cwd(), 'dist', 'antd.less'),
'@import "../lib/style/index.less";\n@import "../lib/style/components.less";',
'@import "../lib/style/default.less";\n@import "../lib/style/components.less";',
);
// eslint-disable-next-line no-console
fs.writeFileSync(
Expand Down Expand Up @@ -126,49 +144,58 @@ module.exports = {
}
}

function isComponentStyle(file) {
function isComponentStyleEntry(file) {
return file.path.match(/style(\/|\\)index\.tsx/);
}

function needTransformStyle(content) {
return content.includes('./index.less');
return content.includes('../../style/index.less') || content.includes('./index.less');
}

module.exports = {
compile: {
transformTSFile(file) {
if (isComponentStyle(file)) {
if (isComponentStyleEntry(file)) {
let content = file.contents.toString();

if (needTransformStyle(content)) {
const cloneFile = file.clone();

// Origin
content = content.replace('./index.less', './index-default.less');
content = content.replace('../../style/index.less', '../../style/index-default.less');
// content = content.replace('./index.less', './index-default.less');
cloneFile.contents = Buffer.from(content);

return cloneFile;
}
}
},
transformFile(file) {
if (isComponentStyle(file)) {
const content = file.contents.toString();

if (needTransformStyle(content)) {
const cloneFile = file.clone();
cloneFile.contents = Buffer.from(
if (isComponentStyleEntry(file)) {
const indexLessFilePath = file.path.replace('index.tsx', 'index.less');

if (fs.existsSync(indexLessFilePath)) {
// We put origin `index.less` file to `index-pure.less`
const pureFile = file.clone();
pureFile.contents = Buffer.from(fs.readFileSync(indexLessFilePath, 'utf8'));
pureFile.path = pureFile.path.replace('index.tsx', 'index-pure.less');

// Rewrite `index.less` file with `root-entry-name`
const indexLessFile = file.clone();
indexLessFile.contents = Buffer.from(
[
// Inject variable
'@root-entry-name: default;',
// Point to origin file
"@import './index';",
"@import './index-pure.less';",
].join('\n\n'),
);
cloneFile.path = cloneFile.path.replace('index.tsx', 'index-default.less');
return cloneFile;
indexLessFile.path = indexLessFile.path.replace('index.tsx', 'index.less');

return [indexLessFile, pureFile];
}
}

return [];
},
lessConfig: {
Expand Down
4 changes: 3 additions & 1 deletion components/cascader/style/rtl.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import (reference) './index';
// We can not import reference of `./index` directly since it will make dead loop in less
@import (reference) '../../style/themes/index';
@cascader-prefix-cls: ~'@{ant-prefix}-cascader';

.@{cascader-prefix-cls}-rtl {
.@{cascader-prefix-cls}-menu-item {
Expand Down
3 changes: 0 additions & 3 deletions components/drawer/style/customize.less

This file was deleted.

3 changes: 2 additions & 1 deletion components/drawer/style/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './drawer';
@import './customize';
@import './rtl';

.popover-customize-bg(@drawer-prefix-cls, @popover-background);
4 changes: 3 additions & 1 deletion components/dropdown/style/status.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import './index';
@import (reference) '../../style/themes/index';

@dropdown-prefix-cls: ~'@{ant-prefix}-dropdown';

.@{dropdown-prefix-cls}-menu-item {
&&-danger {
Expand Down
5 changes: 4 additions & 1 deletion components/form/style/components.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import './index';
@import (reference) '../../style/themes/index';

@form-prefix-cls: ~'@{ant-prefix}-form';
@form-item-prefix-cls: ~'@{form-prefix-cls}-item';

// ================================================================
// = Children Component =
Expand Down
5 changes: 4 additions & 1 deletion components/form/style/horizontal.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import './index';
@import (reference) '../../style/themes/index';

@form-prefix-cls: ~'@{ant-prefix}-form';
@form-item-prefix-cls: ~'@{form-prefix-cls}-item';

.@{form-prefix-cls}-horizontal {
.@{form-item-prefix-cls}-label {
Expand Down
5 changes: 4 additions & 1 deletion components/form/style/inline.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import './index';
@import (reference) '../../style/themes/index';

@form-prefix-cls: ~'@{ant-prefix}-form';
@form-item-prefix-cls: ~'@{form-prefix-cls}-item';

.@{form-prefix-cls}-inline {
display: flex;
Expand Down
5 changes: 4 additions & 1 deletion components/form/style/status.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import './index.less';
@import (reference) '../../style/themes/index';

@form-prefix-cls: ~'@{ant-prefix}-form';
@form-item-prefix-cls: ~'@{form-prefix-cls}-item';

.@{form-item-prefix-cls} {
// ================================================================
Expand Down
5 changes: 4 additions & 1 deletion components/form/style/vertical.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import './index';
@import (reference) '../../style/themes/index';

@form-prefix-cls: ~'@{ant-prefix}-form';
@form-item-prefix-cls: ~'@{form-prefix-cls}-item';

// ================== Label ==================
.make-vertical-layout-label() {
Expand Down
4 changes: 3 additions & 1 deletion components/input/style/affix.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import './index';
@import './mixin';

@import (reference) '../../style/themes/index';
@input-prefix-cls: ~'@{ant-prefix}-input';

@input-affix-margin: 4px;

.@{ant-prefix}-input {
Expand Down
3 changes: 2 additions & 1 deletion components/input/style/allow-clear.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './index';
@import (reference) '../../style/themes/index';
@input-prefix-cls: ~'@{ant-prefix}-input';

// ========================= Input =========================
.@{iconfont-css-prefix}.@{ant-prefix}-input-clear-icon {
Expand Down
3 changes: 2 additions & 1 deletion components/list/style/customize.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import './index.less';
@import '../../style/themes/index';

@list-prefix-cls: ~'@{ant-prefix}-list';
@card-prefix-cls: ~'@{ant-prefix}-card';

.@{list-prefix-cls} {
Expand Down
3 changes: 2 additions & 1 deletion components/menu/style/status.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './index';
@import (reference) '../../style/themes/index';
@menu-prefix-cls: ~'@{ant-prefix}-menu';

.@{menu-prefix-cls} {
// Danger
Expand Down
3 changes: 0 additions & 3 deletions components/modal/style/customize.less

This file was deleted.

3 changes: 2 additions & 1 deletion components/modal/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
@import '../../style/mixins/index';
@import './modal';
@import './confirm';
@import './customize';
@import './rtl';

.popover-customize-bg(@dialog-prefix-cls, @popover-background);
3 changes: 0 additions & 3 deletions components/notification/style/customize.less

This file was deleted.

3 changes: 2 additions & 1 deletion components/notification/style/index.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './customize.less';

.popover-customize-bg(@notification-prefix-cls, @popover-background);

@notification-prefix-cls: ~'@{ant-prefix}-notification';
@notification-width: 384px;
Expand Down
3 changes: 0 additions & 3 deletions components/popover/style/customize.less

This file was deleted.

3 changes: 2 additions & 1 deletion components/select/style/multiple.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './index';
@import (reference) '../../style/themes/index';
@select-prefix-cls: ~'@{ant-prefix}-select';

@select-overflow-prefix-cls: ~'@{select-prefix-cls}-selection-overflow';
@select-multiple-item-border-width: 1px;
Expand Down
3 changes: 2 additions & 1 deletion components/select/style/single.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './index';
@import (reference) '../../style/themes/index';
@select-prefix-cls: ~'@{ant-prefix}-select';

@selection-item-padding: ceil(@font-size-base * 1.25);

Expand Down
4 changes: 4 additions & 0 deletions components/style/default.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This is same as `index.less` but given `root-entry-name` for `dist/antd.less` usage
@root-entry-name: default;

@import './index';
4 changes: 3 additions & 1 deletion components/switch/style/rtl.less
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './index';

@switch-prefix-cls: ~'@{ant-prefix}-switch';

@switch-pin-size: @switch-height - 4px;
@switch-sm-pin-size: @switch-sm-height - 4px;

.@{switch-prefix-cls}-rtl {
direction: rtl;

Expand Down
4 changes: 3 additions & 1 deletion components/table/style/bordered.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import './index';
@import './size';

@import (reference) '../../style/themes/index';
@table-prefix-cls: ~'@{ant-prefix}-table';

@table-border: @border-width-base @border-style-base @table-border-color;

.@{table-prefix-cls}.@{table-prefix-cls}-bordered {
Expand Down
4 changes: 3 additions & 1 deletion components/table/style/size.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import './index';
@import (reference) '../../style/themes/index';

@table-prefix-cls: ~'@{ant-prefix}-table';

.table-size(@size, @padding-vertical, @padding-horizontal, @font-size) {
.@{table-prefix-cls}.@{table-prefix-cls}-@{size} {
Expand Down
3 changes: 2 additions & 1 deletion components/tabs/style/card.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './index';

@tab-prefix-cls: ~'@{ant-prefix}-tabs';

.@{tab-prefix-cls}-card {
> .@{tab-prefix-cls}-nav,
Expand Down
3 changes: 2 additions & 1 deletion components/tabs/style/dropdown.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './index';

@tab-prefix-cls: ~'@{ant-prefix}-tabs';

.@{tab-prefix-cls}-dropdown {
.reset-component();
Expand Down
3 changes: 2 additions & 1 deletion components/tabs/style/position.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './index';
@import '../../style/themes/index';
@tab-prefix-cls: ~'@{ant-prefix}-tabs';

.@{tab-prefix-cls} {
// ========================== Top & Bottom ==========================
Expand Down
3 changes: 2 additions & 1 deletion components/tabs/style/size.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './index';

@tab-prefix-cls: ~'@{ant-prefix}-tabs';

.@{tab-prefix-cls} {
&-small {
Expand Down
4 changes: 3 additions & 1 deletion components/transfer/style/customize.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import './index.less';
@import '../../style/themes/index';

@transfer-prefix-cls: ~'@{ant-prefix}-transfer';

@table-prefix-cls: ~'@{ant-prefix}-table';
@input-prefix-cls: ~'@{ant-prefix}-input';
Expand Down

0 comments on commit e13c4d4

Please sign in to comment.