@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.cjs
CHANGED
|
@@ -90,8 +90,13 @@ var MelonyContextProviderInner = ({
|
|
|
90
90
|
case "client:navigate": {
|
|
91
91
|
const url = event.data?.url;
|
|
92
92
|
if (url) {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
const isStreaming = client.getState().isLoading;
|
|
94
|
+
if (isStreaming) {
|
|
95
|
+
window.history.replaceState(null, "", url);
|
|
96
|
+
} else {
|
|
97
|
+
window.history.pushState(null, "", url);
|
|
98
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
99
|
+
}
|
|
95
100
|
}
|
|
96
101
|
return true;
|
|
97
102
|
}
|
|
@@ -777,6 +782,7 @@ var ThreadProvider = ({
|
|
|
777
782
|
initialThreadId: providedInitialThreadId
|
|
778
783
|
}) => {
|
|
779
784
|
const queryClient = reactQuery.useQueryClient();
|
|
785
|
+
const melonyContext = React11.useContext(MelonyContext);
|
|
780
786
|
const [activeThreadId, setActiveThreadId] = nuqs.useQueryState(
|
|
781
787
|
"threadId",
|
|
782
788
|
nuqs.parseAsString
|
|
@@ -793,17 +799,24 @@ var ThreadProvider = ({
|
|
|
793
799
|
const {
|
|
794
800
|
data: threads = [],
|
|
795
801
|
isLoading,
|
|
802
|
+
isFetched: isFetchedThreads,
|
|
796
803
|
error: threadsError,
|
|
797
804
|
refetch: refreshThreads
|
|
798
805
|
} = reactQuery.useQuery({
|
|
799
806
|
queryKey: ["threads"],
|
|
800
807
|
queryFn: () => service.getThreads(),
|
|
801
|
-
staleTime:
|
|
808
|
+
staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
|
|
802
809
|
});
|
|
810
|
+
const isNewThread = React11.useMemo(() => {
|
|
811
|
+
if (!activeThreadId || !isFetchedThreads) return false;
|
|
812
|
+
return !threads.some((t) => t.id === activeThreadId);
|
|
813
|
+
}, [activeThreadId, threads, isFetchedThreads]);
|
|
803
814
|
const { data: threadEvents = [], isLoading: isLoadingEvents } = reactQuery.useQuery({
|
|
804
815
|
queryKey: ["threads", activeThreadId, "events"],
|
|
805
816
|
queryFn: () => service.getEvents(activeThreadId),
|
|
806
|
-
enabled: !!activeThreadId
|
|
817
|
+
enabled: !!activeThreadId,
|
|
818
|
+
initialData: isNewThread ? melonyContext?.events : void 0,
|
|
819
|
+
staleTime: isNewThread ? Infinity : 0
|
|
807
820
|
});
|
|
808
821
|
const createMutation = reactQuery.useMutation({
|
|
809
822
|
mutationFn: async () => {
|