Skip to content

Commit f3b2a0f

Browse files
fix: resolve login crash, infinite renders, and logout scroll bugs (#1319)
1 parent 8116b22 commit f3b2a0f

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

packages/react/src/views/ChatBody/ChatBody.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ const ChatBody = ({
8686
(state) => state.isUserAuthenticated
8787
);
8888

89+
const isUserAuthenticatedRef = useRef(isUserAuthenticated);
90+
useEffect(() => {
91+
isUserAuthenticatedRef.current = isUserAuthenticated;
92+
}, [isUserAuthenticated]);
93+
8994
const username = useUserStore((state) => state.username);
9095

9196
const { getMessagesAndRoles, fetchAndSetPermissions, permissionsRef } =
@@ -217,7 +222,8 @@ const ChatBody = ({
217222
if (
218223
messageListRef.current.scrollTop === 0 &&
219224
!loadingOlderMessages &&
220-
hasMoreMessages
225+
hasMoreMessages &&
226+
(isUserAuthenticatedRef.current || anonymousMode)
221227
) {
222228
setLoadingOlderMessages(true);
223229

packages/react/src/views/EmbeddedChat.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import GlobalStyles from './GlobalStyles';
2626
import { overrideECProps } from '../lib/overrideECProps';
2727

2828
const EmbeddedChat = (props) => {
29-
const [config, setConfig] = useState(() => props);
29+
const [remoteOverrides, setRemoteOverrides] = useState({});
3030

31-
useEffect(() => {
32-
setConfig(props);
33-
}, [props]);
31+
const config = useMemo(
32+
() => ({ ...props, ...remoteOverrides }),
33+
// eslint-disable-next-line react-hooks/exhaustive-deps
34+
[props, remoteOverrides]
35+
);
3436

3537
const {
3638
isClosable = false,
@@ -52,14 +54,18 @@ const EmbeddedChat = (props) => {
5254
className = '',
5355
style = {},
5456
hideHeader = false,
55-
auth = {
56-
flow: 'PASSWORD',
57-
},
57+
auth: authProp = null,
5858
secure = false,
5959
dark = false,
6060
remoteOpt = false,
6161
} = config;
6262

63+
const auth = useMemo(
64+
() => authProp ?? { flow: 'PASSWORD' },
65+
// eslint-disable-next-line react-hooks/exhaustive-deps
66+
[authProp?.flow, authProp?.credentials]
67+
);
68+
6369
const hasMounted = useRef(false);
6470
const { classNames, styleOverrides } = useComponentOverrides('EmbeddedChat');
6571
const [fullScreen, setFullScreen] = useState(false);
@@ -208,7 +214,7 @@ const EmbeddedChat = (props) => {
208214

209215
if (appInfo) {
210216
const remoteConfig = appInfo.propConfig;
211-
setConfig((prevConfig) => overrideECProps(prevConfig, remoteConfig));
217+
setRemoteOverrides((prev) => overrideECProps(prev, remoteConfig));
212218
}
213219
} catch (error) {
214220
console.error('Error fetching remote config:', error?.message || error);
@@ -219,7 +225,7 @@ const EmbeddedChat = (props) => {
219225
if (remoteOpt) {
220226
getConfig();
221227
}
222-
}, [RCInstance, remoteOpt, setConfig, setIsSynced]);
228+
}, [RCInstance, remoteOpt, setIsSynced]);
223229

224230
const ECOptions = useMemo(
225231
() => ({

packages/ui-elements/src/components/Modal/Modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ export const Modal = forwardRef(
7272
}
7373
);
7474

75-
Modal.displayName = Modal;
75+
Modal.displayName = 'Modal';

0 commit comments

Comments
 (0)