Merge pull request #8359 from igrowp/fix-formula-control

fix: nextjs13环境下formulaControl组件popOverContainer 写死,导致编辑器出现死循环bug Close:#8355
This commit is contained in:
刘丹 2023-10-12 10:19:46 +08:00 committed by GitHub
commit 9647a54d78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -1587,7 +1587,7 @@ export function mapObject(
}
if (Array.isArray(value)) {
return value.map(item => mapObject(item, fn));
return value.map(item => mapObject(item, fn, skipFn));
}
if (isObject(value)) {
@ -1595,7 +1595,8 @@ export function mapObject(
Object.keys(tmpValue).forEach(key => {
(tmpValue as PlainObject)[key] = mapObject(
(tmpValue as PlainObject)[key],
fn
fn,
skipFn
);
});
return tmpValue;

View File

@ -1063,14 +1063,12 @@ export function getI18nEnabled() {
}
/** schema 翻译方法 */
export function translateSchema(schema: any, replaceData?: any) {
export function translateSchema(schema: any, replaceData?: any, skipFn?: any) {
replaceData = replaceData || (window as any)?.editorStore?.appCorpusData;
if (!isPlainObject(replaceData)) {
return schema;
}
return mapObject(schema, (item: any) => {
return replaceData[item] || item;
});
return mapObject(schema, (item: any) => replaceData[item] || item, skipFn);
}
/** 应用级别的翻译方法 */

View File

@ -516,15 +516,23 @@ export default class FormulaControl extends React.Component<
curRendererSchema.placeholder = '请输入静态值';
}
// 设置popOverContainer
curRendererSchema.popOverContainer = window.document.body;
if (!curRendererSchema.popOverContainer) {
curRendererSchema.popOverContainer = window.document.body;
}
}
JSONPipeOut(curRendererSchema);
// 对 schema 进行国际化翻译
if (this.appLocale && this.appCorpusData) {
return translateSchema(curRendererSchema, this.appCorpusData);
translateSchema(
curRendererSchema,
this.appCorpusData,
(item: any) => item.__reactFiber || item.__reactProp // 在nextjs 13中window.document.body对象有__reactFiber__reactProp 两个子对象,递归遍历会导致死循环,因此过滤掉
);
}
return JSONPipeOut(curRendererSchema);
return curRendererSchema;
}
@autobind