Skip to content

fix: CreateConnection crash — hasDetailsChanged temporal dead zone#65

Merged
abhizipstack merged 1 commit into
mainfrom
fix/create-connection-crash-tdz
Apr 16, 2026
Merged

fix: CreateConnection crash — hasDetailsChanged temporal dead zone#65
abhizipstack merged 1 commit into
mainfrom
fix/create-connection-crash-tdz

Conversation

@abhizipstack
Copy link
Copy Markdown
Contributor

What

Fixed a crash when opening the Create/Edit Connection modal: ReferenceError: Cannot access 'hasDetailsChanged' before initialization.

Why

PR #57 introduced hasDetailsChanged as a useMemo at line 419, but the handleCreateOrUpdate useCallback at line 128 references it in both its body (line 148) and dependency array (line 211). Since const declarations via useMemo aren't hoisted, the useCallback closure captures the variable before it's initialized — JavaScript's temporal dead zone (TDZ) throws a ReferenceError on every render.

How

Moved the hasDetailsChanged useMemo above the handleCreateOrUpdate useCallback that 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 useMemo computation and the useCallback body 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

  1. Navigate to Connections → click Create or Edit on any connection.
  2. Before fix: page crashes with ReferenceError: Cannot access 'hasDetailsChanged' before initialization.
  3. After fix: modal opens normally, create/edit/update all work.

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

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>
@abhizipstack abhizipstack requested a review from a team as a code owner April 16, 2026 14:10
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR fixes a hard crash (ReferenceError: Cannot access 'hasDetailsChanged' before initialization) in the Create/Edit Connection modal by reordering two hook declarations. The hasDetailsChanged useMemo is moved from line ~419 to before the handleCreateOrUpdate useCallback that references it in its dependency array, eliminating the temporal dead zone access at render time. No logic or behavior changes.

Confidence Score: 5/5

Safe to merge — pure declaration-order fix with no logic changes.

The change is a minimal, correct reordering that resolves a hard render crash. No functional logic is altered, dependencies are unchanged, and the fix is well-scoped to a single file. No P0/P1 findings remain.

No files require special attention.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix: CreateConnection crash — hasDetails..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@wicky-zipstack wicky-zipstack left a comment

Choose a reason for hiding this comment

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

LGTM

@abhizipstack abhizipstack merged commit b3e752c into main Apr 16, 2026
8 checks passed
@abhizipstack abhizipstack deleted the fix/create-connection-crash-tdz branch April 16, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants