@melony/react 0.1.42 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,8 +69,13 @@ var MelonyContextProviderInner = ({
|
|
|
69
69
|
case "client:navigate": {
|
|
70
70
|
const url = event.data?.url;
|
|
71
71
|
if (url) {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const isStreaming = client.getState().isLoading;
|
|
73
|
+
if (isStreaming) {
|
|
74
|
+
window.history.replaceState(null, "", url);
|
|
75
|
+
} else {
|
|
76
|
+
window.history.pushState(null, "", url);
|
|
77
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
return true;
|
|
76
81
|
}
|
|
@@ -756,6 +761,7 @@ var ThreadProvider = ({
|
|
|
756
761
|
initialThreadId: providedInitialThreadId
|
|
757
762
|
}) => {
|
|
758
763
|
const queryClient = useQueryClient();
|
|
764
|
+
const melonyContext = useContext(MelonyContext);
|
|
759
765
|
const [activeThreadId, setActiveThreadId] = useQueryState(
|
|
760
766
|
"threadId",
|
|
761
767
|
parseAsString
|
|
@@ -772,17 +778,24 @@ var ThreadProvider = ({
|
|
|
772
778
|
const {
|
|
773
779
|
data: threads = [],
|
|
774
780
|
isLoading,
|
|
781
|
+
isFetched: isFetchedThreads,
|
|
775
782
|
error: threadsError,
|
|
776
783
|
refetch: refreshThreads
|
|
777
784
|
} = useQuery({
|
|
778
785
|
queryKey: ["threads"],
|
|
779
786
|
queryFn: () => service.getThreads(),
|
|
780
|
-
staleTime:
|
|
787
|
+
staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
|
|
781
788
|
});
|
|
789
|
+
const isNewThread = useMemo(() => {
|
|
790
|
+
if (!activeThreadId || !isFetchedThreads) return false;
|
|
791
|
+
return !threads.some((t) => t.id === activeThreadId);
|
|
792
|
+
}, [activeThreadId, threads, isFetchedThreads]);
|
|
782
793
|
const { data: threadEvents = [], isLoading: isLoadingEvents } = useQuery({
|
|
783
794
|
queryKey: ["threads", activeThreadId, "events"],
|
|
784
795
|
queryFn: () => service.getEvents(activeThreadId),
|
|
785
|
-
enabled: !!activeThreadId
|
|
796
|
+
enabled: !!activeThreadId,
|
|
797
|
+
initialData: isNewThread ? melonyContext?.events : void 0,
|
|
798
|
+
staleTime: isNewThread ? Infinity : 0
|
|
786
799
|
});
|
|
787
800
|
const createMutation = useMutation({
|
|
788
801
|
mutationFn: async () => {
|