mirror of
https://github.com/lobehub/lobe-chat.git
synced 2025-12-26 04:33:46 +08:00
🐛 fix: fix a bug that weather plugin is not work correctly
This commit is contained in:
@@ -3,7 +3,8 @@ import { Skeleton } from 'antd';
|
||||
import { memo, useRef, useState } from 'react';
|
||||
|
||||
import { useOnPluginReadyForInteraction } from '../../utils/iframeOnReady';
|
||||
import { sendMessageToPlugin } from '../../utils/postMessage';
|
||||
import { useOnPluginFetchMessage } from '../../utils/listenToPlugin';
|
||||
import { sendMessageContentToPlugin } from '../../utils/postMessage';
|
||||
|
||||
interface IFrameRenderProps extends PluginRenderProps {
|
||||
height?: number;
|
||||
@@ -20,7 +21,15 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, width = 800, height = 300,
|
||||
const iframeWin = iframeRef.current?.contentWindow;
|
||||
|
||||
if (iframeWin) {
|
||||
sendMessageToPlugin(iframeWin, props);
|
||||
sendMessageContentToPlugin(iframeWin, props);
|
||||
}
|
||||
}, [props]);
|
||||
|
||||
// when get iframe fetch message ,send message content
|
||||
useOnPluginFetchMessage(() => {
|
||||
const iframeWin = iframeRef.current?.contentWindow;
|
||||
if (iframeWin) {
|
||||
sendMessageContentToPlugin(iframeWin, props);
|
||||
}
|
||||
}, [props]);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
useOnPluginFillContent,
|
||||
} from '../utils/listenToPlugin';
|
||||
import {
|
||||
sendMessageToPlugin,
|
||||
sendMessageContentToPlugin,
|
||||
sendPayloadToPlugin,
|
||||
sendPluginSettingsToPlugin,
|
||||
sendPluginStateToPlugin,
|
||||
@@ -58,7 +58,7 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, id, payload, width = 600, h
|
||||
props.content = message.content || '';
|
||||
}
|
||||
|
||||
sendMessageToPlugin(iframeWin, props);
|
||||
sendMessageContentToPlugin(iframeWin, props);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PluginChannel } from '@lobehub/chat-plugin-sdk/client';
|
||||
|
||||
export const sendMessageToPlugin = (window: Window, props: any) => {
|
||||
export const sendMessageContentToPlugin = (window: Window, props: any) => {
|
||||
window.postMessage({ props, type: PluginChannel.renderPlugin }, '*');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user