feat: Replace Yoga (asm.js) with pure TypeScript Flex layout engine#42
Draft
feat: Replace Yoga (asm.js) with pure TypeScript Flex layout engine#42
Conversation
|
|
Co-authored-by: zhanghaocong <180445+zhanghaocong@users.noreply.github.com>
- Add flex-layout.ts: pure TypeScript implementation of Flex layout - Update yoga.ts: compatibility layer using new flex-layout engine - Update render-object.ts: use YogaNode type export instead of Yoga.YogaNode - Update yoga.spec.ts: import from new modules instead of yoga-layout-prebuilt-fork - Update layout.spec.ts: replace asm.js-specific assertions with reference equality - Remove yoga-layout-prebuilt-fork dependency from packages/core/package.json Co-authored-by: zhanghaocong <180445+zhanghaocong@users.noreply.github.com>
- Create flex-layout.ts: pure TypeScript implementation of Flex layout algorithm supporting flexDirection, flexWrap, justifyContent, alignItems, alignContent, alignSelf, flexGrow, flexShrink, flexBasis, padding, margin, position, min/max dimensions, measure functions, percentage values, and display:none - Update yoga.ts: compatibility layer using new flex-layout engine - Update render-object.ts: use YogaNode type export instead of Yoga.YogaNode - Update yoga.spec.ts: import from new modules instead of yoga-layout-prebuilt-fork - Update layout.spec.ts: replace asm.js-specific assertions with reference equality - Add flex-layout.spec.ts: comprehensive tests for the new layout engine - Remove yoga-layout-prebuilt-fork dependency from packages/core/package.json Co-authored-by: zhanghaocong <180445+zhanghaocong@users.noreply.github.com>
Co-authored-by: zhanghaocong <180445+zhanghaocong@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement Flex layout using TypeScript for Canvas UI
feat: Replace Yoga (asm.js) with pure TypeScript Flex layout engine
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Yoga asm.js has inherent limitations: pre-allocated fixed linear memory with node count caps, manual memory reclamation, and an extra
_yogaNodereference on every render object that prevents clean integration with the layout pipeline.This PR replaces the
yoga-layout-prebuilt-forkdependency with a pure TypeScript flex layout implementation (~960 LOC) that provides a drop-in compatible API surface.New:
flex-layout.tsFlexNodeclass implementing the full flex layout algorithmflexDirection,flexWrap,justifyContent,alignItems/Content/Self,flexGrow/Shrink/Basis, padding, margin, absolute/relative positioning, min/max dimensions, percentage values,display:none, measure functionsfree()/freeRecursive()are no-ops — GC handles cleanupModified:
yoga.tsflex-layout.tsYoga.*constants,StyleToYogamappings, andYogaMeasuretype preservedOther changes
render-object.ts:_yogaNodetype changed fromYoga.YogaNode(namespace) to importedYogaNodetypelayout.spec.ts: Replaced__nbindPtr/__nbindFlagsasm.js pointer assertions with reference equalityyoga.spec.ts: Imports updated fromyoga-layout-prebuilt-forkto../yogayoga-layout-prebuilt-forkfrompackages/core/package.jsonTest coverage
flex-layout.spec.tscovering all supported featuresOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.