Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/components/artifacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type HTMLPreviewProps = {
onLoad?: (title?: string) => void;
};

export type HTMLPreviewHander = {
export type HTMLPreviewHandler = {
reload: () => void;
};

export const HTMLPreview = forwardRef<HTMLPreviewHander, HTMLPreviewProps>(
export const HTMLPreview = forwardRef<HTMLPreviewHandler, HTMLPreviewProps>(
function HTMLPreview(props, ref) {
const iframeRef = useRef<HTMLIFrameElement>(null);
const [frameId, setFrameId] = useState<string>(nanoid());
Expand Down Expand Up @@ -207,7 +207,7 @@ export function Artifacts() {
const [code, setCode] = useState("");
const [loading, setLoading] = useState(true);
const [fileName, setFileName] = useState("");
const previewRef = useRef<HTMLPreviewHander>(null);
const previewRef = useRef<HTMLPreviewHandler>(null);

Comment on lines +210 to 211
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Same useRef nullability issue here.

-const previewRef = useRef<HTMLPreviewHandler>(null);
+const previewRef = useRef<HTMLPreviewHandler | null>(null);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const previewRef = useRef<HTMLPreviewHandler>(null);
const previewRef = useRef<HTMLPreviewHandler | null>(null);
🤖 Prompt for AI Agents
In app/components/artifacts.tsx around lines 210 to 211, the useRef hook is
initialized with null but the type does not explicitly allow null, causing a
nullability issue. Update the type parameter of useRef to include null, for
example useRef<HTMLPreviewHandler | null>(null), to correctly reflect that the
ref can be null initially.

useEffect(() => {
if (id) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { showImageModal, FullScreen } from "./ui-lib";
import {
ArtifactsShareButton,
HTMLPreview,
HTMLPreviewHander,
HTMLPreviewHandler,
} from "./artifacts";
import { useChatStore } from "../store";
import { IconButton } from "./button";
Expand Down Expand Up @@ -73,7 +73,7 @@ export function Mermaid(props: { code: string }) {

export function PreCode(props: { children: any }) {
const ref = useRef<HTMLPreElement>(null);
const previewRef = useRef<HTMLPreviewHander>(null);
const previewRef = useRef<HTMLPreviewHandler>(null);
const [mermaidCode, setMermaidCode] = useState("");
Comment on lines 75 to 77
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

useRef generic should include null to satisfy strict null-checks.

With strictNullChecks enabled, null isn’t assignable to HTMLPreviewHandler.
Adjust the generic so the initial value type matches.

-const previewRef = useRef<HTMLPreviewHandler>(null);
+const previewRef = useRef<HTMLPreviewHandler | null>(null);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const ref = useRef<HTMLPreElement>(null);
const previewRef = useRef<HTMLPreviewHander>(null);
const previewRef = useRef<HTMLPreviewHandler>(null);
const [mermaidCode, setMermaidCode] = useState("");
const ref = useRef<HTMLPreElement>(null);
- const previewRef = useRef<HTMLPreviewHandler>(null);
+ const previewRef = useRef<HTMLPreviewHandler | null>(null);
const [mermaidCode, setMermaidCode] = useState("");
🤖 Prompt for AI Agents
In app/components/markdown.tsx around lines 75 to 77, the useRef generic type
for previewRef is currently HTMLPreviewHandler but does not include null, which
causes issues with strictNullChecks. Update the generic type to
HTMLPreviewHandler | null to match the initial null value and satisfy
TypeScript's strict null checking.

const [htmlCode, setHtmlCode] = useState("");
const { height } = useWindowSize();
Expand Down
Loading