Skip to content

Commit

Permalink
fix: avoid empty placeholder flashing
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Aug 17, 2022
1 parent aab06cf commit fe55e3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions examples/chat.tsx
Expand Up @@ -71,10 +71,11 @@ function ChatList({ userId, messages = [], onSend, onReceive, placeholder }: Cha
}

const row = React.useMemo(
() => (i: number, { message, id }: { message: string; id: string }) => {
const fromUser = id === userId
return <Bubble key={i} fromUser={fromUser} text={message} />
},
() =>
(i: number, { message, id }: { message: string; id: string }) => {
const fromUser = id === userId
return <Bubble key={i} fromUser={fromUser} text={message} />
},
[userId]
)

Expand Down Expand Up @@ -127,7 +128,7 @@ function ChatList({ userId, messages = [], onSend, onReceive, placeholder }: Cha
}

const data = Array.from({ length: 130 }, (_) => ({
id: faker.random.number({ min: 1, max: 2 }).toString(),
id: faker.datatype.number({ min: 1, max: 2 }).toString(),
message: faker.lorem.sentences(),
}))

Expand Down
6 changes: 5 additions & 1 deletion examples/empty-placeholder.tsx
Expand Up @@ -10,12 +10,16 @@ export default function App() {
<Virtuoso
computeItemKey={(key) => `item-${key}`}
components={{
EmptyPlaceholder: () => <div>Nothing to See here!</div>,
EmptyPlaceholder: () => {
console.log('empty placeholder rendered')
return <div>Nothing to See here!</div>
},
}}
totalCount={totalCount}
itemContent={(index) => <div style={{ height: 30 }}>Item {index}</div>}
style={{ height: 300 }}
/>
<p>Empty placeholder should not be flashed in default rendering. check the console for logs.</p>
</div>
)
}
2 changes: 1 addition & 1 deletion src/listStateSystem.ts
Expand Up @@ -191,7 +191,7 @@ export const listStateSystem = u.system(
const { sizeTree, offsetTree } = sizesValue

if (totalCount === 0 || (startOffset === 0 && endOffset === 0)) {
return EMPTY_LIST_STATE
return { ...EMPTY_LIST_STATE, totalCount }
}

if (empty(sizeTree)) {
Expand Down

0 comments on commit fe55e3f

Please sign in to comment.