feat: fiber architecture rewrite with lane-based scheduler and type safety#50
Merged
Conversation
MarcelOlsen
force-pushed
the
feat/fiber-rewrite
branch
from
May 2, 2026 13:06
4d9c089 to
0f92c9d
Compare
…afety BREAKING CHANGE: Replaces the old hook-based reconciler with a full fiber architecture modeled after React's internals. The public API surface remains compatible, but the internal reconciliation engine is completely new. ## New Architecture - **Fiber tree**: work-in-progress / current dual tree for interruptible renders - **Work loop**: and - **Begin / Complete work**: separate phases for building and finalizing fibers - **Commit phase**: mutation + layout effects, then passive effects flush - **Lane-based priority system**: 16-bit branded / with merge, intersect, highest-priority selection, and entanglement - **Scheduler**: binary min-heap () with , , and priority-based task ordering - **Concurrent rendering groundwork**: time-slicing ready, sync path still default ## Type Safety Hardening - Centralised unsafe-cast boundary: — all / / conversions live here; zero stray elsewhere - alias resolves impossible branded-type incompatibilities - (bitwise OR produces naturally) - Compile-time enforcement: with directives ## New Modules - — branded type conversion helpers - — binary min-heap for scheduler task queue - — work loop + sync + concurrent rendering paths - — begin work phase - — complete work phase - — DOM mutation helpers - — commit root orchestration - — priority task scheduler - — lane priority system - — child reconciliation with key-based diff - — hook implementations for fiber architecture - — effect collection and execution - — WIP tree management - — fiber factory functions - — runtime type guards and assertions - — SSR hydration support - — serialization / deserialization for SSR - — live Vite-powered browser demo ## Tests - 9 new test modules covering previously untested internals - 473 tests, 0 failures, 1,526 expectations across 38 files ## Verification ```bash bun test # 473 pass, 0 fail bun run typecheck # 0 errors ```
MarcelOlsen
force-pushed
the
feat/fiber-rewrite
branch
from
May 2, 2026 13:26
0f92c9d to
a7d6b69
Compare
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.
Overview
This PR replaces the old hook-based reconciler with a full fiber architecture modeled after React's internals. The public API surface remains compatible, but the internal reconciliation engine is completely rewritten.
Architecture
Fiber Tree
lanes(pending work),flags(side effects), andeffects(hook lifecycle)Work Loop
performSyncWorkOnRoot— synchronous render + commitperformConcurrentWorkOnRoot— time-sliced render withshouldYieldchecksensureRootIsScheduled— routes sync lanes directly, non-sync lanes via schedulerBegin / Complete Work
beginWork— builds WIP fibers from element tree, calls component functions, reconciles childrencompleteWork— finalizes host component props, creates DOM nodes, propagates effects upwardCommit Phase
commitRoot— three-pass commit: mutation (DOM changes) → layout effects → passive effects flushcommitWork.ts— DOM mutation helpers (create, insert, update, delete)commitRoot.ts— effect list traversal and execution orderLane-Based Priority System
Lane/Lanestypes with bitwise operationsmergeLanes,intersectLanes,removeLanes,getHighestPriorityLaneSyncLane,InputContinuousLane,DefaultLane,TransitionLane1/2,IdleLaneScheduler
O(log n)) for task queue instead ofArray.sort()scheduleCallback,shouldYield,cancelCallback,runWithPrioritylanesToSchedulerPriority/schedulerPriorityToLanebridgeType Safety Hardening
src/fiber/bitwise.ts— centralised unsafe-cast boundary for allLane/Lanes/Flagsconversions. Zero strayas numberelsewhere.Lanes = Lanealias — resolves impossible branded-type incompatibilities at every function boundary while keeping type branding.HookEffectTag = number— bitwise OR on effect tags naturally producesnumber; using a branded union would fail.tests/fiber/types.typecheck.tswith@ts-expect-errordirectives that fail on regression.New Modules (17 files)
src/fiber/bitwise.tssrc/fiber/minHeap.tssrc/fiber/workLoop.tssrc/fiber/beginWork.tssrc/fiber/completeWork.tssrc/fiber/commitWork.tssrc/fiber/commitRoot.tssrc/fiber/scheduler.tssrc/fiber/lanes.tssrc/fiber/childReconciler.tssrc/fiber/fiberHooks.tssrc/fiber/effectList.tssrc/fiber/workInProgress.tssrc/fiber/createFiber.tssrc/fiber/typeGuards.tssrc/fiber/hydration.tssrc/fiber/resumability.tsRemoved Modules (7 files)
src/dom-renderer/index.ts— replaced by fiber commit phasesrc/fragments/index.ts— inlined into coresrc/hooks/index.ts/src/hooks/types.ts— replaced byfiberHooks.tssrc/reconciler/index.ts— replaced by full fiber reconcilertests/MiniReact.reconciler.test.ts— superseded by fiber tests.trae/rules/project_rules.md— stale project rulesBrowser Showcase
examples/interactive-showcase/— Vite-powered live demo covering all 7 public APIs:useState— counter with historyuseEffect + useRef— interval timer with animated displayuseMemo + useCallback— filterable list with render countcreateContext + useContext— theme switchercreatePortal— floating panel outside root DOMFragment— dynamic grid columnsuseReducer— todo list with add/removeRun with:
cd examples/interactive-showcase && npx viteTest Coverage
bitwise.test.ts,minHeap.test.ts,typeGuards.test.ts,lanes.test.tsscheduler.test.ts,resumability.test.ts,hydration.test.tsfiberUtils.test.ts,commitIntegration.test.tstests/fiber/types.typecheck.tsBreaking Changes
None for the public API. All internal refactoring. Existing consumers using:
…will continue to work without changes.
Verification
Checklist
Closes the entire fiber architecture stack (fiber/lanes, fiber/scheduler, fiber/workloop, fiber/public-api, fiber/tests, fiber/type-safety).