Skip to content

Commit 4adda38

Browse files
authoredMar 12, 2024
chore: add PTE in Presentation race condition reproduction (#5961)
1 parent 334917f commit 4adda38

File tree

8 files changed

+116
-60
lines changed

8 files changed

+116
-60
lines changed
 

‎dev/test-studio/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@sanity/logos": "^2.1.2",
3636
"@sanity/migrate": "workspace:*",
3737
"@sanity/portable-text-editor": "workspace:*",
38+
"@sanity/presentation": "1.11.4",
3839
"@sanity/preview-url-secret": "^1.6.1",
3940
"@sanity/react-loader": "^1.8.3",
4041
"@sanity/tsdoc": "1.0.0-alpha.44",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {PortableText, type PortableTextComponents} from '@portabletext/react'
2+
import {type PortableTextBlock} from 'sanity'
3+
4+
import {imageBuilder, useQuery} from './loader'
5+
6+
const components: PortableTextComponents = {
7+
types: {
8+
image: ({value}) => {
9+
if (!value?.asset?._ref) {
10+
return null
11+
}
12+
return (
13+
<img
14+
alt={value.alt || ''}
15+
src={imageBuilder.image(value).width(150).height(150).fit('crop').url()}
16+
/>
17+
)
18+
},
19+
},
20+
}
21+
22+
export function SimpleBlockPortableText(): JSX.Element {
23+
const {data, loading, error} = useQuery<
24+
{
25+
_id: string
26+
title: string | null
27+
body: PortableTextBlock[]
28+
notes: {_key: string; title?: string; minutes?: number; notes?: PortableTextBlock[]}[]
29+
}[]
30+
>(/* groq */ `*[_type == "simpleBlock"]{_id,title,body,notes}`)
31+
32+
if (error) {
33+
throw error
34+
}
35+
36+
if (loading) {
37+
return <p>Loading...</p>
38+
}
39+
40+
return (
41+
<>
42+
{data?.map((item) => {
43+
return (
44+
<article
45+
key={item._id}
46+
style={{
47+
margin: '10px 20px',
48+
background: 'ghostwhite',
49+
borderRadius: '8px',
50+
border: '1px solid lightgray',
51+
padding: '10px 20px',
52+
}}
53+
>
54+
<h1>{item.title || 'Untitled'}</h1>
55+
<PortableText components={components} value={item.body} />
56+
{item.notes?.map((note) => (
57+
<div key={note._key}>
58+
<h2>{note.title}</h2>
59+
<p>{note.minutes} minutes</p>
60+
<PortableText components={components} value={note.notes || []} />
61+
</div>
62+
))}
63+
</article>
64+
)
65+
})}
66+
</>
67+
)
68+
}

‎dev/test-studio/preview/loader.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {createClient} from '@sanity/client'
2+
import imageUrlBuilder from '@sanity/image-url'
3+
import {createQueryStore} from '@sanity/react-loader'
4+
5+
const client = createClient({
6+
projectId: 'ppsg7ml5',
7+
dataset: 'playground',
8+
useCdn: true,
9+
apiVersion: '2023-02-06',
10+
stega: {
11+
enabled: true,
12+
studioUrl: '/presentation',
13+
// logger: console,
14+
filter: (props) => {
15+
return props.filterDefault(props)
16+
},
17+
},
18+
})
19+
20+
export const {useQuery, useLiveMode} = createQueryStore({client})
21+
export const imageBuilder: ReturnType<typeof imageUrlBuilder> = imageUrlBuilder(client)

‎dev/test-studio/preview/main.tsx

+4-60
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,24 @@
1-
import {PortableText} from '@portabletext/react'
2-
import {createClient} from '@sanity/client'
3-
import {createQueryStore} from '@sanity/react-loader'
41
import {enableVisualEditing} from '@sanity/visual-editing'
52
import {Suspense, useEffect} from 'react'
63
import {createRoot} from 'react-dom/client'
74

8-
const client = createClient({
9-
projectId: 'ppsg7ml5',
10-
dataset: 'playground',
11-
useCdn: true,
12-
apiVersion: '2023-02-06',
13-
stega: {
14-
enabled: true,
15-
studioUrl: '/',
16-
filter: (props) => {
17-
if (props.sourcePath[0] == 'type') {
18-
return true
19-
}
20-
return props.filterDefault(props)
21-
},
22-
},
23-
})
24-
25-
const {useQuery, useLiveMode} = createQueryStore({client})
5+
import {useLiveMode} from './loader'
6+
import {SimpleBlockPortableText} from './SimpleBlockPortableText'
267

278
function Main() {
289
return (
2910
<>
30-
<AllSchemaTypes />
11+
<SimpleBlockPortableText />
3112
<Suspense fallback={null}>
3213
<VisualEditing />
3314
</Suspense>
3415
</>
3516
)
3617
}
3718

38-
function AllSchemaTypes() {
39-
const {data, loading, error} = useQuery<any[]>(/* groq */ `*[_type == "allTypes"]`)
40-
41-
if (error) {
42-
throw error
43-
}
44-
45-
if (loading) {
46-
return <p>Loading...</p>
47-
}
48-
49-
return (
50-
<ol>
51-
{data?.map((item) => {
52-
return (
53-
<li key={item._id}>
54-
<dl>
55-
<dt>string</dt>
56-
<dd>{item.string}</dd>
57-
<dt>type</dt>
58-
<dd>{item.type}</dd>
59-
<dt>text</dt>
60-
<dd>{item.text}</dd>
61-
<dt>array</dt>
62-
<dd>{item.array?.map?.((word: any, i: number) => <span key={i}>{word}</span>)}</dd>
63-
<dt>blocks</dt>
64-
<dd>
65-
<PortableText value={item.blocks} />
66-
</dd>
67-
</dl>
68-
</li>
69-
)
70-
})}
71-
</ol>
72-
)
73-
}
74-
7519
function VisualEditing() {
7620
useEffect(() => enableVisualEditing(), [])
77-
useLiveMode({client})
21+
useLiveMode({})
7822

7923
return null
8024
}

‎dev/test-studio/sanity.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {nnNOLocale} from '@sanity/locale-nn-no'
77
import {ptPTLocale} from '@sanity/locale-pt-pt'
88
import {svSELocale} from '@sanity/locale-sv-se'
99
import {SanityMonogram} from '@sanity/logos'
10+
import {presentationTool as pinnedPresentationTool} from '@sanity/presentation'
1011
import {debugSecrets} from '@sanity/preview-url-secret/sanity-plugin-debug-secrets'
1112
import {tsdoc} from '@sanity/tsdoc/studio'
1213
import {visionTool} from '@sanity/vision'
@@ -293,8 +294,16 @@ export default defineConfig([
293294
plugins: [
294295
debugSecrets(),
295296
presentationTool({
297+
name: 'presentation',
298+
title: 'Presentation (stable)',
296299
previewUrl: '/preview/index.html',
297300
}),
301+
pinnedPresentationTool({
302+
name: 'reproduction-presentation',
303+
title: 'Presentation (reproduction)',
304+
previewUrl: '/preview/index.html',
305+
}),
306+
assist(),
298307
sharedSettings(),
299308
],
300309
basePath: '/presentation',

‎dev/test-studio/schema/standard/portableText/simpleBlock.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export default defineType({
118118
{
119119
type: 'image',
120120
name: 'image',
121+
options: {
122+
hotspot: true,
123+
},
124+
fields: [{type: 'string', name: 'alt'}],
121125
},
122126
{
123127
type: 'object',

‎pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎renovate.json

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"matchFileNames": ["package.json", "dev/**/package.json", "examples/**/package.json"],
99
"extends": [":semanticCommitTypeAll(chore)"]
1010
},
11+
{
12+
"description": "Pin Presentation in Test Studio to the version that has the agressive focus path behavior that makes race conditions easier to debug",
13+
"matchFileNames": ["dev/test-studio/package.json"],
14+
"matchDepNames": ["@sanity/presentation"],
15+
"allowedVersions": "<=1.11.4"
16+
},
1117
{
1218
"matchDepTypes": ["dependencies"],
1319
"matchPackageNames": ["get-it", "@sanity/client", "@sanity/presentation"],

0 commit comments

Comments
 (0)
Please sign in to comment.