Revert "Upgrade linter and formatter to Ultracite" (#1226)

This commit is contained in:
josh 2025-09-21 12:03:29 +01:00 committed by GitHub
parent 0e320b391d
commit 1aff7d9868
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 8334 additions and 6943 deletions

View file

@ -1,15 +1,15 @@
"use client";
'use client';
import { useCallback, useMemo } from "react";
import useSWR from "swr";
import type { UIArtifact } from "@/components/artifact";
import useSWR from 'swr';
import type { UIArtifact } from '@/components/artifact';
import { useCallback, useMemo } from 'react';
export const initialArtifactData: UIArtifact = {
documentId: "init",
content: "",
kind: "text",
title: "",
status: "idle",
documentId: 'init',
content: '',
kind: 'text',
title: '',
status: 'idle',
isVisible: false,
boundingBox: {
top: 0,
@ -22,14 +22,12 @@ export const initialArtifactData: UIArtifact = {
type Selector<T> = (state: UIArtifact) => T;
export function useArtifactSelector<Selected>(selector: Selector<Selected>) {
const { data: localArtifact } = useSWR<UIArtifact>("artifact", null, {
const { data: localArtifact } = useSWR<UIArtifact>('artifact', null, {
fallbackData: initialArtifactData,
});
const selectedValue = useMemo(() => {
if (!localArtifact) {
return selector(initialArtifactData);
}
if (!localArtifact) return selector(initialArtifactData);
return selector(localArtifact);
}, [localArtifact, selector]);
@ -38,17 +36,15 @@ export function useArtifactSelector<Selected>(selector: Selector<Selected>) {
export function useArtifact() {
const { data: localArtifact, mutate: setLocalArtifact } = useSWR<UIArtifact>(
"artifact",
'artifact',
null,
{
fallbackData: initialArtifactData,
}
},
);
const artifact = useMemo(() => {
if (!localArtifact) {
return initialArtifactData;
}
if (!localArtifact) return initialArtifactData;
return localArtifact;
}, [localArtifact]);
@ -57,14 +53,14 @@ export function useArtifact() {
setLocalArtifact((currentArtifact) => {
const artifactToUpdate = currentArtifact || initialArtifactData;
if (typeof updaterFn === "function") {
if (typeof updaterFn === 'function') {
return updaterFn(artifactToUpdate);
}
return updaterFn;
});
},
[setLocalArtifact]
[setLocalArtifact],
);
const { data: localArtifactMetadata, mutate: setLocalArtifactMetadata } =
@ -74,7 +70,7 @@ export function useArtifact() {
null,
{
fallbackData: null,
}
},
);
return useMemo(
@ -84,6 +80,6 @@ export function useArtifact() {
metadata: localArtifactMetadata,
setMetadata: setLocalArtifactMetadata,
}),
[artifact, setArtifact, localArtifactMetadata, setLocalArtifactMetadata]
[artifact, setArtifact, localArtifactMetadata, setLocalArtifactMetadata],
);
}

View file

@ -1,16 +1,16 @@
"use client";
'use client';
import type { UseChatHelpers } from "@ai-sdk/react";
import { useEffect } from "react";
import { useDataStream } from "@/components/data-stream-provider";
import type { ChatMessage } from "@/lib/types";
import { useEffect } from 'react';
import type { UseChatHelpers } from '@ai-sdk/react';
import type { ChatMessage } from '@/lib/types';
import { useDataStream } from '@/components/data-stream-provider';
export type UseAutoResumeParams = {
export interface UseAutoResumeParams {
autoResume: boolean;
initialMessages: ChatMessage[];
resumeStream: UseChatHelpers<ChatMessage>["resumeStream"];
setMessages: UseChatHelpers<ChatMessage>["setMessages"];
};
resumeStream: UseChatHelpers<ChatMessage>['resumeStream'];
setMessages: UseChatHelpers<ChatMessage>['setMessages'];
}
export function useAutoResume({
autoResume,
@ -21,31 +21,25 @@ export function useAutoResume({
const { dataStream } = useDataStream();
useEffect(() => {
if (!autoResume) {
return;
}
if (!autoResume) return;
const mostRecentMessage = initialMessages.at(-1);
if (mostRecentMessage?.role === "user") {
if (mostRecentMessage?.role === 'user') {
resumeStream();
}
// we intentionally run this once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoResume, initialMessages.at, resumeStream]);
}, []);
useEffect(() => {
if (!dataStream) {
return;
}
if (dataStream.length === 0) {
return;
}
if (!dataStream) return;
if (dataStream.length === 0) return;
const dataPart = dataStream[0];
if (dataPart.type === "data-appendMessage") {
if (dataPart.type === 'data-appendMessage') {
const message = JSON.parse(dataPart.data);
setMessages([...initialMessages, message]);
}

View file

@ -1,14 +1,14 @@
"use client";
'use client';
import { useMemo } from "react";
import useSWR, { useSWRConfig } from "swr";
import { unstable_serialize } from "swr/infinite";
import { updateChatVisibility } from "@/app/(chat)/actions";
import { useMemo } from 'react';
import useSWR, { useSWRConfig } from 'swr';
import { unstable_serialize } from 'swr/infinite';
import { updateChatVisibility } from '@/app/(chat)/actions';
import {
type ChatHistory,
getChatHistoryPaginationKey,
} from "@/components/sidebar-history";
import type { VisibilityType } from "@/components/visibility-selector";
type ChatHistory,
} from '@/components/sidebar-history';
import type { VisibilityType } from '@/components/visibility-selector';
export function useChatVisibility({
chatId,
@ -18,24 +18,20 @@ export function useChatVisibility({
initialVisibilityType: VisibilityType;
}) {
const { mutate, cache } = useSWRConfig();
const history: ChatHistory = cache.get("/api/history")?.data;
const history: ChatHistory = cache.get('/api/history')?.data;
const { data: localVisibility, mutate: setLocalVisibility } = useSWR(
`${chatId}-visibility`,
null,
{
fallbackData: initialVisibilityType,
}
},
);
const visibilityType = useMemo(() => {
if (!history) {
return localVisibility;
}
const chat = history.chats.find((currentChat) => currentChat.id === chatId);
if (!chat) {
return "private";
}
if (!history) return localVisibility;
const chat = history.chats.find((chat) => chat.id === chatId);
if (!chat) return 'private';
return chat.visibility;
}, [history, chatId, localVisibility]);
@ -44,7 +40,7 @@ export function useChatVisibility({
mutate(unstable_serialize(getChatHistoryPaginationKey));
updateChatVisibility({
chatId,
chatId: chatId,
visibility: updatedVisibilityType,
});
};

View file

@ -1,12 +1,14 @@
import type { UseChatHelpers } from "@ai-sdk/react";
import { useEffect, useState } from "react";
import type { ChatMessage } from "@/lib/types";
import { useScrollToBottom } from "./use-scroll-to-bottom";
import { useState, useEffect } from 'react';
import { useScrollToBottom } from './use-scroll-to-bottom';
import type { UseChatHelpers } from '@ai-sdk/react';
import type { ChatMessage } from '@/lib/types';
export function useMessages({
chatId,
status,
}: {
status: UseChatHelpers<ChatMessage>["status"];
chatId: string;
status: UseChatHelpers<ChatMessage>['status'];
}) {
const {
containerRef,
@ -20,7 +22,7 @@ export function useMessages({
const [hasSentMessage, setHasSentMessage] = useState(false);
useEffect(() => {
if (status === "submitted") {
if (status === 'submitted') {
setHasSentMessage(true);
}
}, [status]);

View file

@ -1,19 +0,0 @@
import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
}
mql.addEventListener("change", onChange)
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
return () => mql.removeEventListener("change", onChange)
}, [])
return !!isMobile
}

21
hooks/use-mobile.tsx Normal file
View file

@ -0,0 +1,21 @@
import * as React from 'react';
const MOBILE_BREAKPOINT = 768;
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
undefined,
);
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
};
mql.addEventListener('change', onChange);
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
return () => mql.removeEventListener('change', onChange);
}, []);
return !!isMobile;
}

View file

@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from "react";
import useSWR from "swr";
import useSWR from 'swr';
import { useRef, useEffect, useCallback, useState } from 'react';
type ScrollFlag = ScrollBehavior | false;
@ -9,25 +9,21 @@ export function useScrollToBottom() {
const [isAtBottom, setIsAtBottom] = useState(true);
const { data: scrollBehavior = false, mutate: setScrollBehavior } =
useSWR<ScrollFlag>("messages:should-scroll", null, { fallbackData: false });
useSWR<ScrollFlag>('messages:should-scroll', null, { fallbackData: false });
const handleScroll = useCallback(() => {
if (!containerRef.current) {
return;
}
if (!containerRef.current) return;
const { scrollTop, scrollHeight, clientHeight } = containerRef.current;
// Check if we are within 100px of the bottom (like v0 does)
setIsAtBottom(scrollTop + clientHeight >= scrollHeight - 100);
}, []);
}, []);
useEffect(() => {
if (!containerRef.current) {
return;
}
if (!containerRef.current) return;
const container = containerRef.current;
const resizeObserver = new ResizeObserver(() => {
requestAnimationFrame(() => {
handleScroll();
@ -47,7 +43,7 @@ export function useScrollToBottom() {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["style", "class", "data-state"],
attributeFilter: ['style', 'class', 'data-state']
});
handleScroll();
@ -60,15 +56,13 @@ export function useScrollToBottom() {
useEffect(() => {
const container = containerRef.current;
if (!container) {
return;
}
if (!container) return;
container.addEventListener("scroll", handleScroll);
container.addEventListener('scroll', handleScroll);
handleScroll(); // Check initial state
return () => {
container.removeEventListener("scroll", handleScroll);
container.removeEventListener('scroll', handleScroll);
};
}, [handleScroll]);
@ -85,10 +79,10 @@ export function useScrollToBottom() {
}, [scrollBehavior, setScrollBehavior]);
const scrollToBottom = useCallback(
(currentScrollBehavior: ScrollBehavior = "smooth") => {
setScrollBehavior(currentScrollBehavior);
(scrollBehavior: ScrollBehavior = 'smooth') => {
setScrollBehavior(scrollBehavior);
},
[setScrollBehavior]
[setScrollBehavior],
);
function onViewportEnter() {