Skip to content
Merged
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
35 changes: 15 additions & 20 deletions src/modules/reverse-proxy/table/ReverseProxyStatusCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import useFetchApi from "@utils/api";
import Badge from "@components/Badge";
import { Loader2 } from "lucide-react";
import { useMemo } from "react";
import { useRef } from "react";

type Props = {
serviceId: string;
Expand All @@ -21,38 +21,33 @@ export default function ReverseProxyStatusCell({
meta,
enabled,
}: Readonly<Props>) {
const status = meta?.status;
const certificateIssued = !!meta?.certificate_issued_at;
const dataRef = useRef<ReverseProxy | undefined>(undefined);

const isSettingUp =
enabled &&
status !== undefined &&
status !== ReverseProxyStatus.ACTIVE &&
!certificateIssued;
const isActive =
meta?.status === ReverseProxyStatus.ACTIVE ||
dataRef.current?.meta?.status === ReverseProxyStatus.ACTIVE;

const certificateIssued =
!!meta?.certificate_issued_at ||
!!dataRef.current?.meta?.certificate_issued_at;

const shouldPoll = !!enabled && !certificateIssued;

const { data } = useFetchApi<ReverseProxy>(
`/reverse-proxies/services/${serviceId}`,
true,
false,
isSettingUp,
shouldPoll,
{ refreshInterval: POLL_INTERVAL_MS },
Comment thread
heisbrot marked this conversation as resolved.
Outdated
);

const currentStatus = data?.meta?.status ?? status;

const currentCertificateIssued = useMemo(() => {
if (data && data?.meta) return !!data?.meta?.certificate_issued_at;
return certificateIssued;
}, [data]);
dataRef.current = data;

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 | 🟠 Major

Preserve last known data instead of overwriting ref with undefined

Unconditionally assigning dataRef.current = data can clear cached status when fetching is disabled, which can reintroduce stale UI state on later renders.

🔧 Proposed fix
-  dataRef.current = data;
+  if (data !== undefined) {
+    dataRef.current = data;
+  }
📝 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
dataRef.current = data;
if (data !== undefined) {
dataRef.current = data;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/modules/reverse-proxy/table/ReverseProxyStatusCell.tsx` at line 44, The
code unconditionally assigns dataRef.current = data which can overwrite the
last-known status with undefined when fetching is disabled; change the update to
only overwrite the ref when a real value is present (e.g., check data !==
undefined/null) so dataRef.current retains the previous cached status when data
is undefined; update the assignment used in ReverseProxyStatusCell (the dataRef
and data variables in that component) to guard the write accordingly.


if (
!enabled ||
(currentStatus === ReverseProxyStatus.ACTIVE && currentCertificateIssued)
) {
if (!enabled || (isActive && certificateIssued)) {
return null;
}

if (!currentCertificateIssued) {
if (!certificateIssued) {
return (
<div className={"flex"}>
<Badge variant={"yellow"}>
Expand Down