fix: CreateConnection crash — hasDetailsChanged temporal dead zone#65
Conversation
The useMemo for hasDetailsChanged was declared after the useCallback (handleCreateOrUpdate) that references it in its dependency array. JavaScript's temporal dead zone causes a ReferenceError when the useCallback closure captures the variable before the useMemo initializes it. Moved the useMemo above the useCallback. Introduced by PR #57 (connection name/description edit fix). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
| Filename | Overview |
|---|---|
| frontend/src/base/components/environment/CreateConnection.jsx | Moved hasDetailsChanged useMemo above handleCreateOrUpdate useCallback to fix TDZ ReferenceError on render; no logic changes. |
Sequence Diagram
sequenceDiagram
participant React as React Renderer
participant UC as useCallback(handleCreateOrUpdate)
participant UM as useMemo(hasDetailsChanged)
Note over React: Before fix — render order
React->>UC: evaluate deps array [..., hasDetailsChanged]
UC-->>React: ❌ TDZ ReferenceError (hasDetailsChanged not yet initialized)
Note over UM: hasDetailsChanged declared here (too late)
Note over React: After fix — render order
React->>UM: evaluate hasDetailsChanged
UM-->>React: ✅ returns boolean
React->>UC: evaluate deps array [..., hasDetailsChanged]
UC-->>React: ✅ useCallback registered successfully
Reviews (1): Last reviewed commit: "fix: CreateConnection crash — hasDetails..." | Re-trigger Greptile
What
Fixed a crash when opening the Create/Edit Connection modal:
ReferenceError: Cannot access 'hasDetailsChanged' before initialization.Why
PR #57 introduced
hasDetailsChangedas auseMemoat line 419, but thehandleCreateOrUpdateuseCallbackat line 128 references it in both its body (line 148) and dependency array (line 211). Sinceconstdeclarations viauseMemoaren't hoisted, theuseCallbackclosure captures the variable before it's initialized — JavaScript's temporal dead zone (TDZ) throws aReferenceErroron every render.How
Moved the
hasDetailsChangeduseMemoabove thehandleCreateOrUpdateuseCallbackthat depends on it. No logic changes — just declaration order.Can this PR break any existing features?
No — this is a pure declaration-order fix. The
useMemocomputation and theuseCallbackbody are unchanged. The bug was a hard crash on render, so merging this strictly improves stability.Database Migrations
None.
Env Config
None.
Related Issues or PRs
Dependencies Versions
No changes.
Notes on Testing
ReferenceError: Cannot access 'hasDetailsChanged' before initialization.Checklist
I have read and understood the Contribution Guidelines.
🤖 Generated with Claude Code