Skip to content

Commit 813539b

Browse files
fix: expose Fiber type from react-reconciler (#22)
* fix: expose Fiber type * tweaks
1 parent 2624f67 commit 813539b

7 files changed

Lines changed: 18 additions & 21 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"release": "release-it"
3939
},
4040
"dependencies": {
41-
"react-reconciler": "~0.31.0"
41+
"react-reconciler": "~0.31.0",
42+
"@types/react-reconciler": "~0.31.0"
4243
},
4344
"peerDependencies": {
4445
"react": "^19.0.0"
@@ -49,7 +50,6 @@
4950
"@release-it/conventional-changelog": "^10.0.0",
5051
"@types/jest": "^30.0.0",
5152
"@types/react": "^19.0.10",
52-
"@types/react-reconciler": "^0.28.9",
5353
"eslint": "^9.21.0",
5454
"eslint-plugin-simple-import-sort": "^12.1.1",
5555
"jest": "^30.2.0",

src/__tests__/host-element.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, jest, test } from "@jest/globals";
22

3-
import { FiberTag } from "../constants";
43
import type { HostElement } from "../host-element";
4+
import { ReactWorkTag } from "../react-constants";
55
import { createRoot } from "../renderer";
66
import { renderWithAct } from "../test-utils/render";
77

@@ -42,8 +42,8 @@ test("host elements exposes fiber instance", async () => {
4242
await renderWithAct(renderer, <div>Hello!</div>);
4343

4444
const fiber = renderer.root!.unstable_fiber!;
45-
expect(fiber.tag).toBe(FiberTag.HostComponent);
46-
expect(fiber.return!.tag).toBe(FiberTag.Root);
45+
expect(fiber.tag).toBe(ReactWorkTag.HostComponent);
46+
expect(fiber.return!.tag).toBe(ReactWorkTag.HostRoot);
4747
});
4848

4949
interface TestComponentProps {
@@ -62,6 +62,6 @@ test("can access composite parent props", async () => {
6262
expect(renderer.root!.props).toEqual({ className: "test-class", children: "Hello!" });
6363

6464
const fiber = renderer.root!.unstable_fiber!;
65-
expect(fiber.return!.tag).toBe(FiberTag.FunctionComponent);
65+
expect(fiber.return!.tag).toBe(ReactWorkTag.FunctionComponent);
6666
expect(fiber.return!.memoizedProps).toEqual({ className: "test-class", onChange: handleChange });
6767
});

src/constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,3 @@ export const Tag = {
33
Instance: "INSTANCE",
44
Text: "TEXT",
55
} as const;
6-
7-
// Source: https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactWorkTags.js#L46
8-
export const FiberTag = {
9-
FunctionComponent: 0,
10-
Root: 3,
11-
HostComponent: 5,
12-
} as const;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export type { Root, RootOptions } from "./renderer";
55
export type { HostElement, HostElementProps, HostNode } from "./host-element";
66
export type { JsonElement, JsonNode } from "./render-to-json";
77
export type { FindAllOptions } from "./find-all";
8+
9+
export type { Fiber } from "react-reconciler";

src/react-constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Source: https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactWorkTags.js#L46
2+
export const ReactWorkTag = {
3+
FunctionComponent: 0,
4+
ClassComponent: 1,
5+
HostRoot: 3,
6+
HostComponent: 5,
7+
} as const;

src/reconciler.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import type { ReactElement } from "react";
22
import type { Fiber } from "react-reconciler";
33
import ReactReconciler from "react-reconciler";
4-
import {
5-
DefaultEventPriority,
6-
// @ts-expect-error missing types
7-
NoEventPriority,
8-
} from "react-reconciler/constants";
4+
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
95

106
import { Tag } from "./constants";
117
import { formatComponentList } from "./utils";
@@ -61,7 +57,6 @@ type HostContext = {
6157

6258
const nodeToInstanceMap = new WeakMap<object, Instance>();
6359

64-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6560
let currentUpdatePriority: number = NoEventPriority;
6661

6762
const hostConfig: ReactReconciler.HostConfig<

0 commit comments

Comments
 (0)