|
854 | 854 | }; |
855 | 855 | init(); |
856 | 856 |
|
| 857 | + const onVisibilityChange = () => { |
| 858 | + if (document.visibilityState === 'visible') { |
| 859 | + cancelAnimationFrame(contentsRAF); |
| 860 | + contentsRAF = null; |
| 861 | + getContents(); |
| 862 | + const contents = get(artifactContents); |
| 863 | + if (contents && contents.length > 0 && !get(showControls) && !get(mobile)) { |
| 864 | + showArtifacts.set(true); |
| 865 | + showControls.set(true); |
| 866 | + } |
| 867 | + } |
| 868 | + }; |
| 869 | + document.addEventListener('visibilitychange', onVisibilityChange); |
| 870 | +
|
857 | 871 | return () => { |
858 | 872 | try { |
859 | 873 | clearTimeout(saveControlsTimer); |
860 | 874 | saveControls(); |
| 875 | + cancelAnimationFrame(scrollRAF); |
| 876 | + cancelAnimationFrame(contentsRAF); |
| 877 | + scrollRAF = null; |
| 878 | + contentsRAF = null; |
861 | 879 | if (chatIdProp && !$temporaryChatEnabled) { |
862 | 880 | updateLastReadAt(chatIdProp); |
863 | 881 | } |
864 | 882 | pageSubscribe(); |
865 | 883 | showControlsSubscribe(); |
866 | 884 | selectedFolderSubscribe(); |
867 | 885 | window.removeEventListener('message', onMessageHandler); |
| 886 | + document.removeEventListener('visibilitychange', onVisibilityChange); |
868 | 887 | $socket?.off('events', chatEventHandler); |
869 | 888 | audioQueueInstance?.destroy(); |
870 | 889 | audioQueue.set(null); |
|
1060 | 1079 |
|
1061 | 1080 | const onHistoryChange = (history) => { |
1062 | 1081 | if (history) { |
1063 | | - clearTimeout(contentsRAF); |
1064 | | - contentsRAF = setTimeout(() => { |
| 1082 | + if (createMessagesList(history, history.currentId).some(m => m.role !== 'user' && m.done === false)) return; |
| 1083 | +
|
| 1084 | + cancelAnimationFrame(contentsRAF); |
| 1085 | + contentsRAF = requestAnimationFrame(() => { |
1065 | 1086 | getContents(); |
1066 | 1087 | contentsRAF = null; |
1067 | | - }, 0); |
| 1088 | + }); |
1068 | 1089 | } else { |
1069 | 1090 | artifactContents.set([]); |
1070 | 1091 | } |
|
0 commit comments