feat(iframe-bridge): implement iframe communication bridge and language sync

This commit is contained in:
2025-11-14 20:07:08 +08:00
parent 4356813820
commit 034c190373
15 changed files with 469 additions and 160 deletions

View File

@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { createPenpalHostBridge } from '@teres/iframe-bridge';
import { setChildPromise, clearChildPromise } from '@/iframe/bridgeManager';
import logger from '@/utils/logger';
export default function RagflowAgentPage() {
@@ -14,7 +15,7 @@ export default function RagflowAgentPage() {
useEffect(() => {
const el = iframeRef.current;
if (!el) return;
const { destroy } = createPenpalHostBridge({
const { destroy, child } = createPenpalHostBridge({
iframe: el,
methods: {
navigate: (to: string) => navigate(to),
@@ -24,7 +25,11 @@ export default function RagflowAgentPage() {
},
},
});
return () => destroy();
setChildPromise(child);
return () => {
clearChildPromise();
destroy();
};
}, [navigate]);
// 如需兼容旧的 postMessage 事件,可保留以下监听;为了纯 Penpal此处移除

View File

@@ -1,6 +1,7 @@
import { useEffect, useRef } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { createPenpalHostBridge, toChildPath } from '@teres/iframe-bridge';
import { setChildPromise, clearChildPromise } from '@/iframe/bridgeManager';
export default function RagflowIframePage() {
const location = useLocation();
@@ -13,7 +14,7 @@ export default function RagflowIframePage() {
useEffect(() => {
const el = iframeRef.current;
if (!el) return;
const { destroy } = createPenpalHostBridge({
const { destroy, child } = createPenpalHostBridge({
iframe: el,
methods: {
navigate: (to: string) => navigate(to),
@@ -23,7 +24,11 @@ export default function RagflowIframePage() {
},
},
});
return () => destroy();
setChildPromise(child);
return () => {
clearChildPromise();
destroy();
};
}, [navigate, src]);
return (