Skip to content

Commit ac37210

Browse files
committed
fix(logs,kb,tasks): lazy-init useRef for URL param, add cold-path docs to useWorkspaceFileRecord, document key remount requirement in ScheduleModal
1 parent 473cfcc commit ac37210

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

apps/sim/app/workspace/[workspaceId]/logs/logs.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,13 @@ export default function Logs() {
266266
isSidebarOpen: false,
267267
})
268268
const isInitialized = useRef<boolean>(false)
269-
const pendingExecutionIdRef = useRef<string | null>(
270-
typeof window !== 'undefined'
271-
? new URLSearchParams(window.location.search).get('executionId')
272-
: null
273-
)
269+
const pendingExecutionIdRef = useRef<string | null | undefined>(undefined)
270+
if (pendingExecutionIdRef.current === undefined) {
271+
pendingExecutionIdRef.current =
272+
typeof window !== 'undefined'
273+
? new URLSearchParams(window.location.search).get('executionId')
274+
: null
275+
}
274276

275277
const [searchQuery, setSearchQuery] = useState(() => {
276278
if (typeof window === 'undefined') return ''

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/components/create-schedule-modal/schedule-modal.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ function buildCronExpression(
151151
}
152152
}
153153

154+
/**
155+
* Modal for creating and editing scheduled tasks.
156+
*
157+
* All `useState` initializers read from the `schedule` prop at mount time only.
158+
* When editing an existing task, the call-site **must** supply a `key` prop equal to the
159+
* task's ID so React remounts the component when the selected task changes — otherwise
160+
* the form will display stale values from the previously selected task.
161+
*/
154162
export function ScheduleModal({ open, onOpenChange, workspaceId, schedule }: ScheduleModalProps) {
155163
const createScheduleMutation = useCreateSchedule()
156164
const updateScheduleMutation = useUpdateSchedule()

apps/sim/hooks/queries/workspace-files.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export interface StorageInfo {
3535

3636
/**
3737
* Hook to fetch a single workspace file record by ID.
38-
* Uses the same query key as useWorkspaceFiles so the result is served from cache when the list is already loaded.
38+
* Shares the `list(workspaceId, 'active')` query key with {@link useWorkspaceFiles} so no extra
39+
* network request is made when the list is already cached (warm path).
40+
* On a cold path (e.g. direct navigation to a file URL), this fetches the full active file list
41+
* for the workspace and selects the matching record via `select`.
3942
*/
4043
export function useWorkspaceFileRecord(workspaceId: string, fileId: string) {
4144
return useQuery({

0 commit comments

Comments
 (0)