@melony/react 0.1.42 → 0.1.43

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 CHANGED
@@ -777,6 +777,7 @@ var ThreadProvider = ({
777
777
  initialThreadId: providedInitialThreadId
778
778
  }) => {
779
779
  const queryClient = reactQuery.useQueryClient();
780
+ const melonyContext = React11.useContext(MelonyContext);
780
781
  const [activeThreadId, setActiveThreadId] = nuqs.useQueryState(
781
782
  "threadId",
782
783
  nuqs.parseAsString
@@ -793,17 +794,24 @@ var ThreadProvider = ({
793
794
  const {
794
795
  data: threads = [],
795
796
  isLoading,
797
+ isFetched: isFetchedThreads,
796
798
  error: threadsError,
797
799
  refetch: refreshThreads
798
800
  } = reactQuery.useQuery({
799
801
  queryKey: ["threads"],
800
802
  queryFn: () => service.getThreads(),
801
- staleTime: !prevActiveThreadIdRef.current && activeThreadId ? Infinity : 0
803
+ staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
802
804
  });
805
+ const isNewThread = React11.useMemo(() => {
806
+ if (!activeThreadId || !isFetchedThreads) return false;
807
+ return !threads.some((t) => t.id === activeThreadId);
808
+ }, [activeThreadId, threads, isFetchedThreads]);
803
809
  const { data: threadEvents = [], isLoading: isLoadingEvents } = reactQuery.useQuery({
804
810
  queryKey: ["threads", activeThreadId, "events"],
805
811
  queryFn: () => service.getEvents(activeThreadId),
806
- enabled: !!activeThreadId
812
+ enabled: !!activeThreadId,
813
+ initialData: isNewThread ? melonyContext?.events : void 0,
814
+ staleTime: isNewThread ? Infinity : 0
807
815
  });
808
816
  const createMutation = reactQuery.useMutation({
809
817
  mutationFn: async () => {