Skip to content

fix: πŸ› StrictMode socket state and CLI startup crash - #143

Merged
prc5 merged 2 commits into
mainfrom
fix/strict-mode-connected-and-cli-node
Oct 4, 2026
Merged

prc5 merged 2 commits into
mainfrom
fix/strict-mode-connected-and-cli-node

Conversation

@prc5

@prc5 prc5 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Fixes two open issues and adds tests so neither can come back quietly.

StrictMode: `connected` stuck on `false` (closes #140)

StrictMode runs mount, cleanup and mount again. `useSocketState` subscribed to connection events behind a mount-once guard, so the cleanup removed the subscriptions and the guard stopped them from coming back.

  • `useSocketState` now uses a plain effect and syncs `connected` / `connecting` from the socket when it subscribes. This covers `useListener` and `useEmitter`.
  • `useAppManager` and `useSubmit` had the same pattern and the same bug (online/focus never updated, cache updates before the first submit were missed). Fixed as well.

CLI crash on startup (closes #142)

Not specific to Node 24. The CLI was built for the browser, so Vite swapped `fs`, `path` and other builtins for an empty stub. Reproduced with the published 9.0.0.

  • Build now targets Node and prefers CommonJS entries of bundled dependencies.
  • `bin` pointed at the library file instead of the CLI entry, so `npx @hyper-fetch/cli init` would have done nothing once the crash was gone. It now points at `dist/cli.js` under the name `hyper-fetch` (a global install used to expose it as `cli`).
  • `init --help` and `generate --help` failed with "argument missing", and top level `--help` / `--version` opened the command picker. Both work now.

Tests

  • `packages/react/tests/features/strict-mode/`: runs `useSocketState`, `useListener`, `useEmitter`, `useAppManager` and `useSubmit` under StrictMode. 24 of 29 cases failed before the fix.
  • `packages/cli/tests/bundle/bundle.spec.ts`: builds the package and runs the real output with `node` (version, help, a full `init --yes` in a temp project), checks that no builtin is stubbed and that every leftover `require` is installable. Adds about 5 seconds to the CLI test run and needs `@hyper-fetch/core` built first, which CI already does.

Full suites pass locally: react 428, cli 32. Lint and typecheck are clean for both packages.

πŸ€– Generated with Claude Code

prc5 and others added 2 commits October 4, 2026 16:58
… in StrictMode

StrictMode runs mount, cleanup and mount again. Hooks guarded with a
mount-once check lost their subscriptions on the cleanup and never got
them back, so connected from useListener and useEmitter stayed false.

Closes #140

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The bundle was built for the browser, so fs, path and other builtins
were replaced with an empty stub and the cli crashed on startup.
Also fixes the bin entry, --help and --version, and adds a spec that
builds the package and runs the output with node.

Closes #142

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@prc5
prc5 requested a review from GerasNyx as a code owner October 4, 2026 14:58
@prc5
prc5 merged commit 2e22923 into main Oct 4, 2026
4 checks passed
@prc5
prc5 deleted the fix/strict-mode-connected-and-cli-node branch October 4, 2026 18:59
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

πŸŽ‰ This PR is included in version 9.0.1 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI fails on Node.js v24 with TypeError: Cannot read properties of undefined (reading 'native') Connected state issue with StrictMode

1 participant