Skip to content
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

fix: 修复 Overlay 定位弹出层部分懒加载导致的定位不准的问题 #11190

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/amis-core/src/RootRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export class RootRenderer extends React.Component<RootRendererProps> {
}
}
});
return loadAsyncRenderersByType(types, true);
return hasAsyncRenderers(types)
? loadAsyncRenderersByType(types, true)
: undefined;
});
}

Expand Down
9 changes: 4 additions & 5 deletions packages/amis-core/src/components/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Position extends React.Component<any, any> {
parentPopover: any;
// setState: (state: any) => void;
componentId: string;
overlay: HTMLDivElement;

static defaultProps = {
containerPadding: 0,
Expand Down Expand Up @@ -89,16 +90,13 @@ class Position extends React.Component<any, any> {
}

const watchTargetSizeChange = this.props.watchTargetSizeChange;
const overlay = findDOMNode(this as any) as HTMLElement;
const overlay = this.overlay;
const container = getContainer(
this.props.container,
ownerDocument(this).body
);

if (
(!this.watchedTarget || this.watchedTarget !== target) &&
getComputedStyle(target, 'position') !== 'static'
) {
if (!this.watchedTarget || this.watchedTarget !== target) {
this.resizeDispose?.forEach(fn => fn());
this.watchedTarget = target;
this.resizeDispose = [
Expand Down Expand Up @@ -131,6 +129,7 @@ class Position extends React.Component<any, any> {
}

componentDidMount() {
this.overlay = findDOMNode(this) as HTMLDivElement;
this.updatePosition(this.getTarget());
}

Expand Down
8 changes: 6 additions & 2 deletions packages/amis-core/src/factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,12 @@ export function isAsyncRenderer(item: RendererConfig) {
);
}

export function hasAsyncRenderers() {
return renderers.some(isAsyncRenderer);
export function hasAsyncRenderers(types?: Array<string>) {
return (
Array.isArray(types)
? renderers.filter(item => item.type && types.includes(item.type))
: renderers
).some(isAsyncRenderer);
}

export async function loadAsyncRenderersByType(
Expand Down
Loading