Skip to content

Commit d46d484

Browse files
committed
fix nil fragment bug
1 parent f727da6 commit d46d484

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

demo/src/use-state.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { h, render, useEffect, useState } from "../../src/index"
1+
import { h, render, useEffect, useState,Fragment } from "../../src/index"
22

33
function App() {
44
const [count, setCount] = useState(0)
55
const [two, setTwo] = useState(0)
6-
console.log(count, two)
76
return (
8-
<div>
7+
<>
8+
<Nil/>
99
<button
1010
onClick={() =>
1111
setCount((c) => {
@@ -16,8 +16,12 @@ function App() {
1616
{count}
1717
</button>
1818
<button onClick={() => setTwo(two + 1)} style="color:#2ef">{two}</button>
19-
</div>
19+
</>
2020
)
2121
}
2222

23+
function Nil(){
24+
return <></>
25+
}
26+
2327
render(<App />, document.body)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fre",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"type": "module",
55
"main": "dist/fre.js",
66
"unpkg": "dist/fre.umd.js",

src/reconciler.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const enum LANE {
2222
INSERT = 1 << 2,
2323
REMOVE = 1 << 3,
2424
SVG = 1 << 4,
25-
DIRTY = 1 << 5
25+
DIRTY = 1 << 5,
2626
}
2727
export const render = (
2828
vnode: FreElement,
@@ -72,7 +72,7 @@ const updateHook = <P = Attributes>(WIP: IFiber): void => {
7272
try {
7373
var children = (WIP.type as FC<P>)(WIP.props)
7474
} catch (e) {
75-
if (!!e && typeof e.then === 'function') {
75+
if (!!e && typeof e.then === "function") {
7676
const p = getParent(WIP)
7777
if (!p.laziness) {
7878
p.laziness = []
@@ -93,7 +93,7 @@ const getParentNode = (WIP: IFiber): HTMLElement | undefined => {
9393

9494
const getParent = (WIP: IFiber): IFiber | undefined => {
9595
while ((WIP = WIP.parent)) {
96-
if ((WIP.type as any).name === 'Suspense') return WIP
96+
if ((WIP.type as any).name === "Suspense") return WIP
9797
}
9898
}
9999

@@ -222,13 +222,13 @@ function invokeHooks(fiber) {
222222
const { hooks, lane, laziness } = fiber
223223
if (laziness) {
224224
Promise.all(laziness).then(() => {
225-
fiber.laziness=null
225+
fiber.laziness = null
226226
dispatchUpdate(fiber)
227227
})
228228
}
229229
if (hooks) {
230230
if (lane & LANE.REMOVE) {
231-
hooks.list.forEach(e => e[2] && e[2]())
231+
hooks.list.forEach((e) => e[2] && e[2]())
232232
} else {
233233
side(hooks.layout)
234234
schedule(() => side(hooks.effect))
@@ -238,7 +238,7 @@ function invokeHooks(fiber) {
238238

239239
function wireKid(fiber) {
240240
let kid = fiber
241-
while (isFn(kid.type)) kid = kid.child
241+
while (isFn(kid.type) && kid.child) kid = kid.child
242242
const after = fiber.after || kid.after
243243
kid.after = after
244244
kid.lane |= fiber.lane
@@ -305,8 +305,8 @@ const kidsRefer = (kids: any): void => {
305305
}
306306

307307
const side = (effects: IEffect[]): void => {
308-
effects.forEach(e => e[2] && e[2]())
309-
effects.forEach(e => e[2] = e[0]())
308+
effects.forEach((e) => e[2] && e[2]())
309+
effects.forEach((e) => (e[2] = e[0]()))
310310
effects.length = 0
311311
}
312312

0 commit comments

Comments
 (0)