From d46d484bc73e8b298414c6a71a06bde6d6018c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Changhao=20Zhao=20=EF=BC=88=E8=B5=B5=E6=98=8C=E6=B5=A9?= =?UTF-8?q?=EF=BC=89?= Date: Tue, 30 Mar 2021 11:25:59 +0800 Subject: [PATCH] fix nil fragment bug --- demo/src/use-state.tsx | 12 ++++++++---- package.json | 2 +- src/reconciler.ts | 16 ++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/demo/src/use-state.tsx b/demo/src/use-state.tsx index 61298480..2c3b809c 100644 --- a/demo/src/use-state.tsx +++ b/demo/src/use-state.tsx @@ -1,11 +1,11 @@ -import { h, render, useEffect, useState } from "../../src/index" +import { h, render, useEffect, useState,Fragment } from "../../src/index" function App() { const [count, setCount] = useState(0) const [two, setTwo] = useState(0) - console.log(count, two) return ( -
+ <> + -
+ ) } +function Nil(){ + return <> +} + render(, document.body) diff --git a/package.json b/package.json index 5ea9bcc5..215032ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fre", - "version": "2.0.3", + "version": "2.0.4", "type": "module", "main": "dist/fre.js", "unpkg": "dist/fre.umd.js", diff --git a/src/reconciler.ts b/src/reconciler.ts index 9b5ca49c..3111f5bc 100644 --- a/src/reconciler.ts +++ b/src/reconciler.ts @@ -22,7 +22,7 @@ export const enum LANE { INSERT = 1 << 2, REMOVE = 1 << 3, SVG = 1 << 4, - DIRTY = 1 << 5 + DIRTY = 1 << 5, } export const render = ( vnode: FreElement, @@ -72,7 +72,7 @@ const updateHook =

(WIP: IFiber): void => { try { var children = (WIP.type as FC

)(WIP.props) } catch (e) { - if (!!e && typeof e.then === 'function') { + if (!!e && typeof e.then === "function") { const p = getParent(WIP) if (!p.laziness) { p.laziness = [] @@ -93,7 +93,7 @@ const getParentNode = (WIP: IFiber): HTMLElement | undefined => { const getParent = (WIP: IFiber): IFiber | undefined => { while ((WIP = WIP.parent)) { - if ((WIP.type as any).name === 'Suspense') return WIP + if ((WIP.type as any).name === "Suspense") return WIP } } @@ -222,13 +222,13 @@ function invokeHooks(fiber) { const { hooks, lane, laziness } = fiber if (laziness) { Promise.all(laziness).then(() => { - fiber.laziness=null + fiber.laziness = null dispatchUpdate(fiber) }) } if (hooks) { if (lane & LANE.REMOVE) { - hooks.list.forEach(e => e[2] && e[2]()) + hooks.list.forEach((e) => e[2] && e[2]()) } else { side(hooks.layout) schedule(() => side(hooks.effect)) @@ -238,7 +238,7 @@ function invokeHooks(fiber) { function wireKid(fiber) { let kid = fiber - while (isFn(kid.type)) kid = kid.child + while (isFn(kid.type) && kid.child) kid = kid.child const after = fiber.after || kid.after kid.after = after kid.lane |= fiber.lane @@ -305,8 +305,8 @@ const kidsRefer = (kids: any): void => { } const side = (effects: IEffect[]): void => { - effects.forEach(e => e[2] && e[2]()) - effects.forEach(e => e[2] = e[0]()) + effects.forEach((e) => e[2] && e[2]()) + effects.forEach((e) => (e[2] = e[0]())) effects.length = 0 }