redi 이슈 해결
This commit is contained in:
@@ -44,6 +44,7 @@ declare global {
|
||||
getGlobalState: () => GlobalUniverState;
|
||||
clearGlobalState: () => void;
|
||||
forceReset: () => void;
|
||||
completeCleanup: () => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -213,6 +214,33 @@ const UniverseManager = {
|
||||
}
|
||||
}
|
||||
|
||||
// REDI 전역 상태 완전 정리 시도
|
||||
try {
|
||||
// 브라우저의 전역 REDI 상태 정리 (가능한 경우)
|
||||
if (typeof window !== "undefined") {
|
||||
// REDI 관련 전역 객체들 정리
|
||||
const globalKeys = Object.keys(window).filter(
|
||||
(key) =>
|
||||
key.includes("redi") ||
|
||||
key.includes("REDI") ||
|
||||
key.includes("univerjs") ||
|
||||
key.includes("univer"),
|
||||
);
|
||||
|
||||
globalKeys.forEach((key) => {
|
||||
try {
|
||||
delete (window as any)[key];
|
||||
} catch (e) {
|
||||
console.warn(`전역 키 ${key} 정리 실패:`, e);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("🧹 REDI 전역 상태 정리 시도 완료");
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("⚠️ REDI 전역 상태 정리 중 오류:", error);
|
||||
}
|
||||
|
||||
state.instance = null;
|
||||
state.univerAPI = null;
|
||||
state.isInitializing = false;
|
||||
@@ -221,37 +249,72 @@ const UniverseManager = {
|
||||
state.lastContainerId = null;
|
||||
window[GLOBAL_UNIVER_KEY] = null;
|
||||
|
||||
console.log("🔄 전역 Univer 상태 강제 리셋 완료");
|
||||
console.log("🔄 전역 Univer 상태 강제 리셋 완료 (REDI 정리 포함)");
|
||||
},
|
||||
|
||||
// 완전한 정리 메서드 (REDI 포함)
|
||||
async completeCleanup(): Promise<void> {
|
||||
const state = getGlobalState();
|
||||
|
||||
if (state.isDisposing) {
|
||||
console.log("🔄 이미 정리 진행 중...");
|
||||
return;
|
||||
}
|
||||
|
||||
state.isDisposing = true;
|
||||
|
||||
try {
|
||||
console.log("🗑️ 완전한 정리 시작 (REDI 포함)");
|
||||
|
||||
if (state.instance) {
|
||||
await state.instance.dispose();
|
||||
}
|
||||
|
||||
// 약간의 대기 후 REDI 상태 정리
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// REDI 전역 상태 정리 시도
|
||||
this.forceReset();
|
||||
|
||||
console.log("✅ 완전한 정리 완료");
|
||||
} catch (error) {
|
||||
console.error("❌ 완전한 정리 실패:", error);
|
||||
} finally {
|
||||
state.isDisposing = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// 전역 디버그 객체 설정
|
||||
if (typeof window !== "undefined") {
|
||||
// 전역 상태 초기화
|
||||
initializeGlobalState();
|
||||
// 전역 디버그 객체 설정을 위한 헬퍼 함수 (모듈 레벨 실행 방지)
|
||||
const setupDebugTools = (): void => {
|
||||
if (typeof window !== "undefined" && !window.__UNIVER_DEBUG__) {
|
||||
// 전역 상태 초기화 (필요한 경우에만)
|
||||
initializeGlobalState();
|
||||
|
||||
// 디버그 객체 설정
|
||||
window.__UNIVER_DEBUG__ = {
|
||||
getGlobalUniver: () => UniverseManager.getInstance(),
|
||||
getGlobalState: () => getGlobalState(),
|
||||
clearGlobalState: () => {
|
||||
const state = getGlobalState();
|
||||
Object.assign(state, {
|
||||
instance: null,
|
||||
univerAPI: null,
|
||||
isInitializing: false,
|
||||
isDisposing: false,
|
||||
initializationPromise: null,
|
||||
lastContainerId: null,
|
||||
});
|
||||
window[GLOBAL_UNIVER_KEY] = null;
|
||||
console.log("🧹 전역 상태 정리 완료");
|
||||
},
|
||||
forceReset: () => UniverseManager.forceReset(),
|
||||
};
|
||||
// 디버그 객체 설정
|
||||
window.__UNIVER_DEBUG__ = {
|
||||
getGlobalUniver: () => UniverseManager.getInstance(),
|
||||
getGlobalState: () => getGlobalState(),
|
||||
clearGlobalState: () => {
|
||||
const state = getGlobalState();
|
||||
Object.assign(state, {
|
||||
instance: null,
|
||||
univerAPI: null,
|
||||
isInitializing: false,
|
||||
isDisposing: false,
|
||||
initializationPromise: null,
|
||||
lastContainerId: null,
|
||||
});
|
||||
window[GLOBAL_UNIVER_KEY] = null;
|
||||
console.log("🧹 전역 상태 정리 완료");
|
||||
},
|
||||
forceReset: () => UniverseManager.forceReset(),
|
||||
completeCleanup: () => UniverseManager.completeCleanup(),
|
||||
};
|
||||
|
||||
console.log("🐛 디버그 객체 설정 완료: window.__UNIVER_DEBUG__");
|
||||
}
|
||||
console.log("🐛 디버그 객체 설정 완료: window.__UNIVER_DEBUG__");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Univer CE + 파일 업로드 오버레이
|
||||
@@ -520,28 +583,76 @@ const TestSheetViewer: React.FC = () => {
|
||||
mountedRef.current = true;
|
||||
console.log("🎯 컴포넌트 마운트됨");
|
||||
|
||||
// 기존 전역 인스턴스 확인 및 재사용
|
||||
// 디버그 도구 설정 (컴포넌트 마운트 시에만)
|
||||
setupDebugTools();
|
||||
|
||||
// 강화된 기존 인스턴스 확인 및 재사용
|
||||
const existingUniver = UniverseManager.getInstance();
|
||||
if (existingUniver && !UniverseManager.isInitializing()) {
|
||||
console.log("♻️ 기존 전역 Univer 인스턴스 재사용");
|
||||
const state = getGlobalState();
|
||||
|
||||
// 기존 인스턴스가 있고 정상 상태면 재사용
|
||||
if (
|
||||
existingUniver &&
|
||||
state.univerAPI &&
|
||||
!UniverseManager.isInitializing() &&
|
||||
!UniverseManager.isDisposing()
|
||||
) {
|
||||
console.log("♻️ 기존 전역 Univer 인스턴스와 univerAPI 재사용");
|
||||
setIsInitialized(true);
|
||||
|
||||
// 기존 인스턴스의 컨테이너가 현재 컨테이너와 다른 경우 갱신
|
||||
if (
|
||||
containerRef.current &&
|
||||
state.lastContainerId !== containerRef.current.id
|
||||
) {
|
||||
console.log("🔄 컨테이너 정보 갱신");
|
||||
state.lastContainerId = containerRef.current.id;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 컨테이너 준비 후 초기화
|
||||
// 초기화 중이거나 정리 중인 경우 대기
|
||||
if (UniverseManager.isInitializing() || UniverseManager.isDisposing()) {
|
||||
console.log("⏳ 초기화/정리 중이므로 대기");
|
||||
const waitTimer = setInterval(() => {
|
||||
if (
|
||||
!UniverseManager.isInitializing() &&
|
||||
!UniverseManager.isDisposing()
|
||||
) {
|
||||
clearInterval(waitTimer);
|
||||
const currentUniver = UniverseManager.getInstance();
|
||||
if (currentUniver && getGlobalState().univerAPI) {
|
||||
console.log("✅ 대기 후 기존 인스턴스 재사용");
|
||||
setIsInitialized(true);
|
||||
} else if (containerRef.current && mountedRef.current) {
|
||||
console.log("🚀 대기 후 새 인스턴스 초기화");
|
||||
initializeUniver();
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
|
||||
return () => clearInterval(waitTimer);
|
||||
}
|
||||
|
||||
// 완전히 새로운 초기화가 필요한 경우만 진행
|
||||
const initTimer = setTimeout(() => {
|
||||
if (containerRef.current && !UniverseManager.isInitializing()) {
|
||||
console.log("🚀 컴포넌트 마운트 시 Univer 초기화");
|
||||
// 마운트 상태와 컨테이너 재확인
|
||||
if (
|
||||
containerRef.current &&
|
||||
mountedRef.current &&
|
||||
!UniverseManager.isInitializing()
|
||||
) {
|
||||
console.log("🚀 컴포넌트 마운트 시 새 Univer 초기화");
|
||||
initializeUniver();
|
||||
}
|
||||
}, 100); // 짧은 지연으로 DOM 완전 준비 보장
|
||||
}, 100); // DOM 완전 준비 보장
|
||||
|
||||
return () => {
|
||||
clearTimeout(initTimer);
|
||||
mountedRef.current = false;
|
||||
console.log("👋 컴포넌트 언마운트됨");
|
||||
};
|
||||
}, [initializeUniver]);
|
||||
}, []); // 의존성 배열을 빈 배열로 변경하여 한 번만 실행
|
||||
|
||||
// 컴포넌트 언마운트 시 정리 (전역 인스턴스는 유지)
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user