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(integrations): resolve saved slack channel name on initial load (#60510)

Daniel Marchukbdbbd46ad049
diff --git a/frontend/src/lib/integrations/SlackChannelPicker.test.tsx b/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
index 0caf6dc50488..a998f65bc268 100644
--- a/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
+++ b/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
@@ -39,22 +39,40 @@ const CHANNELS = [
},
]
+// A channel whose ID is not returned by the bulk /channels endpoint — simulating a workspace
+// where the saved channel falls beyond the first page that the backend returns.
+const OFF_PAGE_CHANNEL = {
+ id: 'COFFPAGE9XX',
+ name: 'off-page-channel',
+ is_private: false,
+ is_member: true,
+ is_ext_shared: false,
+ is_private_without_access: false,
+}
+
describe('SlackChannelPicker', () => {
let channelsRequestSearchQueries: (string | null)[] = []
+ let channelIdLookups: string[] = []
beforeEach(() => {
channelsRequestSearchQueries = []
+ channelIdLookups = []
useMocks({
get: {
'/api/environments/:team_id/integrations/:id/channels': (req: any) => {
const search = req.url.searchParams.get('search')
const channelId = req.url.searchParams.get('channel_id')
if (channelId) {
- const match = CHANNELS.find((c) => c.id === channelId)
+ channelIdLookups.push(channelId)
+ const match =
+ CHANNELS.find((c) => c.id === channelId) ??
+ (OFF_PAGE_CHANNEL.id === channelId ? OFF_PAGE_CHANNEL : null)
return [200, { channels: match ? [match] : [] }]
}
channelsRequestSearchQueries.push(search)
// Server-side search: substring match in name or id (mirrors the backend).
+ // The bulk endpoint deliberately never returns OFF_PAGE_CHANNEL so we can
+ // verify name resolution falls back to the direct-by-id lookup.
const filtered = search
? CHANNELS.filter(
(c) =>
@@ -113,6 +131,64 @@ describe('SlackChannelPicker', () => {
expect(channelsRequestSearchQueries).toEqual([''])
})
+ it('directly fetches the saved channel by id on mount so it resolves even when not in the bulk list', async () => {
+ // The saved value is a bare channel ID and the channel lives beyond the first page that the
+ // backend returns from /channels. Without the direct lookup the picker would only know about
+ // the bulk-list channels (test-slack-notifications, general) and would render the raw
+ // "COFFPAGE9XX" string instead of "#off-page-channel (COFFPAGE9XX)".
+ render(
+ <Provider>
+ <SlackChannelPicker integration={INTEGRATION} value="COFFPAGE9XX" onChange={jest.fn()} />
+ </Provider>
+ )
+
+ // loadSlackChannelById has a 500ms breakpoint before fetching, so wait generously.
+ await waitFor(
+ () => {
+ expect(channelIdLookups).toContain('COFFPAGE9XX')
+ },
+ { timeout: 2000 }
+ )
+ })
+
+ it('skips the direct lookup when the saved value is already in composite "id|#name" form', async () => {
+ // Composite values already carry the name; modifiedValue short-circuits resolution for
+ // them and the picker has nothing to do with a by-id response, so the fetch would be a
+ // wasted round-trip on every mount of a previously-saved picker.
+ render(
+ <Provider>
+ <SlackChannelPicker
+ integration={INTEGRATION}
+ value="COFFPAGE9XX|#off-page-channel"
+ onChange={jest.fn()}
+ />
+ </Provider>
+ )
+
+ // Wait for the bulk load and any debounced by-id call to settle.
+ await waitFor(() => {
+ expect(channelsRequestSearchQueries).toEqual([''])
+ })
+ await new Promise((resolve) => setTimeout(resolve, 800))
+ expect(channelIdLookups).toEqual([])
+ })
+
+ it('does not fire a direct lookup when there is no saved value', async () => {
+ render(
+ <Provider>
+ <SlackChannelPicker integration={INTEGRATION} onChange={jest.fn()} />
+ </Provider>
+ )
+
+ // Wait for the bulk load to finish so the test isn't racing the mount effects.
+ await waitFor(() => {
+ expect(channelsRequestSearchQueries).toEqual([''])
+ })
+ // Wait past the by-id breakpoint window so a stray call would have surfaced by now.
+ await new Promise((resolve) => setTimeout(resolve, 800))
+ expect(channelIdLookups).toEqual([])
+ })
+
it('still searches when the user actually types a different value', async () => {
// Render without an initial value so the input starts empty and typing isn't appended
// to LemonInputSelect's auto-fill of an existing selection.
diff --git a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
index 3fadd7ead02b..d6517901a595 100644
--- a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
+++ b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
@@ -126,6 +126,18 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
}
}, [loadAllSlackChannels, disabled])
+ // Workspaces with hundreds of channels can have the saved channel beyond the first page that
+ // /channels returns. Without a direct lookup the bare ID never resolves to a name on initial
+ // load — the picker just shows the ID. Fetch the saved channel by id so it merges into the
+ // slackChannels selector regardless of where it falls in the bulk list. Skip composite values
+ // ("id|#name") — modifiedValue short-circuits resolution for those, so the lookup result would
+ // never be consumed.
+ useEffect(() => {
+ if (!disabled && value && value.split('|').length === 1) {
+ loadSlackChannelById(value)
+ }
+ }, [loadSlackChannelById, value, disabled])
+
return (
<>
<LemonInputSelect
@@ -190,7 +202,7 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
{allSlackChannels?.has_more && !allSlackChannelsLoading ? (
<p className="text-secondary text-xs mt-1 mb-0">
- Only the first 200 channels are shown — type to search for a specific channel.
+ Only the first page of channels is shown — type to search for a specific channel.
</p>
) : null}
diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.test.ts b/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
index c2deff33e7c5..f2d71f2d66ad 100644
--- a/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
+++ b/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
@@ -57,13 +57,15 @@ describe('slackIntegrationLogic — loadAllSlackChannels search & pagination', (
logic.unmount()
})
- it('forwards search and limit to the channels endpoint when search is provided', async () => {
+ it('forwards search to the channels endpoint when search is provided', async () => {
await expectLogic(logic, () => {
logic.actions.loadAllSlackChannels(false, 'eng')
}).toFinishAllListeners()
expect(lastChannelsQuery.search).toBe('eng')
- expect(lastChannelsQuery.limit).toBe('200')
+ // No explicit limit — the picker defers to the backend default so the initial dropdown
+ // stays light and anything past the default falls through to server-side search.
+ expect(lastChannelsQuery.limit).toBeUndefined()
expect(lastChannelsQuery.force_refresh).toBe('false')
expect(logic.values.allSlackChannels?.has_more).toBe(true)
})
@@ -74,7 +76,7 @@ describe('slackIntegrationLogic — loadAllSlackChannels search & pagination', (
}).toFinishAllListeners()
expect(lastChannelsQuery.search).toBe('')
- expect(lastChannelsQuery.limit).toBe('200')
+ expect(lastChannelsQuery.limit).toBeUndefined()
})
it('reloads the full list when a search-then-clear sequence runs', async () => {
diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.ts b/frontend/src/lib/integrations/slackIntegrationLogic.ts
index 139d4a1b2758..71549106235a 100644
--- a/frontend/src/lib/integrations/slackIntegrationLogic.ts
+++ b/frontend/src/lib/integrations/slackIntegrationLogic.ts
@@ -31,7 +31,7 @@ export const slackIntegrationLogic = kea<slackIntegrationLogicType>([
if (search) {
await breakpoint(300)
}
- return await api.integrations.slackChannels(props.id, forceRefresh, { search, limit: 200 })
+ return await api.integrations.slackChannels(props.id, forceRefresh, { search })
},
},
],