Skip to content
Open
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
32 changes: 16 additions & 16 deletions packages/emotion/src/getTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> | undefined

/**
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Loading