@energy8platform/game-engine 0.14.6 → 0.14.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,18 @@ function isSuspendable(obj: any): obj is Suspendable {
22
22
  /** Layout containers that need flush after commit phase */
23
23
  const pendingLayoutFlush = new Set<Suspendable>();
24
24
 
25
+ /** Suspend a layout container and all its suspendable ancestors, add them to pending flush */
26
+ function suspendWithAncestors(instance: any): void {
27
+ let current = instance;
28
+ while (current) {
29
+ if (isSuspendable(current)) {
30
+ current.suspendLayout();
31
+ pendingLayoutFlush.add(current);
32
+ }
33
+ current = current.parent;
34
+ }
35
+ }
36
+
25
37
  /** Extract FlexItemConfig from props if any flex item props are present */
26
38
  function extractFlexItemConfig(props: Record<string, any>): FlexItemConfig | undefined {
27
39
  let config: FlexItemConfig | undefined;
@@ -196,6 +208,13 @@ const hostConfig: Reconciler.HostConfig<
196
208
  },
197
209
 
198
210
  commitUpdate(instance, _updatePayload, _type, oldProps, newProps) {
211
+ // Suspend this instance and ancestors before applying changes —
212
+ // prevents intermediate relayouts with partially-updated tree
213
+ const dimensionsChanged = newProps.width !== oldProps.width || newProps.height !== oldProps.height;
214
+ if (isSuspendable(instance) || dimensionsChanged) {
215
+ suspendWithAncestors(instance);
216
+ }
217
+
199
218
  if (typeof instance.updateConfig === 'function') {
200
219
  const changed = diffConfig(newProps, oldProps);
201
220
  if (Object.keys(changed).length > 0) {
@@ -226,11 +245,9 @@ const hostConfig: Reconciler.HostConfig<
226
245
  }
227
246
  }
228
247
 
229
- // Trigger parent relayout if flex config or dimensions changed
230
- if (newFlexConfig || oldFlexConfig || newProps.width !== oldProps.width || newProps.height !== oldProps.height) {
231
- if (instance.parent instanceof FlexContainer) {
232
- instance.parent.updateLayout();
233
- }
248
+ // Mark ancestors dirty if flex config or dimensions changed
249
+ if (newFlexConfig || oldFlexConfig || dimensionsChanged) {
250
+ suspendWithAncestors(instance);
234
251
  }
235
252
 
236
253
  if (hasEventProps(newProps) && instance.eventMode === 'auto') {
@@ -271,8 +288,16 @@ const hostConfig: Reconciler.HostConfig<
271
288
  },
272
289
 
273
290
  resetAfterCommit() {
274
- // Flush deferred layout for all FlexContainers modified during this commit
275
- for (const fc of pendingLayoutFlush) {
291
+ if (pendingLayoutFlush.size === 0) return;
292
+
293
+ // Sort by depth (deepest first) so children compute sizes before parents lay out
294
+ const sorted = [...pendingLayoutFlush].sort((a, b) => {
295
+ let da = 0; let n: any = a; while (n.parent) { da++; n = n.parent; }
296
+ let db = 0; n = b; while (n.parent) { db++; n = n.parent; }
297
+ return db - da; // deepest first
298
+ });
299
+
300
+ for (const fc of sorted) {
276
301
  fc.resumeLayout();
277
302
  }
278
303
  pendingLayoutFlush.clear();