Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/components/CircuitJsonPreview/CircuitJsonPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type { CircuitJsonError } from "circuit-json"
import { version } from "../../../package.json"
import type { Object3D } from "three"
import { useEvalVersions } from "lib/hooks/use-eval-versions"
import { FileMenuLeftHeader } from "../FileMenuLeftHeader"
import { FileMenuLeftHeaderWithBugReport } from "../FileMenuLeftHeaderWithBugReport"

declare global {
interface Window {
Expand Down Expand Up @@ -213,7 +213,7 @@ export const CircuitJsonPreview = ({
>
{leftHeaderContent}
{showFileMenu && !leftHeaderContent && (
<FileMenuLeftHeader
<FileMenuLeftHeaderWithBugReport
isWebEmbedded={isWebEmbedded}
circuitJson={circuitJson}
projectName={projectName}
Expand Down
9 changes: 3 additions & 6 deletions lib/components/FileMenuLeftHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import { toast } from "lib/utils/toast"
import { Toaster } from "react-hot-toast"
import { useOrderDialogCli } from "./OrderDialog/useOrderDialog"
import packageJson from "../../package.json"
import { useBugReportDialog } from "./useBugReportDialog"

export const FileMenuLeftHeader = (props: {
isWebEmbedded?: boolean
shouldLoadLatestEval?: boolean
onChangeShouldLoadLatestEval?: (shouldLoadLatestEval: boolean) => void
circuitJson?: any
projectName?: string
openBugReportDialog?: () => void
}) => {
const lastRunEvalVersion = useRunnerStore((s) => s.lastRunEvalVersion)
const currentMainComponentPath = useRunFrameStore(
Expand Down Expand Up @@ -156,8 +156,6 @@ export const FileMenuLeftHeader = (props: {
const [isImportDialogOpen, setIsImportDialogOpen] = useState(false)
const [isAiReviewDialogOpen, setIsAiReviewDialogOpen] = useState(false)

const { BugReportDialog, openBugReportDialog } = useBugReportDialog()

return (
<>
<DropdownMenu>
Expand Down Expand Up @@ -213,11 +211,11 @@ export const FileMenuLeftHeader = (props: {
</>
)}

{!props.isWebEmbedded && (
{!props.isWebEmbedded && props.openBugReportDialog && (
<DropdownMenuItem
className="rf-text-xs"
onSelect={() => {
openBugReportDialog()
props.openBugReportDialog?.()
}}
>
Report Bug
Expand Down Expand Up @@ -356,7 +354,6 @@ export const FileMenuLeftHeader = (props: {
isOpen={isSelectSnippetDialogOpen}
/>
</DropdownMenu>
<BugReportDialog />
<ImportComponentDialogForCli
isOpen={isImportDialogOpen}
onClose={() => setIsImportDialogOpen(false)}
Expand Down
31 changes: 31 additions & 0 deletions lib/components/FileMenuLeftHeaderWithBugReport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { memo } from "react"
import { FileMenuLeftHeader } from "./FileMenuLeftHeader"
import { useBugReportDialog } from "./useBugReportDialog"

/**
* Wrapper component that manages bug report dialog state separately
* from FileMenuLeftHeader to prevent unnecessary re-renders
*/
const FileMenuLeftHeaderWithBugReportComponent = (props: {
isWebEmbedded?: boolean
shouldLoadLatestEval?: boolean
onChangeShouldLoadLatestEval?: (shouldLoadLatestEval: boolean) => void
circuitJson?: any
projectName?: string
}) => {
const { BugReportDialog, openBugReportDialog } = useBugReportDialog()

return (
<>
<FileMenuLeftHeader
{...props}
openBugReportDialog={openBugReportDialog}
/>
{BugReportDialog}
</>
)
}

export const FileMenuLeftHeaderWithBugReport = memo(
FileMenuLeftHeaderWithBugReportComponent,
)
6 changes: 4 additions & 2 deletions lib/components/RunFrame/RunFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useRunnerStore } from "./runner-store/use-runner-store"
import { useMutex } from "./useMutex"
import type { ManualEditEvent } from "@tscircuit/props"
import { registryKy } from "../../utils/get-registry-ky"
import { FileMenuLeftHeader } from "../FileMenuLeftHeader"
import { FileMenuLeftHeaderWithBugReport } from "../FileMenuLeftHeaderWithBugReport"
import { LoadingSkeleton } from "../ui/LoadingSkeleton"
import { useStyles } from "../../hooks/use-styles"
import { API_BASE } from "../RunFrameWithApi/api-base"
Expand Down Expand Up @@ -585,7 +585,9 @@ export const RunFrame = (props: RunFrameProps) => {
</div>
)}
{props.showFileMenu !== false && (
<FileMenuLeftHeader isWebEmbedded={props.isWebEmbedded} />
<FileMenuLeftHeaderWithBugReport
isWebEmbedded={props.isWebEmbedded}
/>
)}
{props.leftHeaderContent}
</>
Expand Down
4 changes: 2 additions & 2 deletions lib/components/RunFrameForCli/RunFrameForCli.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocalStorageState } from "lib/hooks/use-local-storage-state"
import { useCallback, useState } from "react"
import { RunFrameWithApi } from "../RunFrameWithApi/RunFrameWithApi"
import { FileMenuLeftHeader } from "../FileMenuLeftHeader"
import { FileMenuLeftHeaderWithBugReport } from "../FileMenuLeftHeaderWithBugReport"

export const RunFrameForCli = (props: {
debug?: boolean
Expand Down Expand Up @@ -45,7 +45,7 @@ export const RunFrameForCli = (props: {
onMainComponentPathChange={updateMainComponentHash}
leftHeaderContent={
<div className="rf-flex rf-items-center rf-justify-between">
<FileMenuLeftHeader
<FileMenuLeftHeaderWithBugReport
isWebEmbedded={false}
shouldLoadLatestEval={!props.workerBlobUrl && shouldLoadLatestEval}
onChangeShouldLoadLatestEval={(newShouldLoadLatestEval) => {
Expand Down
18 changes: 10 additions & 8 deletions lib/components/useBugReportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare global {
}

type UseBugReportDialogResult = {
BugReportDialog: () => ReactElement
BugReportDialog: ReactElement
openBugReportDialog: () => void
}

Expand Down Expand Up @@ -208,11 +208,12 @@ export const useBugReportDialog = (): UseBugReportDialogResult => {
} finally {
setIsSubmitting(false)
}
}, [userText])
}, [])

const BugReportDialog = useCallback(() => {
const BugReportDialog = useMemo(() => {
return (
<AlertDialog
key="bug-report-dialog"
open={isOpen}
onOpenChange={(open) => {
if (!open) {
Expand Down Expand Up @@ -278,6 +279,7 @@ export const useBugReportDialog = (): UseBugReportDialogResult => {
Description (optional)
</label>
<textarea
key="bug-description-textarea"
id="bug-description"
className="rf-w-full rf-min-h-[100px] rf-px-3 rf-py-2 rf-text-sm rf-border rf-border-gray-300 rf-rounded-md focus:rf-outline-none focus:rf-ring-2 focus:rf-ring-blue-500"
placeholder="Describe the issue you're experiencing..."
Expand Down Expand Up @@ -357,15 +359,15 @@ export const useBugReportDialog = (): UseBugReportDialogResult => {
</AlertDialog>
)
}, [
bugReportFileCount,
closeBugReportDialog,
errorMessage,
handleConfirmBugReport,
isOpen,
isSessionLoggedIn,
isSubmitting,
closeBugReportDialog,
errorMessage,
successState,
bugReportFileCount,
userText,
isSessionLoggedIn,
handleConfirmBugReport,
])

return {
Expand Down
Loading