Skip to content

Commit e3a1aef

Browse files
fix: from PRs
1 parent e3692b6 commit e3a1aef

File tree

7 files changed

+486
-474
lines changed

7 files changed

+486
-474
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@changesets/cli": "^2.27.9",
2727
"@fisch0920/eslint-config": "^1.4.0",
2828
"@total-typescript/ts-reset": "^0.6.1",
29-
"@types/node": "^22.8.4",
29+
"@types/node": "^22.9.0",
3030
"del-cli": "^6.0.0",
3131
"eslint": "^8.57.1",
3232
"npm-run-all2": "^7.0.1",
@@ -35,8 +35,8 @@
3535
"react-dom": "^18.3.1",
3636
"tsup": "^8.3.5",
3737
"tsx": "^4.19.2",
38-
"turbo": "^2.2.3",
38+
"turbo": "^2.3.0",
3939
"typescript": "^5.6.3",
40-
"vitest": "^2.1.4"
40+
"vitest": "^2.1.5"
4141
}
4242
}

packages/react-notion-x/src/block.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export function Block(props: BlockProps) {
8888
disableHeader
8989
} = props
9090

91-
9291
if (!block) {
9392
return null
9493
}

packages/react-notion-x/src/components/asset.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ export function Asset({
130130
let source =
131131
recordMap.signed_urls?.[block.id] || block.properties?.source?.[0]?.[0]
132132

133+
if (!source) {
134+
return null
135+
}
136+
133137
if (block.space_id) {
134138
source = source.concat('&spaceId=', block.space_id)
135139
}
136-
let content = null
137140

138-
if (!source) {
139-
return null
140-
}
141+
let content = null
141142

142143
if (block.type === 'tweet') {
143144
const src = source

packages/react-notion-x/src/components/audio.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ export function Audio({
1717
recordMap.signed_urls[block.id] || block.properties?.source?.[0]?.[0]
1818

1919
if (block.space_id) {
20-
source = source.concat('&spaceId=', block.space_id)
20+
source = source?.concat('&spaceId=', block.space_id)
2121
}
22+
23+
if (!source) {
24+
return null
25+
}
26+
2227
return (
2328
<div className={cs('notion-audio', className)}>
2429
<audio controls preload='none' src={source} />

packages/react-notion-x/src/components/file.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export function File({
1818
let source =
1919
recordMap.signed_urls[block.id] || block.properties?.source?.[0]?.[0]
2020

21+
if (!source) {
22+
return null
23+
}
24+
2125
if (block.space_id) {
2226
source = source.concat('&spaceId=', block.space_id)
2327
}

packages/react-notion-x/src/components/lite-youtube-embed.tsx

+16-17
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,33 @@ const qs = (params: Record<string, string>) => {
1111
}
1212

1313
type ImageType = 'jpg' | 'webp'
14-
// Define a type for video resolutions
15-
type VideoResolution = 120 | 320 | 480 | 640 | 1280
1614

17-
const resolutions: VideoResolution[] = [120, 320, 480, 640, 1280]
15+
const resolutions = [120, 320, 480, 640, 1280] as const
16+
type VideoResolution = (typeof resolutions)[number]
1817

1918
const resolutionMap: Record<VideoResolution, string> = {
2019
120: 'default',
2120
320: 'mqdefault',
2221
480: 'hqdefault',
2322
640: 'sddefault',
2423
1280: 'maxresdefault'
25-
// 2k, 4k, 8k images don't seem to be available
26-
// Source: https://longzero.com/articles/youtube-thumbnail-sizes-url/
24+
// 2k, 4k, 8k images don't seem to be available
25+
// Source: https://longzero.com/articles/youtube-thumbnail-sizes-url/
2726
}
2827

29-
// Function to get the poster URL based on the resolution type
28+
const resolutionSizes = resolutions
29+
.map((resolution) => `(max-width: ${resolution}px) ${resolution}px`)
30+
.join(', ')
31+
3032
function getPosterUrl(
3133
id: string,
3234
resolution: VideoResolution = 480,
3335
type: ImageType = 'jpg'
3436
): string {
35-
// Return the appropriate URL based on the image type
3637
if (type === 'webp') {
3738
return `https://i.ytimg.com/vi_webp/${id}/${resolutionMap[resolution]}.webp`
3839
}
40+
3941
// Default to jpg
4042
return `https://i.ytimg.com/vi/${id}/${resolutionMap[resolution]}.jpg`
4143
}
@@ -46,12 +48,6 @@ function generateSrcSet(id: string, type: ImageType = 'jpg'): string {
4648
.join(', ')
4749
}
4850

49-
function generateSizes(): string {
50-
return resolutions
51-
.map((resolution) => `(max-width: ${resolution}px) ${resolution}px`)
52-
.join(', ')
53-
}
54-
5551
export function LiteYouTubeEmbed({
5652
id,
5753
defaultPlay = false,
@@ -107,13 +103,13 @@ export function LiteYouTubeEmbed({
107103
{/*
108104
'it seems pretty unlikely for a browser to support preloading but not WebP images'
109105
Source: https://blog.laurenashpole.com/post/658079409151016960
110-
*/}
106+
*/}
111107
<link
112108
rel='preload'
113109
as='image'
114110
href={getPosterUrl(id)}
115111
imageSrcSet={generateSrcSet(id, 'webp')}
116-
imageSizes={generateSizes()}
112+
imageSizes={resolutionSizes}
117113
/>
118114

119115
{isPreconnected && (
@@ -128,7 +124,9 @@ export function LiteYouTubeEmbed({
128124

129125
{isPreconnected && adLinksPreconnect && (
130126
<>
131-
{/* Not certain if these ad related domains are in the critical path. Could verify with domain-specific throttling. */}
127+
{/* Not certain if these ad related domains are in the critical path.
128+
Could verify with domain-specific throttling.
129+
*/}
132130
<link rel='preconnect' href='https://static.doubleclick.net' />
133131
<link rel='preconnect' href='https://googleads.g.doubleclick.net' />
134132
</>
@@ -149,7 +147,7 @@ export function LiteYouTubeEmbed({
149147
{/*
150148
Browsers which don't support srcSet will most likely not support webp too
151149
These browsers will then just get the default 480 size jpg
152-
*/}
150+
*/}
153151
{resolutions.map((resolution) => (
154152
<source
155153
key={resolution}
@@ -158,6 +156,7 @@ export function LiteYouTubeEmbed({
158156
type='image/webp'
159157
/>
160158
))}
159+
161160
<img
162161
src={getPosterUrl(id)}
163162
className='notion-yt-thumbnail'

0 commit comments

Comments
 (0)