Skip to content

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.

fix(ui): deliver native text input events within the UI frame

yhh342c9674ef6d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac8d97ef2..791e9562b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Native text-input notifications survive frame boundaries.** Update systems can read browser and native Change and Submit events after UI interaction clears the previous frame. Subscription callbacks remain synchronous, including focus changes made on Submit; their records reach frame consumers without replaying callbacks. Destroyed fields and disposed editors discard queued records.
+
- **Rich-text colors no longer recolor shadows and outlines.** Effect passes use their authored color and alpha on both bitmap and SDF atlases, including blurred shadows. The fill retains per-run colors, and inherited UI opacity continues to fade every pass.
- **UI text effects follow inherited opacity.** Parent transparency now fades text shadows, outlines and explicit rich-text colors together with the fill. Opacity changes invalidate cached batches, and fully transparent subtrees skip glyph layout and submission until they become visible again.
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 5de8c9ebe..df51120eb 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -3553,6 +3553,7 @@ type: string
## EntityEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
@@ -9339,6 +9340,7 @@ type: string
## UIEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 2f28f1c26..5155945af 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -3561,6 +3561,7 @@ type: string
## EntityEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
@@ -9552,6 +9553,7 @@ type: string
## UIEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 92dd73f4f..c199e3f59 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -3548,6 +3548,7 @@ type: string
## EntityEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
@@ -9334,6 +9335,7 @@ type: string
## UIEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 66c60cc31..49b449185 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -3548,6 +3548,7 @@ type: string
## EntityEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
@@ -9627,6 +9628,7 @@ type: string
## UIEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 144af7a60..efaf38d51 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -3548,6 +3548,7 @@ type: string
## EntityEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
@@ -9341,6 +9342,7 @@ type: string
## UIEventQueue — class @experimental
```
+@internal requeue: (event: EntityEvent) => void
clear: () => void
drain: () => readonly EntityEvent[]
emit: <TData = unknown>(entity: Entity, type: string, data?: TData) => EntityEvent<TData>
diff --git a/sdk/src/ecs/entityEvents.ts b/sdk/src/ecs/entityEvents.ts
index 397c07249..4295b7b9e 100644
--- a/sdk/src/ecs/entityEvents.ts
+++ b/sdk/src/ecs/entityEvents.ts
@@ -294,6 +294,11 @@ export class EntityEventQueue {
return this.pending_.filter((e) => e.type === type);
}
+ /** Restore an already-dispatched event for frame consumers without calling handlers again. @internal */
+ requeue(event: EntityEvent): void {
+ if (!this.pending_.includes(event)) this.pending_.push(event);
+ }
+
/** Remove all handlers and pending events. */
clear(): void {
this.entityHandlers_.clear();
diff --git a/sdk/src/ui/text/text-input-plugin.ts b/sdk/src/ui/text/text-input-plugin.ts
index 44f4b031c..5c296bcc1 100644
--- a/sdk/src/ui/text/text-input-plugin.ts
+++ b/sdk/src/ui/text/text-input-plugin.ts
@@ -15,7 +15,7 @@ import { Focusable, FocusManager, FocusManagerState } from '../input/focusable';
import type { FocusableData } from '../input/focusable';
import { UICameraInfo, type UICameraData } from '../core/ui-camera-info';
import { Transform, type TransformData } from '../../ecs/component';
-import { UIEvents, UIEventQueue } from '../core/events';
+import { UIEvents, UIEventQueue, type UIEvent } from '../core/events';
import { Res } from '../../ecs/resource';
import { playModeOnly } from '../../ecs/env';
import { ensureComponent, getUINodeWidth, getUINodeHeight } from '../util/helpers';
@@ -105,6 +105,7 @@ export class TextInputPlugin implements Plugin {
let composing = false;
let editingEntity: Entity | null = null;
+ let nativeEvents: UIEvent[] = [];
let cursorVisible = true;
let cursorTimer = 0;
let lastTime = 0;
@@ -139,7 +140,7 @@ export class TextInputPlugin implements Plugin {
break;
case 'submit':
if (focused !== null) {
- (app.getResource(UIEvents) as UIEventQueue).emit(focused, 'submit');
+ nativeEvents.push((app.getResource(UIEvents) as UIEventQueue).emit(focused, 'submit'));
if (getEditingTextInput() === focused) blurCurrent();
}
break;
@@ -167,6 +168,7 @@ export class TextInputPlugin implements Plugin {
this.cleanupListeners_.set(app, () => {
editingEntity = null;
+ nativeEvents = [];
unsubscribe();
editor.dispose();
for (const ch of childrenOf.values()) {
@@ -196,7 +198,7 @@ export class TextInputPlugin implements Plugin {
d.cursorPos = Math.min(state.selectionStart, val.length);
});
if (valueChanged) {
- (app.getResource(UIEvents) as UIEventQueue).emit(focused, 'change');
+ nativeEvents.push((app.getResource(UIEvents) as UIEventQueue).emit(focused, 'change'));
}
resetCursorBlink();
}
@@ -314,6 +316,20 @@ export class TextInputPlugin implements Plugin {
cursorTimer = 0;
}
+ // Native callbacks dispatch immediately. Restore their query records
+ // after interaction drains the old frame, without replaying callbacks.
+ app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], () => {
+ if (nativeEvents.length === 0) return;
+ const pending = nativeEvents;
+ nativeEvents = [];
+ const events = app.getResource(UIEvents) as UIEventQueue;
+ for (const event of pending) {
+ if (world.valid(event.target) && world.has(event.target, TextInput)) {
+ events.requeue(event);
+ }
+ }
+ }, { name: 'TextInputEventSystem' }), { runAfter: [SystemLabel.UIInteraction] });
+
let prevFocusedTextInput: Entity | null = null;
app.addSystemToSchedule(Schedule.Update, defineSystem(
diff --git a/sdk/tests/entity-event-observation.test.ts b/sdk/tests/entity-event-observation.test.ts
index 000cb045e..6283c9eb3 100644
--- a/sdk/tests/entity-event-observation.test.ts
+++ b/sdk/tests/entity-event-observation.test.ts
@@ -3,6 +3,19 @@ import { describe, expect, it } from 'vitest';
import { EntityEventQueue } from '../src/ecs/entityEvents';
import type { Entity, EntityEventObservation } from '../src';
describe('dispatch observation', () => {
+ it('restores a frame record without redispatching handlers or debugger observations', () => {
+ const q = new EntityEventQueue(), seen: EntityEventObservation[] = [];
+ let calls = 0;
+ q.on('change', event => { calls++; event.preventDefault(); });
+ q.observe(event => seen.push(event));
+ const event = q.emit(1 as Entity, 'change');
+ q.requeue(event);
+ expect(q.query('change')).toEqual([event]);
+ q.drain(); q.requeue(event); q.requeue(event);
+ expect(q.query('change')).toEqual([event]);
+ expect(event.defaultPrevented).toBe(true);
+ expect(calls).toBe(1); expect(seen).toHaveLength(1);
+ });
it('records completed target and actual bubble steps with one event identity', () => {
const q = new EntityEventQueue(), seen: EntityEventObservation[] = [];
q.on(2 as Entity, 'click', event => { event.preventDefault(); event.stopPropagation(); });
diff --git a/sdk/tests/text-input-plugin-lifecycle.test.ts b/sdk/tests/text-input-plugin-lifecycle.test.ts
index a0dd65ad0..d755d6690 100644
--- a/sdk/tests/text-input-plugin-lifecycle.test.ts
+++ b/sdk/tests/text-input-plugin-lifecycle.test.ts
@@ -31,6 +31,7 @@ const { TextInputPlugin } = await import('../src/ui/text/text-input-plugin');
const { FocusManager, FocusManagerState } = await import('../src/ui/input/focusable');
const { UIEvents, UIEventQueue } = await import('../src/ui/core/events');
const { TextInput } = await import('../src/ui/text/text-input');
+const { defineSystem, Schedule } = await import('../src/ecs/system');
const { Disabled } = await import('../src/ecs/component');
const { Interactable } = await import('../src/ui/input/interactable');
const apps: ReturnType<typeof App.new>[] = [];
@@ -48,6 +49,47 @@ afterEach(() => {
surfaces.length = 0;
});
+it.each(['change', 'composition', 'submit'] as const)('delivers native %s after UI clearing and before Update consumers', async kind => {
+ const app = build(new TextInputPlugin());
+ const events = app.getResource(UIEvents);
+ app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], () => { events.drain(); }, { name: 'UIInteractionSystem' }));
+ const field = app.world.spawn();
+ app.world.insert(field, TextInput, { value: '' });
+ app.getResource(FocusManager).focus(field);
+ await app.tick(1 / 60);
+ const type = kind === 'submit' ? 'submit' : 'change';
+ const handler = vi.fn();
+ events.on(type, handler);
+ const counts: number[] = [];
+ app.addSystemToSchedule(Schedule.Update, defineSystem([], () => { counts.push(events.query(type).length); }));
+ for (const listener of surfaces[0].listeners) {
+ listener(kind === 'composition' ? { kind, composing: false } : { kind });
+ }
+ expect(handler).toHaveBeenCalledOnce();
+ await app.tick(1 / 60);
+ expect(counts).toEqual([1]);
+ expect(handler).toHaveBeenCalledOnce();
+ await app.tick(1 / 60);
+ expect(counts).toEqual([1, 0]);
+});
+
+it('drops the frame record when its native input field was destroyed', async () => {
+ const app = build(new TextInputPlugin());
+ const field = app.world.spawn();
+ app.world.insert(field, TextInput, { value: '' });
+ app.getResource(FocusManager).focus(field);
+ await app.tick(1 / 60);
+ const handler = vi.fn();
+ app.getResource(UIEvents).on('change', handler);
+ const events = app.getResource(UIEvents);
+ app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], () => { events.drain(); }, { name: 'UIInteractionSystem' }));
+ for (const listener of surfaces[0].listeners) listener({ kind: 'change' });
+ app.world.despawn(field);
+ await app.tick(1 / 60);
+ expect(handler).toHaveBeenCalledOnce();
+ expect(events.query('change')).toEqual([]);
+});
+
it('quitting an older app releases only its text surface and preserves newer input', async () => {
const plugin = new TextInputPlugin(), first = build(plugin), second = build(plugin);
const field = second.world.spawn();
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 3b6b6358c..76e4b9b59 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(ui): deliver native text input events within the UI frame':
+ { note: 'Native text-input notifications survive frame boundaries.' },
'fix(ui): preserve rich text shadow and outline colors':
{ note: 'Rich-text colors no longer recolor shadows and outlines.' },
'fix(ui): apply inherited opacity to all text passes':