diff --git a/src/core/Autosizer.ts b/src/core/Autosizer.ts index 47978d14..5412401e 100644 --- a/src/core/Autosizer.ts +++ b/src/core/Autosizer.ts @@ -44,8 +44,10 @@ const getFilteredChildren = ( const filtered: CoreNode[] = []; while (children.length > 0) { const id = children.pop()!; - const child = childMap.get(id)!; - filtered.push(child); + const child = childMap.get(id); + if (child !== undefined) { + filtered.push(child); + } } return filtered; }; diff --git a/src/core/CoreTextNode.ts b/src/core/CoreTextNode.ts index 3d65dd3a..bc71dc9a 100644 --- a/src/core/CoreTextNode.ts +++ b/src/core/CoreTextNode.ts @@ -77,6 +77,28 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { private _type: 'sdf' | 'canvas' = 'sdf'; // Default to SDF renderer + /** + * Only texts whose parent transform/layout depends on measured dimensions + * need eager layout to avoid an initial position jump. + */ + private requiresLayoutForInitialTransform(props: CoreTextNodeProps): boolean { + const parent = props.parent; + if (parent === null) { + return false; + } + + if ( + parent.mountX !== 0 || + parent.mountY !== 0 || + parent.pivotX !== 0.5 || + parent.pivotY !== 0.5 + ) { + return true; + } + + return parent.autosizer !== null || parent.parentAutosizer !== null; + } + constructor( stage: Stage, props: CoreTextNodeProps, @@ -92,6 +114,16 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { this.textProps = props; this._containType = TextConstraint[props.contain]; + if ( + (props.forceLoad === true || props.parent !== null) && + this.requiresLayoutForInitialTransform(props) === true && + this.fontHandler.isFontLoaded(this.textProps.fontFamily) === true + ) { + const resp = this.textRenderer.renderText(this.textProps); + this.handleRenderResult(resp); + this._layoutGenerated = true; + } + this.setUpdateType(UpdateType.All); }