Skip to content

Commit f0b225b

Browse files
committed
add bench
1 parent 55d3e82 commit f0b225b

9 files changed

Lines changed: 231 additions & 44 deletions

File tree

demo/demo.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {type PortableTextComponents, PortableText} from '@portabletext/react'
1+
import {type PortableTextBlock, type PortableTextComponents, PortableText} from '@portabletext/react-latest'
22
import {studioTheme, ThemeProvider} from '@sanity/ui'
3-
import {StrictMode, useEffect, useState} from 'react'
3+
import {StrictMode, Suspense, use, useEffect, useState} from 'react'
44
import {createRoot} from 'react-dom/client'
5+
import {createClient} from '@sanity/client'
56

67
import {AnnotatedMap} from './components/AnnotatedMap'
78
import {CharacterReference} from './components/CharacterReference'
@@ -12,7 +13,7 @@ import {LinkableHeader} from './components/LinkableHeader'
1213
import {SchnauzerList} from './components/SchnauzerList'
1314
import {hasSpeechApi, SpeechSynthesis} from './components/SpeechSynthesis'
1415
import {TermDefinition} from './components/TermDefinition'
15-
import {blocks} from './fixture'
16+
// import {blocks} from './fixture'
1617

1718
/**
1819
* Note that these are statically defined (outside the scope of a function),
@@ -48,14 +49,21 @@ const ptComponents: PortableTextComponents = {
4849
},
4950
}
5051

52+
const client = createClient({projectId: 'ppsg7ml5', dataset: 'test', apiVersion: '2025-12-09', useCdn: true, perspective: 'published'})
53+
const promise = client.fetch<PortableTextBlock[]>(`*[_type == "simpleBlock" && _id == $id][0].body`, {id: '6468a09e-ce29-48d3-8b36-4b058366e6b5'})
54+
5155
function Demo() {
56+
const blocks = use(promise)
5257
const [count, setCount] = useState(0)
5358
const showingEverything = count >= blocks.length
5459
const blocksToShow = showingEverything ? blocks : blocks.slice(0, count)
5560
useEffect(() => {
56-
if (!showingEverything) {
57-
setCount(count + 1)
61+
if (showingEverything) {
62+
// setCount(count + 100)
63+
return undefined
5864
}
65+
const raf = requestAnimationFrame(() => setCount( count + 30))
66+
return () => cancelAnimationFrame(raf)
5967
}, [showingEverything, count])
6068
return <PortableText value={blocksToShow} components={ptComponents} />
6169
}
@@ -64,7 +72,9 @@ const root = createRoot(document.getElementById('demo-root')!)
6472
root.render(
6573
<StrictMode>
6674
<ThemeProvider theme={studioTheme}>
67-
<Demo />
75+
<Suspense fallback={<div>Loading...</div>}>
76+
<Demo />
77+
</Suspense>
6878
</ThemeProvider>
6979
</StrictMode>,
7080
)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"devDependencies": {
5555
"@changesets/changelog-github": "^0.5.2",
5656
"@changesets/cli": "^2.29.8",
57+
"@portabletext/react-latest": "npm:@portabletext/react@latest",
58+
"@sanity/client": "^7.13.1",
5759
"@sanity/tsconfig": "^2.0.0",
5860
"@sanity/tsdown-config": "^0.4.0",
5961
"@sanity/ui": "^3.1.11",
@@ -77,7 +79,6 @@
7779
"refractor": "^5.0.0",
7880
"rimraf": "^5.0.1",
7981
"rollup-plugin-visualizer": "^6.0.5",
80-
"@portabletext/react-latest": "npm:@portabletext/react@latest",
8182
"styled-components": "npm:@sanity/css-in-js@6.1.26",
8283
"tsdown": "^0.17.2",
8384
"typescript": "5.9.3",

0 commit comments

Comments
 (0)