|
883 | 883 | }; |
884 | 884 | init(); |
885 | 885 |
|
| 886 | + const onVisibilityChange = () => { |
| 887 | + if (document.visibilityState === 'visible') { |
| 888 | + cancelAnimationFrame(contentsRAF); |
| 889 | + contentsRAF = null; |
| 890 | + getContents(); |
| 891 | + const contents = get(artifactContents); |
| 892 | + if (contents && contents.length > 0 && !get(showControls) && !get(mobile)) { |
| 893 | + showArtifacts.set(true); |
| 894 | + showControls.set(true); |
| 895 | + } |
| 896 | + } |
| 897 | + }; |
| 898 | + document.addEventListener('visibilitychange', onVisibilityChange); |
| 899 | +
|
886 | 900 | return () => { |
887 | 901 | try { |
888 | 902 | clearTimeout(saveControlsTimer); |
889 | 903 | saveControls(); |
| 904 | + cancelAnimationFrame(scrollRAF); |
| 905 | + cancelAnimationFrame(contentsRAF); |
| 906 | + scrollRAF = null; |
| 907 | + contentsRAF = null; |
890 | 908 | if (chatIdProp && !$temporaryChatEnabled) { |
891 | 909 | updateLastReadAt(chatIdProp); |
892 | 910 | } |
893 | 911 | pageSubscribe(); |
894 | 912 | showControlsSubscribe(); |
895 | 913 | selectedFolderSubscribe(); |
896 | 914 | window.removeEventListener('message', onMessageHandler); |
| 915 | + document.removeEventListener('visibilitychange', onVisibilityChange); |
897 | 916 | $socket?.off('events', chatEventHandler); |
898 | 917 | audioQueueInstance?.destroy(); |
899 | 918 | audioQueue.set(null); |
|
1089 | 1108 |
|
1090 | 1109 | const onHistoryChange = (history) => { |
1091 | 1110 | if (history) { |
1092 | | - clearTimeout(contentsRAF); |
1093 | | - contentsRAF = setTimeout(() => { |
| 1111 | + if (createMessagesList(history, history.currentId).some(m => m.role !== 'user' && m.done === false)) return; |
| 1112 | +
|
| 1113 | + cancelAnimationFrame(contentsRAF); |
| 1114 | + contentsRAF = requestAnimationFrame(() => { |
1094 | 1115 | getContents(); |
1095 | 1116 | contentsRAF = null; |
1096 | | - }, 0); |
| 1117 | + }); |
1097 | 1118 | } else { |
1098 | 1119 | artifactContents.set([]); |
1099 | 1120 | } |
|
0 commit comments