Skip to content

ref: Remove createDefinedContext utility, inline standard createContext + hooks#115544

Draft
ryan953 wants to merge 6 commits into
masterfrom
ryan953/deprecate-createDefinedContext
Draft

ref: Remove createDefinedContext utility, inline standard createContext + hooks#115544
ryan953 wants to merge 6 commits into
masterfrom
ryan953/deprecate-createDefinedContext

Conversation

@ryan953
Copy link
Copy Markdown
Member

@ryan953 ryan953 commented May 14, 2026

Removes the createDefinedContext() helper from static/app/utils/performance/contexts/utils.tsx and replaces all 18 usages with standard createContext() calls and inline guarded hooks. The helper was a thin wrapper that hid a type lie — it cast Context<T | undefined> to Context<T>, masking the undefined case from consumers of strict: false contexts.

strict: false contexts now honestly type their hooks as T | undefined

Six contexts used strict: false, meaning the hook silently returned undefined without throwing when no provider was present. The old utility cast this to T, hiding the nullability from TypeScript. These hooks now return T | undefined, and seven downstream files were updated to handle the previously-hidden undefined:

  • metricsDataSwitcher.tsx, trendsWidget.tsx, table.tsx, transactionOverview/index.tsx, trendChart/index.tsx, transactionOverview/utils.tsx, onDemandControl.tsx

strict: true contexts get a standard throw guard

Twelve contexts used the default strict: true. These now have an inline if (context === undefined) throw new Error(...) guard in their hook, preserving the same runtime behavior with no type changes for consumers.

…guarded hooks

strict: false (hook returns T | undefined, no throw):
- static/app/utils/performance/contexts/onDemandControl.tsx
- static/app/utils/performance/contexts/metricsCardinality.tsx
- static/app/utils/performance/contexts/metricsEnhancedPerformanceDataContext.tsx (PerformanceDataMultipleMetaContext)
- static/app/views/explore/metrics/metricsFrozenContext.tsx
- static/app/views/explore/logs/logsFrozenContext.tsx
- static/app/views/dashboards/contexts/widgetSyncContext.tsx

strict: true (default — hook throws if undefined):
- static/app/utils/performance/contexts/performanceEventViewContext.tsx
- static/app/utils/performance/contexts/performanceDisplayContext.tsx
- static/app/utils/performance/contexts/metricsEnhancedSetting.tsx
- static/app/utils/performance/contexts/metricsEnhancedPerformanceDataContext.tsx (MetricsEnhancedPerformanceDataContext)
- static/app/views/explore/metrics/multiMetricsQueryParams.tsx
- static/app/views/explore/metrics/metricsQueryParams.tsx
- static/app/views/explore/contexts/logs/logsAutoRefreshContext.tsx
- static/app/views/explore/contexts/logs/logsPageData.tsx
- static/app/views/explore/logs/logsQueryParamsProvider.tsx
- static/app/views/explore/queryParams/context.tsx
- static/app/views/dashboards/widgetCard/dashboardsMEPContext.tsx
- static/app/views/seerExplorer/contexts/llmContext.tsx
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.51%

Move export keyword directly onto function/const declarations instead
of using separate export {} statements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines 9 to 16
const PerformanceEventViewContext = createContext<
UsePerformanceEventViewContext | undefined
>(undefined);
PerformanceEventViewContext.displayName = 'PerformanceEventViewContext';

const PerformanceEventViewProvider = PerformanceEventViewContext.Provider;

export {PerformanceEventViewProvider, PerformanceEventViewContext};
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@cursor move the export keyword next to the thing that is defined. don't define then export separatly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Taking a look!

Open in Web Open in Cursor 

Comment on lines 22 to 161
@@ -155,9 +155,9 @@ export function LogsFrozenContextProvider(
return <LogsFrozenContext value={value}>{props.children}</LogsFrozenContext>;
}

function useLogsFrozenContext() {
function useLogsFrozenContext(): Partial<LogsFrozenContextValue> {
// default to `LogsNotFrozen`
return _useLogsFrozenContext() ?? {};
return useLogsFrozenContextValue() ?? {};
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@cursor can we combine useLogsFrozenContext and useLogsFrozenContextValue() so we only have one function that is exported?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Taking a look!

Open in Web Open in Cursor 

Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>
Comment thread static/app/views/explore/metrics/metricsFrozenContext.tsx Outdated
cursoragent and others added 2 commits May 14, 2026 05:08
Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>
Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>

const {eventView: _eventView, withStaticFilters, InteractiveTitle} = props;

const withBreakpoint = !isCardinalityCheckLoading && !outcome?.forceTransactionsOnly;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

so amazing. outcome was already defined as outcome?: MetricDataSwitcherOutcome, so the ? didn't need to be added in this PR.

Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants