Instruction file imported from Nizoka/pdfnative-react (
.github/instructions/reconciler.instructions.md). Copyright stays with the author.
Reconciler instructions
These files implement the React custom renderer. They are the most version- sensitive part of the codebase.
- Target the
react-reconciler@^0.31runtime with@types/react-reconciler@^0.32typings (React 19). The types are one minor ahead of the runtime — do not assume they match. host-config.tsimplements the full 0.32HostConfig(14 generic params, the last beingTransitionStatus). Many members are framework-required no-ops (suspense, hydration, transition/priority surface). Keep them; do not delete.getRootHostContext/getChildHostContextMUST return the non-nullHOST_CONTEXTsentinel. Returningnullmakes React throw "Expected host context to exist" and spin into an OOM.render.tsusesupdateContainerSync+flushSyncWork(with aflushSyncfallback).createContainertakes 11 positional args.serialize.tsis a pure transform (no side effects, no engine calls). The root must be<Document>or it throwsPdfStructureError. Stripundefinedprops viacompact()(build a new object — do notdeletekeys).- Nested lists (
toListItem): an item collects its own text from non-item/listchildren only (do not reuseelementText, which would swallow sub-item text), and returns a plainstringwhen it has no sub-items so flat lists stay byte-identical. - Layout sugar (
resolveLayout): every<Document>sugar prop folds whole intolayoutunder the engine's key — no deep merge — and an explicitlayoutprop wins. When no sugar is set and nolayoutis given the result isundefined, never{}: an empty object changes the bytes of every existing document (tests/layout-sugar.test.tsxpins it).creationDateaccepts aDateor an ISO string (toCreationDate()); an unparseable string is anE_INPUTPdfReactError, never a silent fallback to the clock.keepWithNext/splittablereach a block only when set.
- Nested lists (
nodes.tsdefines the in-memory host tree (ElementNode/TextNode).
When changing any of these, run npm test — the compile/render tests assert the
exact DocumentParams shape and real %PDF-…%%EOF output.
