Skip to content

remove tokenId from useNotificationsUrlGenerator#174

Merged
ghazwarhili merged 8 commits into
mainfrom
prevent-refetch-on-silent-renew
May 22, 2026
Merged

remove tokenId from useNotificationsUrlGenerator#174
ghazwarhili merged 8 commits into
mainfrom
prevent-refetch-on-silent-renew

Conversation

@ghazwarhili
Copy link
Copy Markdown
Contributor

@ghazwarhili ghazwarhili commented May 6, 2026

PR Summary

remove tokenId from useNotificationsUrlGenerator

needs gridsuite/commons-ui#1102

@ghazwarhili ghazwarhili changed the title remove tokenId from notificationsUrlKeys remove tokenId from useNotificationsUrlGenerator May 6, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9731730e-6651-4bcd-9166-71c931f0af21

📥 Commits

Reviewing files that changed from the base of the PR and between d1788f4 and 6e99d2a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json
✅ Files skipped from review due to trivial changes (1)
  • package.json

📝 Walkthrough

Walkthrough

The notification URL hook no longer uses Redux auth; it always builds websocket URLs from getWsBase() plus constants. api-ws was simplified to re-export API types and provide getWsBase() only. App and AppTopBar now select user.profile as userProfile (with shallowEqual) and gate effects/rendering on userProfile.

Changes

Notification URL Generation Simplification

Layer / File(s) Summary
Dependencies and Type Contract
src/utils/notifications-provider.ts
Removed React Redux imports and updated return type to Partial<Record<NotificationsUrlKeys, string>> (no undefined).
URL Generation Logic
src/utils/notifications-provider.ts
Hook now unconditionally constructs CONFIG and GLOBAL_CONFIG websocket URLs using wsBase, PREFIX_CONFIG_NOTIFICATION_WS, and APP_NAME; memoization reduced to [wsBase].
Websocket Base Helper and Re-exports
src/utils/api-ws.ts
Module now re-exports types from ./api and exposes getWsBase(); removed getUrlWithToken and token usage.
App: userProfile selector and gated effects
src/components/App/App.tsx
Select state.user?.profile as userProfile (with shallowEqual); config fetch effect and render/props use userProfile instead of full user object.
AppTopBar: userProfile selector and metadata gating
src/components/App/AppTopBar.tsx
Select state.user?.profile as userProfile (with shallowEqual); gate metadata fetch on userProfile; pass userProfile into TopBar and use it to control Tabs visibility.
Dependency version bump
package.json
Bumped @gridsuite/commons-ui from 0.211.0 to 0.214.0.
🚥 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 pull request title directly matches the primary change: removing tokenId dependency from useNotificationsUrlGenerator function.
Description check ✅ Passed The description is related to the changeset, clearly stating the main objective and noting a dependency on an external PR.
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.

@ghazwarhili ghazwarhili requested a review from flomillot May 7, 2026 13:09
Copy link
Copy Markdown
Contributor

@sBouzols sBouzols left a comment

Choose a reason for hiding this comment

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

Code review OK
Tests OK
Console warning check OK

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/App/App.tsx (1)

70-80: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard config notification handling behind userProfile.

After this PR, notification URLs are generated even when no user is authenticated, but this callback still calls fetchConfigParameter(...) unconditionally. That means config websocket events can now trigger unauthorized fetches on the login screen or right after logout, producing 401s and snackbar noise.

Suggested fix
     const updateConfig = useCallback(
         (event: MessageEvent) => {
+            if (userProfile === null) {
+                return;
+            }
             const eventData = JSON.parse(event.data);
             if (eventData?.headers?.parameterName) {
                 fetchConfigParameter(APP_NAME, eventData.headers.parameterName)
                     .then((param) => updateParams([param]))
                     .catch((error) => snackWithFallback(snackError, error, { headerId: 'paramsRetrievingError' }));
             }
         },
-        [updateParams, snackError]
+        [updateParams, snackError, userProfile]
     );
🤖 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/components/App/App.tsx` around lines 70 - 80, The updateConfig callback
currently calls fetchConfigParameter unconditionally on incoming websocket
events; guard this behavior by checking that userProfile exists (is
authenticated) before invoking fetchConfigParameter so we don't trigger
unauthorized fetches after logout or on the login screen. Modify the
updateConfig function to first verify userProfile (or equivalent auth flag) and
only call fetchConfigParameter(APP_NAME, eventData.headers.parameterName) and
subsequently updateParams(...) when userProfile is truthy; keep the existing
error handling via snackWithFallback(snackError, ...) unchanged when the guarded
call runs.
🤖 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.

Outside diff comments:
In `@src/components/App/App.tsx`:
- Around line 70-80: The updateConfig callback currently calls
fetchConfigParameter unconditionally on incoming websocket events; guard this
behavior by checking that userProfile exists (is authenticated) before invoking
fetchConfigParameter so we don't trigger unauthorized fetches after logout or on
the login screen. Modify the updateConfig function to first verify userProfile
(or equivalent auth flag) and only call fetchConfigParameter(APP_NAME,
eventData.headers.parameterName) and subsequently updateParams(...) when
userProfile is truthy; keep the existing error handling via
snackWithFallback(snackError, ...) unchanged when the guarded call runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2ca73c02-c7e2-42f4-b29a-ae704f7d15d6

📥 Commits

Reviewing files that changed from the base of the PR and between 0ca7bee and d1788f4.

📒 Files selected for processing (2)
  • src/components/App/App.tsx
  • src/components/App/AppTopBar.tsx

Copy link
Copy Markdown
Contributor

@sBouzols sBouzols left a comment

Choose a reason for hiding this comment

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

Code Review OK
Tests OK
Console warning check OK

@sonarqubecloud
Copy link
Copy Markdown

@ghazwarhili ghazwarhili merged commit 9e79d57 into main May 22, 2026
6 checks passed
@ghazwarhili ghazwarhili deleted the prevent-refetch-on-silent-renew branch May 22, 2026 15:10
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