Files
ComfyUI_frontend/src/platform/updates/common/useFrontendVersionMismatchWarning.ts
Christian Byrne 069e94b325 fix: version mismatch warning appearing in Playwright tests despite DisableWarnings setting (#8036)
PR #7004 added a setting to disable version warnings in e2e tests, but
it wasn't working on release branches. The issue was a race condition
(hypothesis): the version check ran before settings finished loading
from the backend, so the DisableWarnings setting read its default value
(false) instead of the configured value (true).

Fixed by making the warningsDisabled check reactive so it updates when
settings load and adding `nextTick` (settings are loaded, but ref
updates flush in a microtask. The immediate `whenever` runs before that
flush, so computeds may see stale/default values -- `nextTick` waits for
reactive microtasks to flush, so computeds will be correct. It's fine).

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8036-fix-version-mismatch-warning-appearing-in-Playwright-tests-despite-DisableWarnings-setti-2e86d73d36508132b4d1fd73ade76e63)
by [Unito](https://www.unito.io)
2026-01-13 18:28:33 -08:00

98 lines
2.9 KiB
TypeScript

import { whenever } from '@vueuse/core'
import { computed, nextTick, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useToastStore } from './toastStore'
import { useVersionCompatibilityStore } from './versionCompatibilityStore'
interface UseFrontendVersionMismatchWarningOptions {
immediate?: boolean
}
/**
* Composable for handling frontend version mismatch warnings.
*
* Displays toast notifications when the frontend version is incompatible with the backend,
* either because the frontend is outdated or newer than the backend expects.
* Automatically dismisses warnings when shown and persists dismissal state for 7 days.
*
* @param options - Configuration options
* @param options.immediate - If true, automatically shows warning when version mismatch is detected
* @returns Object with methods and computed properties for managing version warnings
*
* @example
* ```ts
* // Show warning immediately when mismatch detected
* const { showWarning, shouldShowWarning } = useFrontendVersionMismatchWarning({ immediate: true })
*
* // Manual control
* const { showWarning } = useFrontendVersionMismatchWarning()
* showWarning() // Call when needed
* ```
*/
export function useFrontendVersionMismatchWarning(
options: UseFrontendVersionMismatchWarningOptions = {}
) {
const { immediate = false } = options
const { t } = useI18n()
const toastStore = useToastStore()
const versionCompatibilityStore = useVersionCompatibilityStore()
// Track if we've already shown the warning
let hasShownWarning = false
const showWarning = () => {
// Prevent showing the warning multiple times
if (hasShownWarning) return
const message = versionCompatibilityStore.warningMessage
if (!message) return
const detailMessage = t('g.frontendOutdated', {
frontendVersion: message.frontendVersion,
requiredVersion: message.requiredVersion
})
const fullMessage = t('g.versionMismatchWarningMessage', {
warning: t('g.versionMismatchWarning'),
detail: detailMessage
})
toastStore.addAlert(fullMessage)
hasShownWarning = true
// Automatically dismiss the warning so it won't show again for 7 days
versionCompatibilityStore.dismissWarning()
}
onMounted(async () => {
// Only set up the watcher if immediate is true
if (immediate) {
// Wait for next tick to ensure reactive updates from settings load have propagated
await nextTick()
whenever(
() => versionCompatibilityStore.shouldShowWarning,
() => {
showWarning()
},
{
immediate: true,
once: true
}
)
}
})
return {
showWarning,
shouldShowWarning: computed(
() => versionCompatibilityStore.shouldShowWarning
),
dismissWarning: versionCompatibilityStore.dismissWarning,
hasVersionMismatch: computed(
() => versionCompatibilityStore.hasVersionMismatch
)
}
}