: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(shared-views): skip API calls that always 401 in shared/exported views (#57670)
Paul D'Ambrad9c5aa35725c
diff --git a/frontend/src/exporter/exporterViewLogic.ts b/frontend/src/exporter/exporterViewLogic.tsindex 1c9b09259210..0a68b75a3788 100644--- a/frontend/src/exporter/exporterViewLogic.ts+++ b/frontend/src/exporter/exporterViewLogic.ts@@ -103,3 +103,7 @@ export const exporterViewLogic = kea<exporterViewLogicType>([export const getCurrentExporterData = (): ExportedData | undefined => {return exporterViewLogic.findMounted()?.values.exportedData}++export const isSharedView = (): boolean => {+ return !!getCurrentExporterData()+}diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 9179e2e35697..3997bbb229b2 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -18,7 +18,7 @@ import { RecordingComment } from 'scenes/session-recordings/player/inspector/plaimport { SessionSummaryContent } from 'scenes/session-recordings/player/player-meta/types'import { LINK_PAGE_SIZE, SURVEY_PAGE_SIZE } from 'scenes/surveys/constants'-import { getCurrentExporterData } from '~/exporter/exporterViewLogic'+import { getCurrentExporterData, isSharedView } from '~/exporter/exporterViewLogic'import { OrganizationOAuthApplicationApi } from '~/generated/core/api.schemas'import { Variable } from '~/queries/nodes/DataVisualization/types'import {@@ -6916,6 +6916,8 @@ const api = {},} as const+const warnedSharedViewLeaks = new Set<string>()+async function handleFetch(url: string, method: string, fetcher: () => Promise<Response>): Promise<Response> {const startTime = new Date().getTime()@@ -6939,6 +6941,7 @@ async function handleFetch(url: string, method: string, fetcher: () => Promise<Rif (!response.ok) {const duration = new Date().getTime() - startTimeconst pathname = new URL(url, location.origin).pathname+ const inSharedView = isSharedView()// when used inside the posthog toolbar, `posthog.capture` isn't loaded// check if the function is available before calling it.if (posthog.capture) {@@ -6947,8 +6950,16 @@ async function handleFetch(url: string, method: string, fetcher: () => Promise<Rmethod,duration,status: response.status,+ is_shared_view: inSharedView,})}+ if (inSharedView && (response.status === 401 || response.status === 403)) {+ const leakKey = `${method} ${pathname}`+ if (!warnedSharedViewLeaks.has(leakKey)) {+ warnedSharedViewLeaks.add(leakKey)+ console.warn(`[shared-view] unexpected ${response.status} on ${leakKey}`)+ }+ }const data = await getJSONOrNull(response)diff --git a/frontend/src/lib/components/QuickFilters/quickFiltersLogic.ts b/frontend/src/lib/components/QuickFilters/quickFiltersLogic.tsindex 9be3688de8da..ebddc5952111 100644--- a/frontend/src/lib/components/QuickFilters/quickFiltersLogic.ts+++ b/frontend/src/lib/components/QuickFilters/quickFiltersLogic.ts@@ -5,6 +5,7 @@ import posthog from 'posthog-js'import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { isSharedView } from '~/exporter/exporterViewLogic'import { QuickFilterContext } from '~/queries/schema/schema-general'import { QuickFilter } from '~/types'@@ -37,6 +38,9 @@ export const quickFiltersLogic = kea<quickFiltersLogicType>([[] as QuickFilter[],{loadQuickFilters: async () => {+ if (isSharedView()) {+ return []+ }const response = await api.quickFilters.list(props.context)return response.results},diff --git a/frontend/src/lib/hooks/useFileSystemLogView.ts b/frontend/src/lib/hooks/useFileSystemLogView.tsindex 00b77e93f0e1..00c4a5888ce6 100644--- a/frontend/src/lib/hooks/useFileSystemLogView.ts+++ b/frontend/src/lib/hooks/useFileSystemLogView.ts@@ -2,6 +2,7 @@ import { useEffect } from 'react'import api, { ApiConfig } from 'lib/api'+import { isSharedView } from '~/exporter/exporterViewLogic'import { recentItemsModel } from '~/models/recentItemsModel'type FileSystemLogViewType =@@ -26,7 +27,14 @@ interface TrackFileSystemLogViewOptions {}export function trackFileSystemLogView({ type, ref, enabled = true }: TrackFileSystemLogViewOptions): void {- if (!enabled || window.IMPERSONATED_SESSION || ref === null || ref === undefined || !ApiConfig.hasCurrentTeamId()) {+ if (+ !enabled ||+ window.IMPERSONATED_SESSION ||+ isSharedView() ||+ ref === null ||+ ref === undefined ||+ !ApiConfig.hasCurrentTeamId()+ ) {return}diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Variables/variableDataLogic.ts b/frontend/src/queries/nodes/DataVisualization/Components/Variables/variableDataLogic.tsindex db511f313af1..ec531104e999 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Variables/variableDataLogic.ts+++ b/frontend/src/queries/nodes/DataVisualization/Components/Variables/variableDataLogic.ts@@ -5,6 +5,8 @@ import { lemonToast } from '@posthog/lemon-ui'import api from 'lib/api'+import { isSharedView } from '~/exporter/exporterViewLogic'+import { Variable } from '../../types'import type { variableDataLogicType } from './variableDataLogicType'@@ -15,6 +17,9 @@ export const variableDataLogic = kea<variableDataLogicType>([[] as Variable[],{loadVariables: async () => {+ if (isSharedView()) {+ return []+ }const insights = await api.insightVariables.list()return insights.results},diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 97624979be38..308bb09952db 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -40,6 +40,7 @@ import { Scene } from 'scenes/sceneTypes'import { urls } from 'scenes/urls'import { userLogic } from 'scenes/userLogic'+import { isSharedView } from '~/exporter/exporterViewLogic'import { SIDE_PANEL_CONTEXT_KEY, SidePanelSceneContext } from '~/layout/navigation-3000/sidepanel/types'import { dashboardsModel } from '~/models/dashboardsModel'import { insightsModel } from '~/models/insightsModel'@@ -1761,6 +1762,9 @@ export const dashboardLogic = kea<dashboardLogicType>([})},updateTileColor: async ({ tileId, color }) => {+ if (isSharedView()) {+ return+ }const previousColor = values.tiles.find((tile) => tile.id === tileId)?.coloractions.setTileProperty(tileId, { color })try {@@ -1773,6 +1777,9 @@ export const dashboardLogic = kea<dashboardLogicType>([}},toggleTileDescription: async ({ tileId }) => {+ if (isSharedView()) {+ return+ }const matchingTile = values.tiles.find((tile) => tile.id === tileId)const previousValue = matchingTile?.show_descriptionconst newValue = previousValue === false@@ -2366,7 +2373,7 @@ export const dashboardLogic = kea<dashboardLogicType>([.map((insight: QueryBasedInsightModel) => insight?.id).filter((id): id is number => !!id)- if (insightIds.length > 0 && values.currentTeamId) {+ if (insightIds.length > 0 && values.currentTeamId && !isSharedView()) {void api.create(`api/environments/${values.currentTeamId}/insights/viewed`, {insight_ids: insightIds,})diff --git a/frontend/src/scenes/insights/insightUsageLogic.ts b/frontend/src/scenes/insights/insightUsageLogic.tsindex 3c1ee284f636..ef777dc33f98 100644--- a/frontend/src/scenes/insights/insightUsageLogic.ts+++ b/frontend/src/scenes/insights/insightUsageLogic.ts@@ -7,6 +7,7 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import { projectLogic } from 'scenes/projectLogic'import { sceneLogic } from 'scenes/sceneLogic'+import { isSharedView } from '~/exporter/exporterViewLogic'import { DataNodeLogicProps, dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'import { Node } from '~/queries/schema/schema-general'@@ -63,7 +64,7 @@ export const insightUsageLogic = kea<insightUsageLogicType>([// Report the insight being viewed to our '/viewed' endpoint.// Used for "recently viewed insights", and in insights dashboard.- if (values.insight.id) {+ if (values.insight.id && !isSharedView()) {void api.create(`api/environments/${values.currentProjectId}/insights/viewed`, {insight_ids: [values.insight.id],})diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsxindex afdd76a6afb4..84ac164159b0 100644--- a/frontend/src/scenes/sceneLogic.tsx+++ b/frontend/src/scenes/sceneLogic.tsx@@ -36,6 +36,7 @@ import {} from 'scenes/sceneTypes'import { urls } from 'scenes/urls'+import { isSharedView } from '~/exporter/exporterViewLogic'import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'import { FileSystemIconType, ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel } from '~/types'@@ -971,6 +972,9 @@ export const sceneLogic = kea<sceneLogicType>([}},loadPinnedTabsFromBackend: async () => {+ if (isSharedView()) {+ return+ }try {const response = await api.get<{tabs?: SceneTab[]@@ -1572,6 +1576,9 @@ export const sceneLogic = kea<sceneLogicType>([subscriptions(({ actions, values, cache }) => {const schedulePinnedStateSync = (): void => {+ if (isSharedView()) {+ return+ }const pinnedTabsForPersistence = getPinnedTabsForPersistence(values.tabs)const homepageForPersistence = getHomepageForPersistence(values.homepage)const serializedPinnedState = JSON.stringify({