|
924 | 924 | }; |
925 | 925 | init(); |
926 | 926 |
|
| 927 | + const onVisibilityChange = () => { |
| 928 | + if (document.visibilityState === 'visible') { |
| 929 | + cancelAnimationFrame(contentsRAF); |
| 930 | + contentsRAF = null; |
| 931 | + getContents(); |
| 932 | + const contents = get(artifactContents); |
| 933 | + if (contents && contents.length > 0 && !get(showControls) && !get(mobile)) { |
| 934 | + showArtifacts.set(true); |
| 935 | + showControls.set(true); |
| 936 | + } |
| 937 | + } |
| 938 | + }; |
| 939 | + document.addEventListener('visibilitychange', onVisibilityChange); |
| 940 | +
|
927 | 941 | return () => { |
928 | 942 | try { |
929 | 943 | clearTimeout(saveControlsTimer); |
930 | 944 | saveControls(); |
| 945 | + cancelAnimationFrame(scrollRAF); |
| 946 | + cancelAnimationFrame(contentsRAF); |
| 947 | + scrollRAF = null; |
| 948 | + contentsRAF = null; |
931 | 949 | if (chatIdProp && !$temporaryChatEnabled) { |
932 | 950 | updateLastReadAt(chatIdProp); |
933 | 951 | } |
934 | 952 | pageSubscribe(); |
935 | 953 | showControlsSubscribe(); |
936 | 954 | selectedFolderSubscribe(); |
937 | 955 | window.removeEventListener('message', onMessageHandler); |
| 956 | + document.removeEventListener('visibilitychange', onVisibilityChange); |
938 | 957 | $socket?.off('events', chatEventHandler); |
939 | 958 | dismissContextCompactionToast(); |
940 | 959 | audioQueueInstance?.destroy(); |
|
1131 | 1150 |
|
1132 | 1151 | const onHistoryChange = (history) => { |
1133 | 1152 | if (history) { |
1134 | | - clearTimeout(contentsRAF); |
1135 | | - contentsRAF = setTimeout(() => { |
| 1153 | + if (createMessagesList(history, history.currentId).some(m => m.role !== 'user' && m.done === false)) return; |
| 1154 | +
|
| 1155 | + cancelAnimationFrame(contentsRAF); |
| 1156 | + contentsRAF = requestAnimationFrame(() => { |
1136 | 1157 | getContents(); |
1137 | 1158 | contentsRAF = null; |
1138 | | - }, 0); |
| 1159 | + }); |
1139 | 1160 | } else { |
1140 | 1161 | artifactContents.set([]); |
1141 | 1162 | } |
|
0 commit comments