Skip to content

feat: add SignalR reconnect provider#5153

Open
MishaliaPillay wants to merge 1 commit into
shesha-io:mainfrom
MishaliaPillay:mishalia/feat/reconnect-signalR-main
Open

feat: add SignalR reconnect provider#5153
MishaliaPillay wants to merge 1 commit into
shesha-io:mainfrom
MishaliaPillay:mishalia/feat/reconnect-signalR-main

Conversation

@MishaliaPillay

@MishaliaPillay MishaliaPillay commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added SignalR connectivity support for real-time application updates.
    • Added configurable connection URLs, connection and disconnection callbacks, and automatic reconnection.
    • Added hooks for accessing SignalR connection state and actions within React components.
    • Improved connection lifecycle handling during startup, reconnection, and shutdown.

@MishaliaPillay MishaliaPillay self-assigned this Jul 14, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a React SignalRProvider that creates and manages a SignalR hub connection, supports automatic reconnect callbacks, exposes connection state and actions through context, and provides hooks for consuming them.

Changes

SignalR provider

Layer / File(s) Summary
Connection lifecycle and reconnect handling
shesha-reactjs/src/providers/signalR/index.tsx
Defines provider options, builds and starts the SignalR connection, handles reconnect and disconnect events, and guards asynchronous cleanup.
Context access and public exports
shesha-reactjs/src/providers/signalR/index.tsx
Publishes state and actions through contexts, adds required or optional hooks, and exports the provider and hooks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: ivanilyichev

Poem

A rabbit hops where SignalR flows,
A hub connects, then onward goes.
Reconnect bells ring clear and bright,
Context shares the state just right.
Hooks gather data, soft as dew—
“The provider’s ready!” says the bunny crew.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a SignalR provider with reconnect support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 12

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shesha-reactjs/src/providers/signalR/index.tsx`:
- Around line 38-40: Update the setConnection helper in the SignalR provider to
use useCallback with stable dependencies, or remove it and dispatch
setConnectionAction directly inside the connection-establishing useEffect;
ensure the effect’s dependency handling does not recreate the SignalR connection
on every render.
- Around line 38-40: Memoize the setConnection callback with useCallback so its
identity remains stable when referenced by the useEffect dependency array.
Preserve its existing dispatch(setConnectionAction(connection)) behavior and
include the appropriate dispatch dependency.
- Around line 38-40: Memoize the setConnection callback with React’s
useCallback, adding useCallback to the existing react imports and preserving its
dispatch behavior. Then include the stable setConnection reference in the
useEffect dependency array to satisfy exhaustive-deps without recreating the
SignalR connection on every render.
- Around line 38-40: Memoize the setConnection callback with React’s useCallback
and include the resulting stable callback in the relevant useEffect dependency
array. Update the React imports accordingly, preserving the existing
dispatch(setConnectionAction(connection)) behavior and preventing repeated
SignalR connection teardown and rebuilding.
- Around line 125-143: Set the require parameter default to true in both
useSignalRState and useSignalRActions, preserving their existing context
validation and return behavior while allowing callers to omit the argument.
- Around line 125-143: Set the require parameter default to true in both
useSignalRState and useSignalRActions, preserving their existing context
validation and return behavior while allowing callers to omit the argument.
- Around line 87-94: Update the startup completion handler in the SignalR
connection effect so that when `isActive` is false, it asynchronously invokes
`connection.stop()` before returning. Preserve the existing state update and
`onConnectedRef` callback only for active effects, and ensure the
cleanup/startup flow handles the stop promise without leaving an unhandled
rejection.
- Around line 87-94: Update the connection.start() completion handler in the
then callback to call connection.stop() and return when isActive is false,
before setConnection or onConnectedRef. Preserve the existing state publication
for active effects, ensuring a connection that finishes starting after unmount
is stopped rather than left open.
- Line 3: Update the React import in the SignalR provider to include
useCallback, so the provider can memoize its callback logic as required.
- Around line 80-83: Update the SignalR connection onclose handler to call
setConnection(undefined) when the connection is permanently closed, alongside
the existing onDisconnectedRef callback, so consumers no longer receive a stale
connection object.
- Around line 80-83: Update the SignalR connection.onclose handler to call
setConnection(undefined) when the connection is permanently closed, while
preserving the existing error logging and onDisconnectedRef callback.
- Around line 80-83: Update the SignalR connection.onclose handler to clear the
provider’s connection state by calling setConnection(undefined) before or
alongside onDisconnectedRef.current?.(), while preserving the existing close
logging and callback behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5715d283-0da0-4f41-8043-c7fd37a0f164

📥 Commits

Reviewing files that changed from the base of the PR and between 19e1270 and 3d4eb78.

📒 Files selected for processing (1)
  • shesha-reactjs/src/providers/signalR/index.tsx

@@ -0,0 +1,159 @@
import * as signalR from '@microsoft/signalr';

import React, { PropsWithChildren, useContext, useEffect, useReducer, useRef } from 'react';

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.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Import useCallback for memoization.

📦 Proposed import
-import React, { PropsWithChildren, useContext, useEffect, useReducer, useRef } from 'react';
+import React, { PropsWithChildren, useContext, useEffect, useReducer, useRef, useCallback } from 'react';
📝 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
import React, { PropsWithChildren, useContext, useEffect, useReducer, useRef } from 'react';
import React, { PropsWithChildren, useContext, useEffect, useReducer, useRef, useCallback } from 'react';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` at line 3, Update the React
import in the SignalR provider to include useCallback, so the provider can
memoize its callback logic as required.

Comment on lines +38 to +40
const setConnection = (connection?: ISignalRConnection) => {
dispatch(setConnectionAction(connection));
};

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.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Wrap setConnection in useCallback or call dispatch directly.

setConnection is defined on every render but is used inside the useEffect that establishes the SignalR connection. If your linter enforces exhaustive dependencies, this will trigger a warning for a missing dependency. If you add it to the dependency array without memoizing it, the effect will continuously tear down and rebuild the connection on every render.

Wrap it in useCallback, or simply call dispatch(setConnectionAction(...)) directly within the effect.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 38 - 40, Update
the setConnection helper in the SignalR provider to use useCallback with stable
dependencies, or remove it and dispatch setConnectionAction directly inside the
connection-establishing useEffect; ensure the effect’s dependency handling does
not recreate the SignalR connection on every render.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Memoize setConnection to prevent dependency array warnings or infinite loops.

setConnection is re-created on every render but used inside the useEffect block. If added to the effect's dependency array, it will cause the connection to be continuously torn down and restarted on every render. If omitted, it will trigger an eslint-react-hooks/exhaustive-deps warning.

Wrap it in useCallback or replace its usages by directly calling dispatch(setConnectionAction(...)) inside the effect.

♻️ Proposed fix
-  const setConnection = (connection?: ISignalRConnection) => {
-    dispatch(setConnectionAction(connection));
-  };
+  const setConnection = React.useCallback((connection?: ISignalRConnection) => {
+    dispatch(setConnectionAction(connection));
+  }, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 38 - 40, Memoize
the setConnection callback with useCallback so its identity remains stable when
referenced by the useEffect dependency array. Preserve its existing
dispatch(setConnectionAction(connection)) behavior and include the appropriate
dispatch dependency.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Memoize setConnection to prevent dependency array warnings.

setConnection is re-created on every render but used inside the useEffect block. Omitting it from the dependency array violates eslint-react-hooks/exhaustive-deps, while including it without memoization will cause the connection to be repeatedly torn down and rebuilt on every render.

Wrap it in useCallback (remembering to add it to the imports from react).

♻️ Proposed fix
-  const setConnection = (connection?: ISignalRConnection) => {
+  const setConnection = useCallback((connection?: ISignalRConnection) => {
     dispatch(setConnectionAction(connection));
-  };
+  }, []);
📝 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
const setConnection = (connection?: ISignalRConnection) => {
dispatch(setConnectionAction(connection));
};
const setConnection = useCallback((connection?: ISignalRConnection) => {
dispatch(setConnectionAction(connection));
}, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 38 - 40, Memoize
the setConnection callback with React’s useCallback, adding useCallback to the
existing react imports and preserving its dispatch behavior. Then include the
stable setConnection reference in the useEffect dependency array to satisfy
exhaustive-deps without recreating the SignalR connection on every render.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Memoize setConnection to prevent dependency array warnings.

setConnection is re-created on every render but used inside the useEffect block. Omitting it from the effect's dependency array violates the eslint-react-hooks/exhaustive-deps rule. Alternatively, including it without memoization will cause the connection to be repeatedly torn down and rebuilt on every render.

Wrap it in useCallback (remembering to add it to the imports from react) or replace its usages by directly calling dispatch inside the effect.

♻️ Proposed fix
-  const setConnection = (connection?: ISignalRConnection) => {
+  const setConnection = useCallback((connection?: ISignalRConnection) => {
     dispatch(setConnectionAction(connection));
-  };
+  }, []);
📝 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
const setConnection = (connection?: ISignalRConnection) => {
dispatch(setConnectionAction(connection));
};
const setConnection = useCallback((connection?: ISignalRConnection) => {
dispatch(setConnectionAction(connection));
}, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 38 - 40, Memoize
the setConnection callback with React’s useCallback and include the resulting
stable callback in the relevant useEffect dependency array. Update the React
imports accordingly, preserving the existing
dispatch(setConnectionAction(connection)) behavior and preventing repeated
SignalR connection teardown and rebuilding.

Comment on lines +80 to +83
connection.onclose((error) => {
console.error('SignalR connection closed', error);
onDisconnectedRef.current?.();
});

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear the connection from state when it is permanently closed.

The onclose event fires when the connection is permanently lost (e.g., if the server disconnects or all automatic reconnect attempts fail). Currently, it invokes the onDisconnected callback but leaves the stale connection object in the context state. Components relying on the provider will still see a connection and might attempt to invoke methods on it, resulting in runtime errors.

Call setConnection(undefined) within the onclose handler to ensure the context accurately reflects that there is no active connection.

🧹 Proposed fix
     connection.onclose((error) => {
       console.error('SignalR connection closed', error);
+      setConnection();
       onDisconnectedRef.current?.();
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 80 - 83, Update
the SignalR connection onclose handler to call setConnection(undefined) when the
connection is permanently closed, alongside the existing onDisconnectedRef
callback, so consumers no longer receive a stale connection object.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear the connection from state when it is permanently closed.

The onclose event fires when the connection is permanently lost (e.g., if the server disconnects or all automatic reconnect attempts fail). Currently, it invokes the onDisconnected callback but leaves the stale connection object in the context state. Components relying on the provider will still see a connection and might attempt to invoke methods on it, resulting in runtime errors.

Call setConnection(undefined) within the onclose handler to ensure the context accurately reflects that there is no active connection.

🧹 Proposed fix
     connection.onclose((error) => {
       console.error('SignalR connection closed', error);
+      setConnection();
       onDisconnectedRef.current?.();
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 80 - 83, Update
the SignalR connection.onclose handler to call setConnection(undefined) when the
connection is permanently closed, while preserving the existing error logging
and onDisconnectedRef callback.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear the connection from state when it permanently closes.

The onclose event fires when the connection is permanently lost (or if all automatic reconnect attempts fail). Currently, it invokes the onDisconnected callback but leaves the disconnected connection object in the context state. Components relying on the provider will still see a connection and might attempt to invoke methods on it, resulting in errors.

Call setConnection(undefined) (or setConnection()) within onclose to ensure the context accurately reflects the disconnected state.

🧹 Proposed fix
     connection.onclose((error) => {
       console.error('SignalR connection closed', error);
+      setConnection();
       onDisconnectedRef.current?.();
     });
📝 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
connection.onclose((error) => {
console.error('SignalR connection closed', error);
onDisconnectedRef.current?.();
});
connection.onclose((error) => {
console.error('SignalR connection closed', error);
setConnection();
onDisconnectedRef.current?.();
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 80 - 83, Update
the SignalR connection.onclose handler to clear the provider’s connection state
by calling setConnection(undefined) before or alongside
onDisconnectedRef.current?.(), while preserving the existing close logging and
callback behavior.

Comment on lines +87 to +94
.then(() => {
// Only expose the connection once it has actually started successfully,
// and only if this effect instance is still active.
if (!isActive) return;
setConnection(connection);
onConnectedRef.current?.(connection);
})
.catch((err) => console.error('SignalR start failed:', err));

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.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent SignalR connection leaks when the component unmounts during startup.

If the component unmounts while connection.start() is still pending, the synchronous stop() call in the cleanup function will fail because SignalR throws an error if you attempt to stop a connection in the Connecting state. When start() eventually completes, the !isActive guard prevents it from being saved to state, but the connection remains permanently open in the background.

To prevent this resource leak, explicitly invoke connection.stop() inside the .then() block if the effect is no longer active.

🔌 Proposed fix
     connection
       .start()
       .then(() => {
         // Only expose the connection once it has actually started successfully,
         // and only if this effect instance is still active.
-        if (!isActive) return;
+        if (!isActive) {
+          connection.stop().catch((err) => console.error('SignalR stop on unmount failed:', err));
+          return;
+        }
         setConnection(connection);
         onConnectedRef.current?.(connection);
       })
📝 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
.then(() => {
// Only expose the connection once it has actually started successfully,
// and only if this effect instance is still active.
if (!isActive) return;
setConnection(connection);
onConnectedRef.current?.(connection);
})
.catch((err) => console.error('SignalR start failed:', err));
.then(() => {
// Only expose the connection once it has actually started successfully,
// and only if this effect instance is still active.
if (!isActive) {
connection.stop().catch((err) => console.error('SignalR stop on unmount failed:', err));
return;
}
setConnection(connection);
onConnectedRef.current?.(connection);
})
.catch((err) => console.error('SignalR start failed:', err));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 87 - 94, Update
the startup completion handler in the SignalR connection effect so that when
`isActive` is false, it asynchronously invokes `connection.stop()` before
returning. Preserve the existing state update and `onConnectedRef` callback only
for active effects, and ensure the cleanup/startup flow handles the stop promise
without leaving an unhandled rejection.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent SignalR connection leaks when the component unmounts during startup.

If the component unmounts while connection.start() is still pending, the synchronous stop() call in the cleanup function will fail because SignalR throws an error if you attempt to stop a connection in the Connecting state. When start() eventually completes, the !isActive guard prevents it from being saved to state, but the connection remains permanently open in the background.

To prevent this resource leak, invoke connection.stop() inside the .then() block if the effect is no longer active.

🔌 Proposed fix
     connection
       .start()
       .then(() => {
         // Only expose the connection once it has actually started successfully,
         // and only if this effect instance is still active.
-        if (!isActive) return;
+        if (!isActive) {
+          connection.stop().catch((err) => console.error('SignalR stop on unmount failed:', err));
+          return;
+        }
         setConnection(connection);
         onConnectedRef.current?.(connection);
       })
📝 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
.then(() => {
// Only expose the connection once it has actually started successfully,
// and only if this effect instance is still active.
if (!isActive) return;
setConnection(connection);
onConnectedRef.current?.(connection);
})
.catch((err) => console.error('SignalR start failed:', err));
.then(() => {
// Only expose the connection once it has actually started successfully,
// and only if this effect instance is still active.
if (!isActive) {
connection.stop().catch((err) => console.error('SignalR stop on unmount failed:', err));
return;
}
setConnection(connection);
onConnectedRef.current?.(connection);
})
.catch((err) => console.error('SignalR start failed:', err));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 87 - 94, Update
the connection.start() completion handler in the then callback to call
connection.stop() and return when isActive is false, before setConnection or
onConnectedRef. Preserve the existing state publication for active effects,
ensuring a connection that finishes starting after unmount is stopped rather
than left open.

Comment on lines +125 to +143
function useSignalRState(require: boolean) {
const context = useContext(SignalRStateContext);

if (context === undefined && require) {
throw new Error('useSignalRState must be used within a SignalRProvider');
}

return context;
}

function useSignalRActions(require: boolean) {
const context = useContext(SignalRActionsContext);

if (context === undefined && require) {
throw new Error('useSignalRActions must be used within a SignalRProvider');
}

return context;
}

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.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Set a default value for the require parameter.

For consistency with useSignalR and to improve developer ergonomics, provide a default value of true for the require parameter in both useSignalRState and useSignalRActions. This prevents TypeScript errors when consumers call these hooks without arguments.

🛠 Proposed fix
-function useSignalRState(require: boolean) {
+function useSignalRState(require: boolean = true) {
   const context = useContext(SignalRStateContext);
 
   if (context === undefined && require) {
     throw new Error('useSignalRState must be used within a SignalRProvider');
   }
 
   return context;
 }
 
-function useSignalRActions(require: boolean) {
+function useSignalRActions(require: boolean = true) {
📝 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
function useSignalRState(require: boolean) {
const context = useContext(SignalRStateContext);
if (context === undefined && require) {
throw new Error('useSignalRState must be used within a SignalRProvider');
}
return context;
}
function useSignalRActions(require: boolean) {
const context = useContext(SignalRActionsContext);
if (context === undefined && require) {
throw new Error('useSignalRActions must be used within a SignalRProvider');
}
return context;
}
function useSignalRState(require: boolean = true) {
const context = useContext(SignalRStateContext);
if (context === undefined && require) {
throw new Error('useSignalRState must be used within a SignalRProvider');
}
return context;
}
function useSignalRActions(require: boolean = true) {
const context = useContext(SignalRActionsContext);
if (context === undefined && require) {
throw new Error('useSignalRActions must be used within a SignalRProvider');
}
return context;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 125 - 143, Set
the require parameter default to true in both useSignalRState and
useSignalRActions, preserving their existing context validation and return
behavior while allowing callers to omit the argument.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Set a default value for the require parameter.

For consistency with useSignalR and to improve developer ergonomics, provide a default value of true for the require parameter in both useSignalRState and useSignalRActions. This prevents TypeScript errors when consumers call these hooks without arguments.

🛠 Proposed fix
-function useSignalRState(require: boolean) {
+function useSignalRState(require: boolean = true) {
   const context = useContext(SignalRStateContext);
 
   if (context === undefined && require) {
     throw new Error('useSignalRState must be used within a SignalRProvider');
   }
 
   return context;
 }
 
-function useSignalRActions(require: boolean) {
+function useSignalRActions(require: boolean = true) {
📝 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
function useSignalRState(require: boolean) {
const context = useContext(SignalRStateContext);
if (context === undefined && require) {
throw new Error('useSignalRState must be used within a SignalRProvider');
}
return context;
}
function useSignalRActions(require: boolean) {
const context = useContext(SignalRActionsContext);
if (context === undefined && require) {
throw new Error('useSignalRActions must be used within a SignalRProvider');
}
return context;
}
function useSignalRState(require: boolean = true) {
const context = useContext(SignalRStateContext);
if (context === undefined && require) {
throw new Error('useSignalRState must be used within a SignalRProvider');
}
return context;
}
function useSignalRActions(require: boolean = true) {
const context = useContext(SignalRActionsContext);
if (context === undefined && require) {
throw new Error('useSignalRActions must be used within a SignalRProvider');
}
return context;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/providers/signalR/index.tsx` around lines 125 - 143, Set
the require parameter default to true in both useSignalRState and
useSignalRActions, preserving their existing context validation and return
behavior while allowing callers to omit the argument.

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.

1 participant