Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(flags): save typed true/false flag dependency values as booleans (#117382)

Ben Lea0c6d590ca025
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
index 2f21ffa5a2fa..c0e36d44e86f 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
@@ -461,4 +461,66 @@ describe('PropertyValue', () => {
// The pasted id is shown as the value.
expect(screen.getByText('org-abc-123')).toBeInTheDocument()
})
+
+ it.each([
+ ['false', false],
+ ['true', true],
+ ])('saves a flag dependency value %s typed before the options load as a boolean', async (typed, expected) => {
+ useMocks({
+ get: {
+ '/api/projects/:team/flag_value/values': () => new Promise(() => {}),
+ },
+ })
+ const onSet = jest.fn()
+ render(
+ <Provider>
+ <PropertyValue
+ propertyKey="42"
+ type={PropertyFilterType.Flag}
+ operator={PropertyOperator.FlagEvaluatesTo}
+ onSet={onSet}
+ value={null}
+ />
+ </Provider>
+ )
+
+ const input = screen.getByRole('textbox')
+ userEvent.click(input)
+ userEvent.type(input, `${typed}{enter}`)
+
+ expect(propertyDefinitionsModel.values.options['42']?.status).not.toBe('loaded')
+ await waitFor(() => expect(onSet).toHaveBeenCalledWith(expected))
+ })
+
+ it('keeps a loaded flag dependency variant named false as a string', async () => {
+ useMocks({
+ get: {
+ '/api/projects/:team/flag_value/values': {
+ results: [{ name: true }, { name: false }, { name: 'false' }],
+ refreshing: false,
+ },
+ },
+ })
+ const onSet = jest.fn()
+ render(
+ <Provider>
+ <PropertyValue
+ propertyKey="42"
+ type={PropertyFilterType.Flag}
+ operator={PropertyOperator.FlagEvaluatesTo}
+ onSet={onSet}
+ value={null}
+ />
+ </Provider>
+ )
+
+ const input = screen.getByRole('textbox')
+ userEvent.click(input)
+ await waitFor(() => expect(propertyDefinitionsModel.values.options['42']?.status).toBe('loaded'), {
+ timeout: 3000,
+ })
+ userEvent.type(input, 'false{enter}')
+
+ await waitFor(() => expect(onSet).toHaveBeenCalledWith('false'))
+ })
})
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
index 230d5eb76b64..463bf4c78124 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
@@ -72,6 +72,19 @@ export interface PropertyValueProps {
propertyTypeOverride?: PropertyType
}
+// A flag dependency matches a boolean result only when its value is the boolean itself. Evaluation compares
+// the string "false" with variant keys, so it never matches a boolean flag. The input returns the typed text
+// as a string when the user presses Enter before the true/false options load.
+function toFlagDependencyValue<T>(value: T): T | boolean {
+ if (value === 'true') {
+ return true
+ }
+ if (value === 'false') {
+ return false
+ }
+ return value
+}
+
export function PropertyValue({
propertyKey,
type,
@@ -528,7 +541,13 @@ export function PropertyValue({
had_search_input: currentSearchInput.current !== '',
})
}
- isMultiSelect ? setValue(trimmedVal) : setValue(trimmedVal[0])
+ // A loaded option keeps its own type, so a variant named "true" or "false" stays a string.
+ const typedVal = isFlagDependencyProperty
+ ? trimmedVal.map((v) =>
+ displayOptions.some((o) => o.name === v) ? v : toFlagDependencyValue(v)
+ )
+ : trimmedVal
+ isMultiSelect ? setValue(typedVal) : setValue(typedVal[0])
}}
onInputChange={onSearchTextChange}
placeholder={placeholder}