From 84ff7e61e053d86a9e2d90729b15c536c3a03518 Mon Sep 17 00:00:00 2001 From: Rodrigo Arze Date: Tue, 25 Feb 2025 23:17:56 -0400 Subject: [PATCH 1/4] Memo main component, improve initial loader bg and bump version --- kits/connect/package.json | 2 +- kits/connect/src/embed-react.tsx | 142 +++++++++++++++++-------------- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/kits/connect/package.json b/kits/connect/package.json index 756043b07..e3b9381d5 100644 --- a/kits/connect/package.json +++ b/kits/connect/package.json @@ -1,6 +1,6 @@ { "name": "@openint/connect", - "version": "0.2.19", + "version": "0.2.22", "sideEffects": false, "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/kits/connect/src/embed-react.tsx b/kits/connect/src/embed-react.tsx index 956551149..c1c510279 100644 --- a/kits/connect/src/embed-react.tsx +++ b/kits/connect/src/embed-react.tsx @@ -10,72 +10,82 @@ export interface OpenIntConnectEmbedProps const DEFAULT_HEIGHT = 500 const DEFAULT_WIDTH = 350 -export const OpenIntConnectEmbed = React.forwardRef( - ( - {baseUrl, params, onReady, ...iframeProps}: OpenIntConnectEmbedProps, - forwardedRef: React.ForwardedRef, - ) => { - const url = getIFrameUrl({baseUrl, params}) - const [loading, setLoading] = React.useState(true) +export const OpenIntConnectEmbed = React.memo( + React.forwardRef( + ( + props: OpenIntConnectEmbedProps, + forwardedRef: React.ForwardedRef, + ) => { + const {baseUrl, params, onReady, ...iframeProps} = props - React.useEffect(() => { - if ( - typeof iframeProps.height === 'number' && - iframeProps.height < DEFAULT_HEIGHT - ) { - console.warn( - 'Optimal height for Connect is 500px. Using 500px instead.', - ) - } - if (typeof iframeProps.width === 'number' && iframeProps.width < 350) { - console.warn('Minimum width for Connect is 350px. Using 350px instead.') - } - }, [iframeProps.height, iframeProps.width]) + const url = React.useMemo( + () => getIFrameUrl({baseUrl, params}), + [baseUrl, params], + ) - const height = - typeof iframeProps.height === 'number' - ? iframeProps.height > DEFAULT_HEIGHT - ? iframeProps.height - : DEFAULT_HEIGHT - : iframeProps.height + const [loading, setLoading] = React.useState(true) - const width = - typeof iframeProps.width === 'number' - ? iframeProps.width > DEFAULT_WIDTH - ? iframeProps.width - : DEFAULT_WIDTH - : iframeProps.width || DEFAULT_WIDTH + React.useEffect(() => { + if ( + typeof iframeProps.height === 'number' && + iframeProps.height < DEFAULT_HEIGHT + ) { + console.warn( + 'Optimal height for Connect is 500px. Using 500px instead.', + ) + } + if (typeof iframeProps.width === 'number' && iframeProps.width < 350) { + console.warn( + 'Minimum width for Connect is 350px. Using 350px instead.', + ) + } + }, [iframeProps.height, iframeProps.width]) - // Add a more reliable way to know iframe has fully finished loading - // by sending message from iframe to parent when ready - return ( -
-
- - - -
-