Fix continuous re-rendering in Auth wrapper components#3525
Open
C1pt2r5 wants to merge 7 commits intointelowlproject:developfrom
Open
Fix continuous re-rendering in Auth wrapper components#3525C1pt2r5 wants to merge 7 commits intointelowlproject:developfrom
C1pt2r5 wants to merge 7 commits intointelowlproject:developfrom
Conversation
- Change type annotation from bool to Optional[bool] - Update conditional check from 'if self.published:' to 'if self.published is not None:' - Remove outdated FIXME comment - Enables proper filtering of unpublished MISP events - Resolves issue where published=False was omitted from search params Fixes: intelowlproject#3429
- Separate useAuthStore calls to avoid array comparison issues - Change from array destructuring to individual store calls - Prevents infinite re-renders caused by [] != [] comparison - Components now only re-render on actual auth state changes - Improves performance in AuthGuard, withAuth, and IfAuthRedirectGuard Fixes: intelowlproject#3403
- Updated Logout component to separately retrieve loading state and logoutUser function from useAuthStore. - Refactored TagSelectInput component to individually access loading, error, allTags, fetchAll, and createTag from useTagsStore. - Modified TagForm to separately access updateTag and createTag from useTagsStore. - Adjusted useQuotaBadge hook to retrieve access and fetchUserAccess separately from useAuthStore. - Simplified withAuth wrapper by changing fetchPluginsConf to directly access hydrate from usePluginConfigurationStore.
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Auth Wrapper Rerendering Bug
PR Title
fix(auth): avoid unstable Zustand selector arrays in auth wrapper components. Closes #999Summary
This PR fixes a rerender storm in frontend auth-aware components that used Zustand selectors returning new arrays, e.g.:
useAuthStore(state => [state.isAuthenticated(), state.service.fetchUserAccess])usePluginConfigurationStore(state => [state.hydrate])In React/Zustand, an array selector returns a fresh array each render, causing pointer inequality and repeated updates (
[] !== []).Now, each state value/function is selected separately via stable selector callbacks:
useAuthStore(state => state.isAuthenticated())useAuthStore(state => state.service.fetchUserAccess)usePluginConfigurationStore(state => state.hydrate)Problem
[], causing inequality checks to fail during React dependency trackinguseEffectruns and state subscription updatesSolution
Split array-returning selectors into individual stable selectors for each state property/method.
Affected Files
frontend/src/wrappers/AuthGuard.jsxfrontend/src/wrappers/IfAuthRedirectGuard.jsxfrontend/src/wrappers/withAuth.jsxfrontend/src/components/auth/Logout.jsxfrontend/src/components/common/form/TagSelectInput.jsxfrontend/src/hooks/useQuotaBadge.jsxChanges Breakdown
AuthGuard.jsx
loadingandisAuthenticatedWithAuth.jsx
fetchPluginsConffetchPluginsConffunctionLogout.jsx
[loading, logoutUser]array destructuringTagSelectInput.jsx
[loading, error, allTags, fetchAll, createTag]useQuotaBadge.jsx
[access, fetchUserAccess]array destructuringIfAuthRedirectGuard.jsx
loadingandisAuthenticatedValidation
✅
npm run build- Compiled successfully✅
python -m ruff check .- All checks passed✅ No breaking changes - Functional behavior unchanged
✅ Performance improvement - Reduced rerender cycles
Type of Change
Checklist for PR
developpython -m ruff check .)npm run build)Closes #999)Related Issue
Closes #3403
Commit Message
How to Create the PR
Ensure you're on the
developbranch:Add the changed files:
git add frontend/src/wrappers/AuthGuard.jsx \ frontend/src/wrappers/IfAuthRedirectGuard.jsx \ frontend/src/wrappers/withAuth.jsx \ frontend/src/components/auth/Logout.jsx \ frontend/src/components/common/form/TagSelectInput.jsx \ frontend/src/hooks/useQuotaBadge.jsxCommit with the issue closure clause:
git commit -m "fix(auth): avoid array selector rerenders in Zustand selectors. Closes #3403"Push to remote:
Open a Pull Request on GitHub with this description and title:
fix(auth): avoid unstable Zustand selector arrays in auth wrapper components. Closes #3403Wait for maintainer review and assignment as per project guidelines.