Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions webview-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,12 @@ const App = () => {
const [useProviderSignupView, setUseProviderSignupView] = useState(false)

// Check PostHog feature flag for provider signup view
// Wait for telemetry to be initialized before checking feature flags
useEffect(() => {
if (!didHydrateState || telemetrySetting === "disabled") {
return
}

posthog.onFeatureFlags(function () {
// Feature flag for new provider-focused welcome view
setUseProviderSignupView(posthog?.getFeatureFlag("welcome-provider-signup") === "test")
})
}, [didHydrateState, telemetrySetting])
}, [])
Comment on lines 89 to +94
Copy link
Contributor

Choose a reason for hiding this comment

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

Reverting these guards means PostHog feature flag checks will now run regardless of the user's telemetry preferences. When users have telemetrySetting === "disabled", this effect will still query PostHog, potentially violating their privacy settings. The original PR #9488 specifically added the telemetrySetting === "disabled" check to respect user preferences.

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines 89 to +94
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing the didHydrateState check introduces a race condition. The feature flag query will now run immediately on component mount, potentially before the extension state (including user identity and telemetry settings) is fully initialized. This is inconsistent with other telemetry operations in the same component - line 217 shows if (didHydrateState) guarding the telemetry client update, demonstrating that waiting for state hydration is the established pattern for telemetry operations.

Fix it with Roo Code or mention @roomote and request a fix.


// Create a persistent state manager
const marketplaceStateManager = useMemo(() => new MarketplaceViewStateManager(), [])
Expand Down
60 changes: 0 additions & 60 deletions webview-ui/src/__tests__/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@

import React from "react"
import { render, screen, act, cleanup } from "@/utils/test-utils"
import posthog from "posthog-js"

import AppWithProviders from "../App"

// Mock posthog
vi.mock("posthog-js", () => ({
default: {
onFeatureFlags: vi.fn(),
getFeatureFlag: vi.fn(),
},
}))

vi.mock("@src/utils/vscode", () => ({
vscode: {
postMessage: vi.fn(),
Expand Down Expand Up @@ -198,7 +189,6 @@ describe("App", () => {
shouldShowAnnouncement: false,
experiments: {},
language: "en",
telemetrySetting: "enabled",
})
})

Expand Down Expand Up @@ -348,54 +338,4 @@ describe("App", () => {
expect(chatView.getAttribute("data-hidden")).toBe("false")
expect(screen.queryByTestId("marketplace-view")).not.toBeInTheDocument()
})

describe("PostHog feature flag initialization", () => {
it("waits for state hydration before checking feature flags", () => {
mockUseExtensionState.mockReturnValue({
didHydrateState: false,
showWelcome: false,
shouldShowAnnouncement: false,
experiments: {},
language: "en",
telemetrySetting: "enabled",
})

render(<AppWithProviders />)

// PostHog feature flag check should not be called before hydration
expect(posthog.onFeatureFlags).not.toHaveBeenCalled()
})

it("checks feature flags after state hydration when telemetry is enabled", () => {
mockUseExtensionState.mockReturnValue({
didHydrateState: true,
showWelcome: false,
shouldShowAnnouncement: false,
experiments: {},
language: "en",
telemetrySetting: "enabled",
})

render(<AppWithProviders />)

// PostHog feature flag check should be called after hydration
expect(posthog.onFeatureFlags).toHaveBeenCalled()
})

it("does not check feature flags when telemetry is disabled", () => {
mockUseExtensionState.mockReturnValue({
didHydrateState: true,
showWelcome: false,
shouldShowAnnouncement: false,
experiments: {},
language: "en",
telemetrySetting: "disabled",
})

render(<AppWithProviders />)

// PostHog feature flag check should not be called when telemetry is disabled
expect(posthog.onFeatureFlags).not.toHaveBeenCalled()
})
})
})
Loading