A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(storage): preserve empty mini-game values
yhhbe2617cef89a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0f0838bf6..379d0ef68 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,8 @@ published separately; it ships inside the editor.### Fixed+- **Mini-game storage preserves empty strings.** The adapter distinguishes an explicitly stored empty string from an absent key through the host's key list, matching Web storage and preserving empty text preferences across adapter restarts. Non-empty reads keep their direct path; unavailable host storage remains a safe absent result.+- **Audio preferences survive game restart.** Audio-demo saves and restores master, music and SFX volumes through engine storage, validates saved values, and restores the displayed percentages and actual bus gains at startup. Golden verification uses independent browser processes with a stable origin and isolated profile, cycles master volume to mute and verifies that both the label and silent output survive restart.- **Release optimization commits valid WASM artifacts atomically.** A failed post-link optimizer now fails the build and preserves the original artifact. Cache scans can repair exact manifest references in a surviving legacy cache, and hosts without usable storage report unsupported cache writes.diff --git a/sdk/src/platform/minigame/adapter.ts b/sdk/src/platform/minigame/adapter.tsindex 0a429b9a8..a932c2cf5 100644--- a/sdk/src/platform/minigame/adapter.ts+++ b/sdk/src/platform/minigame/adapter.ts@@ -580,13 +580,14 @@ export class MiniGamePlatformAdapter implements PlatformAdapter {return this.profile_.createSocket?.(options) ?? new MiniGameSocket(options, this.g_);}- /** `null` means ABSENT, as on the web — but `getStorageSync` answers an unset- * key with `''`, which readers above take for a stored value and fail to- * parse. The host cannot tell the two apart, so `''` is read as absence. */+ /** The host returns `''` for both absent keys and stored empty strings.+ * Only that ambiguous result needs the key list; normal reads stay direct. */getStorageItem(key: string): string | null {try {const value = this.g_.getStorageSync(key);- return typeof value === 'string' && value !== '' ? value : null;+ if (typeof value !== 'string') return null;+ if (value !== '') return value;+ return this.g_.getStorageInfoSync?.().keys.includes(key) ? '' : null;} catch {return null;}diff --git a/sdk/tests/minigame-storage-values.test.ts b/sdk/tests/minigame-storage-values.test.tsnew file mode 100644index 000000000..7f140d222--- /dev/null+++ b/sdk/tests/minigame-storage-values.test.ts@@ -0,0 +1,45 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { expect, it, vi } from 'vitest';+import { MiniGamePlatformAdapter } from '../src/platform/minigame/adapter';+import type { MiniGameGlobal, MiniGameProfile } from '../src/platform/minigame/api';++function setup() {+ const values = new Map<string, string>();+ const info = vi.fn(() => ({ keys: [...values.keys()] }));+ const host = {+ getStorageSync: (key: string) => values.get(key) ?? '',+ setStorageSync: (key: string, value: string) => values.set(key, value),+ removeStorageSync: (key: string) => values.delete(key),+ getStorageInfoSync: info,+ };+ const profile: MiniGameProfile = { id: 'storage-test', hostLabel: 'Storage test', global: host as unknown as MiniGameGlobal };+ return { adapter: new MiniGamePlatformAdapter(profile), info, values, profile };+}+it('preserves an explicitly stored empty string and distinguishes missing keys', () => {+ const { adapter } = setup();+ adapter.setStorageItem('empty', '');+ expect(adapter.getStorageItem('empty')).toBe('');+ expect(adapter.getStorageItem('missing')).toBe(null);+ adapter.removeStorageItem('empty');+ expect(adapter.getStorageItem('empty')).toBe(null);+});+it('reads normal values without querying the key list', () => {+ const { adapter, info } = setup();+ adapter.setStorageItem('value', '{"volume":0}');+ expect(adapter.getStorageItem('value')).toBe('{"volume":0}');+ expect(info).not.toHaveBeenCalled();+});+it('retains stored values when a new adapter is created for the same host', () => {+ const { adapter, profile } = setup();+ adapter.setStorageItem('empty', '');+ adapter.setStorageItem('zero', '0');+ const restarted = new MiniGamePlatformAdapter(profile);+ expect(restarted.getStorageItem('empty')).toBe('');+ expect(restarted.getStorageItem('zero')).toBe('0');+});+it('returns absence if the host refuses the ambiguous key lookup', () => {+ const { adapter, info } = setup();+ info.mockImplementation(() => { throw new Error('storage unavailable'); });+ expect(adapter.getStorageItem('missing')).toBe(null);+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f16d96447..9ffd76235 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(storage): preserve empty mini-game values':+ { note: 'Mini-game storage preserves empty strings.' },'fix(examples): restore audio preferences across game restarts':{ note: 'Audio preferences survive game restart.' },'fix(test): await atomic scale-report persistence':