From 19bc6c40b1573ef855ffdadc435cc0a3772ecb07 Mon Sep 17 00:00:00 2001 From: Matyas Forian-Szabo Date: Tue, 4 Aug 2026 11:05:28 +0200 Subject: [PATCH] fix(emotion): only warn about a missing theme when the fallback is actually used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getTheme warned "No theme provided for [InstUISettingsProvider], using default `canvas` theme." whenever there was no ancestor theme, even when the caller passed a perfectly valid theme via the `theme` prop. That path returns early from the isBaseTheme branch and never touches the canvas fallback, so the warning was a false positive on the most common usage. Move the warning below the isBaseTheme early return so it only fires when we really do fall back to canvas. Also collapse the currentTheme if/else into a hasAncestorTheme flag and make the InstUIProviderProps import type-only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/emotion/src/getTheme.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/emotion/src/getTheme.ts b/packages/emotion/src/getTheme.ts index 1266b33ab9..2dab6fa3c5 100644 --- a/packages/emotion/src/getTheme.ts +++ b/packages/emotion/src/getTheme.ts @@ -31,7 +31,7 @@ import type { ThemeOrLegacyOverride, SpecificThemeOverride } from './EmotionTypes' -import { InstUIProviderProps } from './InstUISettingsProvider/index.js' +import type { InstUIProviderProps } from './InstUISettingsProvider' declare const process: Record | undefined /** @@ -61,21 +61,8 @@ const getTheme = ) => (ancestorTheme = {} as Theme) => { // we need to clone the ancestor theme not to override it - let currentTheme - if (Object.keys(ancestorTheme).length === 0) { - if ( - typeof process !== 'undefined' && - (process?.env?.NODE_ENV !== 'production' || - process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true') - ) { - console.warn( - 'No theme provided for [InstUISettingsProvider], using default `canvas` theme.' - ) - } - currentTheme = canvas - } else { - currentTheme = ancestorTheme - } + const hasAncestorTheme = Object.keys(ancestorTheme).length > 0 + const currentTheme = hasAncestorTheme ? ancestorTheme : canvas const resolvedThemeOverride = typeof themeOverride === 'function' @@ -115,6 +102,19 @@ const getTheme = resolvedLegacyThemeOrOverride = {} } + // We only get here if no full theme was given, so the overrides are merged + // into the implicit `canvas` fallback instead of a theme the consumer chose. + if ( + !hasAncestorTheme && + typeof process !== 'undefined' && + (process?.env?.NODE_ENV !== 'production' || + process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true') + ) { + console.warn( + 'No theme provided for [InstUISettingsProvider], using default `canvas` theme.' + ) + } + const themeName = currentTheme.key // legacy: we pick the overrides for the current theme from the override object