Skip to content

Use notification provider instead or deprecated behaviour#100

Open
klesaulnier wants to merge 10 commits into
mainfrom
use-notification-provider
Open

Use notification provider instead or deprecated behaviour#100
klesaulnier wants to merge 10 commits into
mainfrom
use-notification-provider

Conversation

@klesaulnier
Copy link
Copy Markdown
Contributor

PR Summary

Replace ws.onMessage which was use before by NotificationProvider now used in our other frontends

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Review Change Stack

Warning

Rate limit exceeded

@klesaulnier has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 23 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 983b3cef-6844-4a6f-b4a3-38bda2fa4baf

📥 Commits

Reviewing files that changed from the base of the PR and between 9c53640 and 8bc595c.

📒 Files selected for processing (1)
  • src/shared/api/ws/__tests__/use-notifications-url-generator.test.ts
📝 Walkthrough

Walkthrough

The hook useAppParametersInvalidationListener is relocated to src/app/notifications and rewired to use a NotificationsProvider/url generator; messages parsed by the listener trigger invalidateConfigQueries when headers.parameterName is present. Old WebSocket-based hook and its tests are removed; new tests verify listener and URL generation.

Changes

Notifications-Based Parameter Invalidation

Layer / File(s) Summary
URL Infrastructure & Provider Setup
src/shared/api/ws/use-notifications-url-generator.ts, src/app/providers/AppProviders.tsx, tests, mocks
New hook derives WebSocket URLs with auth tokens from store; NotificationsProvider is introduced to wrap the app with URL mapping; tests and test mocks added.
Core Listener
src/app/notifications/use-app-parameters-invalidation-listener.ts, src/app/__tests__/notifications/use-app-parameters-invalidation-listener.test.ts
Hook registers useNotificationsListener(NotificationsUrlKeys.CONFIG, ...), parses message JSON for headers.parameterName, and calls invalidateConfigQueries(dispatch, parameterName) when present; tests validate registration and message handling (including malformed JSON and missing parameterName).
Wiring & Cleanup
src/app/App.tsx, src/features/app-parameters/hooks/*, src/features/app-parameters/__tests__/*
App imports updated to new local notifications hook; the previous WebSocket-based hook and its test suite under features/app-parameters were removed.
🚥 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
Title check ✅ Passed The title is partially related to the changeset. It mentions replacing deprecated behavior with a notification provider, which aligns with the PR's core objective, but contains a grammatical error ('instead or' should be 'instead of').
Description check ✅ Passed The description is related to the changeset, mentioning the replacement of ws.onMessage with NotificationProvider and alignment with other frontends.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/app/notifications/use-app-parameters-invalidation-listener.ts (1)

21-30: ⚡ Quick win

Wrap invalidateAppParameter in useCallback to prevent listener re-registration on every render.

invalidateAppParameter is recreated on every render and passed as listenerCallbackMessage to useNotificationsListener. If the hook internally tracks the callback in a useEffect dependency array (a standard pattern for subscription hooks), any render of App — e.g. from a Redux state change — will tear down and re-register the WebSocket listener unnecessarily. Since dispatch is a stable reference from useAppDispatch, wrapping in useCallback makes the function reference effectively stable for the lifetime of the component.

♻️ Proposed fix
-import { NotificationsUrlKeys, useNotificationsListener } from '@gridsuite/commons-ui';
+import { useCallback } from 'react';
+import { NotificationsUrlKeys, useNotificationsListener } from '@gridsuite/commons-ui';
 import { useAppDispatch } from '../store/store';
 import { invalidateConfigQueries } from '../../shared/api/config-api/config-api';
 
 // ...
 
 export const useAppParametersInvalidationListener = () => {
     const dispatch = useAppDispatch();
 
-    const invalidateAppParameter = (event: MessageEvent) => {
+    const invalidateAppParameter = useCallback((event: MessageEvent) => {
         const eventData = JSON.parse(event.data) as ConfigNotificationData;
         if (eventData.headers?.parameterName) {
             invalidateConfigQueries(dispatch, eventData.headers.parameterName);
         }
-    };
+    }, [dispatch]);
 
     useNotificationsListener(NotificationsUrlKeys.CONFIG, {
         listenerCallbackMessage: invalidateAppParameter,
     });
 };

Please verify the useNotificationsListener implementation in @gridsuite/commons-ui to confirm whether the listenerCallbackMessage reference is used as a useEffect dependency, which would confirm the impact of this change.

🤖 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 `@src/app/notifications/use-app-parameters-invalidation-listener.ts` around
lines 21 - 30, The listener callback invalidateAppParameter is recreated on
every render and should be wrapped in React's useCallback to avoid
re-registering the notification listener; update the component to memoize
invalidateAppParameter using useCallback with dispatch as its dependency so the
function reference passed to useNotificationsListener (listenerCallbackMessage)
remains stable, keeping the internal invalidateConfigQueries(dispatch, ...) call
intact and preventing unnecessary teardown/re-registration of the WebSocket
listener.
src/shared/api/ws/use-notifications-url-generator.ts (1)

21-36: ⚡ Quick win

Memoize the returned URL map to prevent spurious WebSocket reconnections.

The hook returns a new object literal on every call. AppProvidersWithStore re-renders whenever language or theme changes (via useGetConfigParameterWithFallback), so a fresh object reference is passed to NotificationsProvider on every such render. If NotificationsProvider uses reference equality to decide when to reconnect (as many subscription providers do), this will cause unnecessary WebSocket teardown/reconnect cycles even though the URL string itself hasn't changed.

Since webSocketBaseUrl, PREFIX_CONFIG_NOTIFICATION_WS, and APP_NAME are all effectively constant, only tokenId should gate a new URL.

♻️ Proposed fix
-import { NotificationsUrlKeys, PREFIX_CONFIG_NOTIFICATION_WS } from '@gridsuite/commons-ui';
+import { NotificationsUrlKeys, PREFIX_CONFIG_NOTIFICATION_WS } from '@gridsuite/commons-ui';
+import { useMemo } from 'react';
 import { APP_NAME } from 'app/config/app-config';
 import { selectUser } from '../../../features/authentication/store/authentication.selectors';
 import { useAppSelector } from '../../../app/store/store';
 
 // ...
 
 export const useNotificationsUrlGenerator = (): Partial<Record<NotificationsUrlKeys, string | undefined>> => {
     const webSocketBaseUrl = document.baseURI.replace(/^http:\/\//, 'ws://').replace(/^https:\/\//, 'wss://');
     const tokenId = useAppSelector(selectUser)?.id_token;
 
-    return {
-        [NotificationsUrlKeys.CONFIG]: getUrlWithToken(
-            `${webSocketBaseUrl}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?${new URLSearchParams({
-                appName: APP_NAME,
-            })}`,
-            tokenId
-        ),
-    };
+    return useMemo(
+        () => ({
+            [NotificationsUrlKeys.CONFIG]: getUrlWithToken(
+                `${webSocketBaseUrl}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?${new URLSearchParams({
+                    appName: APP_NAME,
+                })}`,
+                tokenId
+            ),
+        }),
+        [webSocketBaseUrl, tokenId]
+    );
 };

Please verify how NotificationsProvider consumes the urls prop — specifically whether it uses a useEffect with urls in its dependency array (reference equality) or performs a deep/value comparison before reconnecting.

🤖 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 `@src/shared/api/ws/use-notifications-url-generator.ts` around lines 21 - 36,
The hook useNotificationsUrlGenerator currently returns a new object each render
causing spurious reconnects; wrap the returned map in React.useMemo and memoize
it by tokenId (and any other non-constant inputs) so it only changes when
tokenId changes; specifically compute the URL with getUrlWithToken as before but
return the object inside useMemo(() => ({ [NotificationsUrlKeys.CONFIG]: ... }),
[tokenId]) so NotificationsProvider receives a stable reference unless the token
actually changes.
🤖 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
`@src/app/__tests__/notifications/use-app-parameters-invalidation-listener.test.ts`:
- Around line 40-48: The test is asserting against a non-existent enum key
NotificationsUrlKeys.MONITOR; update the test to use the correct key
NotificationsUrlKeys.CONFIG where useNotificationsListener is expected to be
called, and change the test description string to reflect the monitor→config
correction; ensure the assertion still checks useNotificationsListener was
called with NotificationsUrlKeys.CONFIG and the listenerCallbackMessage function
(the test references useAppParametersInvalidationListener,
useNotificationsListener and listenerCallbackMessage).

---

Nitpick comments:
In `@src/app/notifications/use-app-parameters-invalidation-listener.ts`:
- Around line 21-30: The listener callback invalidateAppParameter is recreated
on every render and should be wrapped in React's useCallback to avoid
re-registering the notification listener; update the component to memoize
invalidateAppParameter using useCallback with dispatch as its dependency so the
function reference passed to useNotificationsListener (listenerCallbackMessage)
remains stable, keeping the internal invalidateConfigQueries(dispatch, ...) call
intact and preventing unnecessary teardown/re-registration of the WebSocket
listener.

In `@src/shared/api/ws/use-notifications-url-generator.ts`:
- Around line 21-36: The hook useNotificationsUrlGenerator currently returns a
new object each render causing spurious reconnects; wrap the returned map in
React.useMemo and memoize it by tokenId (and any other non-constant inputs) so
it only changes when tokenId changes; specifically compute the URL with
getUrlWithToken as before but return the object inside useMemo(() => ({
[NotificationsUrlKeys.CONFIG]: ... }), [tokenId]) so NotificationsProvider
receives a stable reference unless the token actually changes.
🪄 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: CHILL

Plan: Pro

Run ID: 8b313d35-77d8-42af-87ed-284d084d8be6

📥 Commits

Reviewing files that changed from the base of the PR and between 8c350ea and bac323c.

📒 Files selected for processing (7)
  • src/app/App.tsx
  • src/app/__tests__/notifications/use-app-parameters-invalidation-listener.test.ts
  • src/app/notifications/use-app-parameters-invalidation-listener.ts
  • src/app/providers/AppProviders.tsx
  • src/features/app-parameters/__tests__/hooks/use-app-parameters-invalidation-listener.test.ts
  • src/features/app-parameters/hooks/use-app-parameters-invalidation-listener.ts
  • src/shared/api/ws/use-notifications-url-generator.ts
💤 Files with no reviewable changes (2)
  • src/features/app-parameters/tests/hooks/use-app-parameters-invalidation-listener.test.ts
  • src/features/app-parameters/hooks/use-app-parameters-invalidation-listener.ts

Comment thread src/app/__tests__/notifications/use-app-parameters-invalidation-listener.test.ts Outdated
klesaulnier and others added 6 commits May 5, 2026 11:08
Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/shared/api/ws/__tests__/use-notifications-url-generator.test.ts`:
- Line 45: The test contains a misspelled variable name `expecteConfigUrl`;
rename it to `expectedConfigUrl` everywhere in the test (e.g., where it's
declared in use-notifications-url-generator.test.ts and where it is referenced
later) so the identifier is spelled correctly and consistent; ensure any
assertions or comparisons use `expectedConfigUrl` after the rename.
🪄 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: CHILL

Plan: Pro

Run ID: 2258ff0e-f8f9-4dc4-8897-720d3e4f4112

📥 Commits

Reviewing files that changed from the base of the PR and between bac323c and 9c53640.

📒 Files selected for processing (4)
  • src/__mocks__/svgrMock.tsx
  • src/app/__tests__/notifications/use-app-parameters-invalidation-listener.test.ts
  • src/shared/api/ws/__tests__/use-notifications-url-generator.test.ts
  • src/test-utils/mocks/gridsuite-commons-ui.ts
💤 Files with no reviewable changes (1)
  • src/mocks/svgrMock.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/tests/notifications/use-app-parameters-invalidation-listener.test.ts

Comment thread src/shared/api/ws/__tests__/use-notifications-url-generator.test.ts Outdated
Signed-off-by: LE SAULNIER Kevin <kevin.lesaulnier.pro@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant