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: 优化插件内存 #231

Merged
merged 1 commit into from
Dec 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
.headerWrapper {
flex: 0 0 auto;
display: flex;
padding: 16px 10px 0;
gap: 30px;
padding: 16px 18px 0;
gap: 20px;

.headerItem {
cursor: pointer;
Expand All @@ -53,7 +53,7 @@
flex: 0 0 auto;

.title {
padding: 0 16px;
padding: 0 24px;
color: @text-primary;
font-weight: 500;
font-size: @font-size-lg;
Expand Down
2 changes: 1 addition & 1 deletion src/components/lake-editor/template-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const templateHtml = `
height: 100%;
}
.ne-layout-mode-fixed .ne-engine, .ne-layout-mode-adapt .ne-engine {
padding: 16px 16px 0;
padding: 16px 24px 0;
min-height: calc(100vh - 10px)
}
.ne-layout-mode-fixed .ne-editor-wrap-content {
Expand Down
21 changes: 21 additions & 0 deletions src/pages/inject/WordMark/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
useEffect,
useImperativeHandle,
useRef,
useState,
} from 'react';
import {
EDITOR_IFRAME_CONTAINER_ID,
Expand Down Expand Up @@ -75,6 +76,7 @@ const getRequestID = (() => {
export default forwardRef<IEditorRef, {}>((props, ref) => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const sendMessageRef = useRef<(data: any) => Promise<any>>();
const [needLoadEditor, setNeedLoadEditor] = useState(true);

useEffect(() => {
const resolveCache: Map<number, (data: any) => void> = new Map();
Expand Down Expand Up @@ -169,6 +171,25 @@ export default forwardRef<IEditorRef, {}>((props, ref) => {
[sendMessage],
);

useEffect(() => {
// 当页面可见性发生改变时,如果发现用户未使用过插件,释放掉 editor iframe
const onVisibilitychange = () => {
if (document.hidden) {
setNeedLoadEditor(false);
} else {
setNeedLoadEditor(true);
}
};
document.addEventListener('visibilitychange', onVisibilitychange);
return () => {
document.removeEventListener('visibilitychange', onVisibilitychange);
};
}, []);

if (!needLoadEditor) {
return null;
}

return (
<iframe
src={chrome.runtime.getURL('editor.html')}
Expand Down
Loading