Skip to content

Commit

Permalink
fix nil fragment bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Mar 30, 2021
1 parent f727da6 commit d46d484
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions demo/src/use-state.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<>
<Nil/>
<button
onClick={() =>
setCount((c) => {
Expand All @@ -16,8 +16,12 @@ function App() {
{count}
</button>
<button onClick={() => setTwo(two + 1)} style="color:#2ef">{two}</button>
</div>
</>
)
}

function Nil(){
return <></>
}

render(<App />, document.body)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,7 +72,7 @@ const updateHook = <P = Attributes>(WIP: IFiber): void => {
try {
var children = (WIP.type as FC<P>)(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 = []
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d46d484

Please sign in to comment.