-
Notifications
You must be signed in to change notification settings - Fork 747
OCPBUGS-111707: Flush async feature flag updates immediately #16949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 6 commits into
openshift:main
from
kchawlani19:fix-16922-async-feature-flag
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
66cbc8d
Flush async feature flag updates immediately
kchawlani19 4754d72
Keep feature flag snapshot in sync across consecutive updates
kchawlani19 c4333de
Avoid shadowing FLAGS with a local flagsRef
kchawlani19 d7b27f1
Defer feature flag flushes via microtask
kchawlani19 cb9d00b
Detach pending flag map before flush for safe reentrancy
kchawlani19 49df1a9
Drop unnecessary @console/internal/plugins mock from flag tests
kchawlani19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
...d/packages/console-app/src/components/flags/__tests__/FeatureFlagExtensionLoader.spec.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { act } from '@testing-library/react'; | ||
| import { useStore } from 'react-redux'; | ||
| import type { RootState } from '@console/internal/redux'; | ||
| import { renderHookWithProviders } from '@console/shared/src/test-utils/unit-test-utils'; | ||
| import { createTestPluginStore } from '../../console-operator/__tests__/pluginTestUtils'; | ||
| import { useFeatureFlagController } from '../FeatureFlagExtensionLoader'; | ||
|
|
||
| const renderController = () => | ||
| renderHookWithProviders(() => useFeatureFlagController(), { | ||
| pluginStore: createTestPluginStore(), | ||
| }); | ||
|
|
||
| describe('useFeatureFlagController', () => { | ||
| it('defers flag updates made during render until after the render completes', async () => { | ||
| let flagDuringRender: boolean | undefined; | ||
| const { store, result } = renderHookWithProviders( | ||
| () => { | ||
| const reduxStore = useStore<RootState>(); | ||
| const setFeatureFlag = useFeatureFlagController(); | ||
| // Simulate console.flag/hookProvider handlers that set flags during render. | ||
| setFeatureFlag('SYNC_FLAG', true); | ||
| flagDuringRender = reduxStore.getState().FLAGS.get('SYNC_FLAG'); | ||
| return setFeatureFlag; | ||
| }, | ||
| { pluginStore: createTestPluginStore() }, | ||
| ); | ||
|
|
||
| expect(flagDuringRender).toBeUndefined(); | ||
| expect(result.current).toEqual(expect.any(Function)); | ||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(store.getState().FLAGS.get('SYNC_FLAG')).toBe(true); | ||
| }); | ||
|
|
||
| it('applies async flag updates without waiting for another render', async () => { | ||
| const { store, result } = renderController(); | ||
|
|
||
| await act(async () => { | ||
| result.current('ASYNC_FLAG', true); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(store.getState().FLAGS.get('ASYNC_FLAG')).toBe(true); | ||
| }); | ||
|
|
||
| it('coalesces consecutive async updates to the latest value', async () => { | ||
| const { store, result } = renderController(); | ||
|
|
||
| await act(async () => { | ||
| result.current('TOGGLE_FLAG', true); | ||
| result.current('TOGGLE_FLAG', false); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(store.getState().FLAGS.get('TOGGLE_FLAG')).toBe(false); | ||
| }); | ||
|
|
||
| it('preserves flag updates made reentrantly during flush', async () => { | ||
| const { store, result } = renderController(); | ||
|
|
||
| await act(async () => { | ||
| const unsubscribe = store.subscribe(() => { | ||
| if (store.getState().FLAGS.get('REENTRANT_FLAG') === true) { | ||
| result.current('REENTRANT_FLAG', false); | ||
| unsubscribe(); | ||
| } | ||
| }); | ||
| result.current('REENTRANT_FLAG', true); | ||
| await Promise.resolve(); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(store.getState().FLAGS.get('REENTRANT_FLAG')).toBe(false); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of
flushScheduledRefis as a lock to prevent multiple queued microtasks offlushPendingUpdatesfrom being called in parallel right?Then shouldn't the unlock,
flushPendingUpdates.current=false, be placed afterpendingUpdatesRefis accessed, instead of before?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes — unlock after taking the batch. Order is now: detach
pendingUpdatesRef→ setflushScheduledRef.current = false→ dispatch the detached updates. That way a reentrantscheduleFlushduring dispatch can queue a follow-up microtask for the new map.