Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 整包版本改读原生真值,避免热更后回退 (#2050)
guyong-zapocda89990d1d0
diff --git a/apps/mobile/app/settings.tsx b/apps/mobile/app/settings.tsxindex 3bf6730f14..7f5ee27089 100644--- a/apps/mobile/app/settings.tsx+++ b/apps/mobile/app/settings.tsx@@ -41,6 +41,7 @@ import {StatusDot,} from '@/components/MobilePrimitives';import {+ APP_BINARY_VERSION,AUTH_API_BASE_URL,AUTH_REGION,DESKTOP_PACKAGE_VERSION,@@ -165,7 +166,11 @@ export default function SettingsScreen() {[auth.deviceId, auth.user?.email, auth.user?.id, auth.user?.name, deviceName, status, t],);- const appVersion = Constants.expoConfig?.version ?? '0.0.0';+ // 整包版本必须读原生烧进的值(CFBundleShortVersionString / versionName):+ // OTA 热更会把 manifest 里内嵌的 expoClient.version 覆盖给 Constants.expoConfig.version,+ // 而热更不改原生包,若读 expoConfig 会在热更后回退成打热更时主仓 app.json 的旧值。+ // APP_BINARY_VERSION 优先取原生层、热更后不漂移(与 mobileTapdb / env 上报同口径)。+ const appVersion = APP_BINARY_VERSION || '0.0.0';const updatesEnabled = Updates.isEnabled;// 当前运行的 OTA bundle 信息(只读),折进「调试」分组,用于核验热更是否生效。const { currentlyRunning } = useUpdates();diff --git a/apps/mobile/src/__tests__/mobileSettings.test.ts b/apps/mobile/src/__tests__/mobileSettings.test.tsindex 187eaa21fa..1ba5b97827 100644--- a/apps/mobile/src/__tests__/mobileSettings.test.ts+++ b/apps/mobile/src/__tests__/mobileSettings.test.ts@@ -231,4 +231,14 @@ describe('mobile settings overview', () => {expect(i18n.t('settings.version.pairedDesktopVersion', { version: '0.1.18' })).toBe('配套桌面版本 0.1.18');});++ it('整包版本读原生真值 APP_BINARY_VERSION,不读会被 OTA 覆盖的 expoConfig.version', () => {+ const source = readTextLf(resolve(process.cwd(), 'app/settings.tsx'), 'utf8');++ // 整包版本必须取原生烧进的 CFBundleShortVersionString / versionName(APP_BINARY_VERSION),+ // 热更后不漂移;绝不能读 Constants.expoConfig.version —— 它会被 OTA manifest 内嵌的+ // expoClient.version(打热更时主仓 app.json 的旧值)覆盖,导致整包版本回退。+ expect(source).toContain("const appVersion = APP_BINARY_VERSION || '0.0.0';");+ expect(source).not.toContain("const appVersion = Constants.expoConfig?.version");+ });});diff --git a/apps/mobile/src/update/bundleUpdate.ts b/apps/mobile/src/update/bundleUpdate.tsindex f3819d4056..3573fa6e49 100644--- a/apps/mobile/src/update/bundleUpdate.ts+++ b/apps/mobile/src/update/bundleUpdate.ts@@ -39,7 +39,7 @@ export interface BundleUpdateEvaluation {export interface EvaluateBundleUpdateInput {/** 当前运行包的 runtimeVersion(取自 expo-updates Updates.runtimeVersion)。 */currentRuntimeVersion: string | null | undefined;- /** 当前包的应用版本(Constants.expoConfig.version)。 */+ /** 当前包的应用版本(原生真值 APP_BINARY_VERSION;不要传会被 OTA 覆盖的 expoConfig.version)。 */currentVersion: string | null | undefined;/** `/latest` 返回体(已解析)。无效/缺字段视为无更新。 */latest: unknown;diff --git a/apps/mobile/src/update/useBundleUpdatePrompt.ts b/apps/mobile/src/update/useBundleUpdatePrompt.tsindex d041c751a6..d62cf487ea 100644--- a/apps/mobile/src/update/useBundleUpdatePrompt.ts+++ b/apps/mobile/src/update/useBundleUpdatePrompt.ts@@ -7,10 +7,10 @@import { useCallback, useEffect, useRef, useState } from 'react';import { Alert, Linking, Platform } from 'react-native';-import Constants from 'expo-constants';import * as Updates from 'expo-updates';import { i18n } from '@/i18n';import {+ APP_BINARY_VERSION,IS_OTA_SELFHOST,IS_TESTFLIGHT_BUILD,REVIEW_MODE,@@ -128,7 +128,9 @@ export function useBundleUpdatePrompt({if (requestEpoch !== channelEpochRef.current) return 'skipped';const evaluation = evaluateBundleUpdate({currentRuntimeVersion: Updates.runtimeVersion,- currentVersion: Constants.expoConfig?.version ?? null,+ // 强更门槛(minVersion)按原生真值比,避免热更后 expoConfig.version 被内嵌旧值+ // 覆盖导致原生已达标的机器被误判为低于门槛、错误触发强更。+ currentVersion: APP_BINARY_VERSION || null,latest,});if (evaluation.needsUpdate) {diff --git a/apps/mobile/src/update/useForcedUpdateRecheck.ts b/apps/mobile/src/update/useForcedUpdateRecheck.tsindex d6d69b2d59..43bd51933a 100644--- a/apps/mobile/src/update/useForcedUpdateRecheck.ts+++ b/apps/mobile/src/update/useForcedUpdateRecheck.ts@@ -6,8 +6,8 @@import { useEffect } from 'react';import { AppState, Platform } from 'react-native';-import Constants from 'expo-constants';import * as Updates from 'expo-updates';+import { APP_BINARY_VERSION } from '@/config/env';import { fetchLatestRelease } from './fetchLatestRelease';import { createForcedUpdateRechecker } from './forcedUpdateRecheck';import {@@ -32,7 +32,8 @@ export function useForcedUpdateRecheck(isCanary = isCanaryChannel()): void {isCanary,),getCurrentRuntimeVersion: () => Updates.runtimeVersion,- getCurrentVersion: () => Constants.expoConfig?.version ?? null,+ // 与 useBundleUpdatePrompt 同口径:强更解除也按原生真值比,热更后不漂移。+ getCurrentVersion: () => APP_BINARY_VERSION || null,onCleared: clearForcedUpdate,// 仍强更时刷新目标(等值时 enterForcedUpdate 幂等,不会引发重渲染)。onStillForced: enterForcedUpdate,diff --git a/apps/mobile/src/update/useResumeUpdateCheck.ts b/apps/mobile/src/update/useResumeUpdateCheck.tsindex c33223767c..8a49f7c555 100644--- a/apps/mobile/src/update/useResumeUpdateCheck.ts+++ b/apps/mobile/src/update/useResumeUpdateCheck.ts@@ -7,9 +7,9 @@import { useEffect } from 'react';import { AppState, Platform } from 'react-native';-import Constants from 'expo-constants';import * as Updates from 'expo-updates';import {+ APP_BINARY_VERSION,IS_OTA_SELFHOST,IS_TESTFLIGHT_BUILD,REVIEW_MODE,@@ -44,7 +44,8 @@ export function useResumeUpdateCheck(isCanary = isCanaryChannel()): void {isCanary,),getCurrentRuntimeVersion: () => Updates.runtimeVersion,- getCurrentVersion: () => Constants.expoConfig?.version ?? null,+ // 与 useBundleUpdatePrompt / useForcedUpdateRecheck 同口径:强更比较按原生真值,热更后不漂移。+ getCurrentVersion: () => APP_BINARY_VERSION || null,onForcedUpdate: promptBundleUpdate,now: () => Date.now(),isCurrent: () => current,