Skip to content

Commit 948b31b

Browse files
committed
Handle flexbox sometimes not parsing updates correctly when components were removed
1 parent 36ee53c commit 948b31b

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

.changeset/three-carrots-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plextv/react-lightning-plugin-flexbox": patch
3+
---
4+
5+
Handle flexbox sometimes not parsing updates correctly when components were removed

packages/plugin-flexbox/src/LightningManager.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class LightningManager {
3434
}
3535

3636
this._elements.delete(element.id);
37+
yoga.instance.applyStyle(element.id, null, true);
3738
yoga.instance.removeNode(element.id);
3839
}),
3940

@@ -95,13 +96,17 @@ export class LightningManager {
9596
private _applyUpdates = (buffer: ArrayBuffer) => {
9697
const dataView = new SimpleDataView(buffer);
9798

98-
// See YogaManagerWorker.ts for the structure of the updates
99-
while (dataView.hasSpace(1)) {
99+
// See YogaManager.ts for the structure of the updates
100+
while (dataView.hasSpace(12)) {
100101
const elementId = dataView.readUint32();
102+
const x = dataView.readInt16();
103+
const y = dataView.readInt16();
104+
const width = dataView.readUint16();
105+
const height = dataView.readUint16();
106+
101107
const el = this._elements.get(elementId);
102108

103109
if (!el) {
104-
console.warn(`Element with ID ${elementId} not found.`);
105110
continue;
106111
}
107112

@@ -121,23 +126,13 @@ export class LightningManager {
121126
}
122127

123128
if (!skipX) {
124-
dirty = el.setNodeProp('x', dataView.readInt16()) || dirty;
125-
} else {
126-
// If the x is skipped, we still need to read the value to maintain the
127-
// correct offset in the data view.
128-
dataView.moveBy(2);
129+
dirty = el.setNodeProp('x', x) || dirty;
129130
}
130131

131132
if (!skipY) {
132-
dirty = el.setNodeProp('y', dataView.readInt16()) || dirty;
133-
} else {
134-
// Same as above
135-
dataView.moveBy(2);
133+
dirty = el.setNodeProp('y', y) || dirty;
136134
}
137135

138-
const width = dataView.readUint16();
139-
const height = dataView.readUint16();
140-
141136
// If width is 0, we should not set it on the node, as it will cause
142137
// layout issues.
143138
if (width !== 0) {

packages/react-lightning/src/render/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
SdfTextRenderer,
1515
WebGlCoreRenderer,
1616
} from '@lightningjs/renderer/webgl';
17-
import type { ComponentClass, ComponentType, ReactNode } from 'react';
17+
import type { ComponentType, ReactNode } from 'react';
1818
import { createContext, createElement } from 'react';
1919
import createReconciler from 'react-reconciler';
2020
import type { LightningElement } from '../types';
@@ -76,12 +76,6 @@ const defaultOptions: Partial<RenderOptions> = {
7676
debug: false,
7777
};
7878

79-
function isReactClassComponent(
80-
ReactComponent: ComponentType<unknown>,
81-
): ReactComponent is ComponentClass<unknown> {
82-
return ReactComponent.prototype?.isReactComponent;
83-
}
84-
8579
export async function createRoot(
8680
target: string | HTMLElement,
8781
options: RenderOptions | (() => RenderOptions),

0 commit comments

Comments
 (0)