@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.js CHANGED
@@ -756,6 +756,7 @@ var ThreadProvider = ({
756
756
  initialThreadId: providedInitialThreadId
757
757
  }) => {
758
758
  const queryClient = useQueryClient();
759
+ const melonyContext = useContext(MelonyContext);
759
760
  const [activeThreadId, setActiveThreadId] = useQueryState(
760
761
  "threadId",
761
762
  parseAsString
@@ -772,17 +773,24 @@ var ThreadProvider = ({
772
773
  const {
773
774
  data: threads = [],
774
775
  isLoading,
776
+ isFetched: isFetchedThreads,
775
777
  error: threadsError,
776
778
  refetch: refreshThreads
777
779
  } = useQuery({
778
780
  queryKey: ["threads"],
779
781
  queryFn: () => service.getThreads(),
780
- staleTime: !prevActiveThreadIdRef.current && activeThreadId ? Infinity : 0
782
+ staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
781
783
  });
784
+ const isNewThread = useMemo(() => {
785
+ if (!activeThreadId || !isFetchedThreads) return false;
786
+ return !threads.some((t) => t.id === activeThreadId);
787
+ }, [activeThreadId, threads, isFetchedThreads]);
782
788
  const { data: threadEvents = [], isLoading: isLoadingEvents } = useQuery({
783
789
  queryKey: ["threads", activeThreadId, "events"],
784
790
  queryFn: () => service.getEvents(activeThreadId),
785
- enabled: !!activeThreadId
791
+ enabled: !!activeThreadId,
792
+ initialData: isNewThread ? melonyContext?.events : void 0,
793
+ staleTime: isNewThread ? Infinity : 0
786
794
  });
787
795
  const createMutation = useMutation({
788
796
  mutationFn: async () => {