Skip to content

Commit 809f1e4

Browse files
authored
fix(notion): avoid patching react-notion-x package
Remove the dead update guide link, replace the react-notion-x patch-package patch with a local Collection wrapper, and remove patch-package from installs. Closes #4341.
1 parent bd04160 commit 809f1e4

9 files changed

Lines changed: 74 additions & 226 deletions

File tree

DEVELOPMENT.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ yarn
9595
- `yarn perf:audit:themes`:全主题性能审计(输出到 `docs/performance`)。
9696
- `yarn perf:compress-theme-previews`:批量生成主题预览 WebP 资源。
9797

98-
- `yarn postinstall`:依赖安装后自动执行 `patch-package`
99-
10098
### 代码质量工具
10199

102100
```bash
Lines changed: 29 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,44 @@
1-
import { execFileSync } from 'child_process'
1+
/** @jest-environment node */
22

3-
const renderGalleryScript = `
4-
const React = (await import('react')).default
5-
const { renderToStaticMarkup } = await import('react-dom/server')
6-
const { NotionRenderer } = await import('react-notion-x')
7-
const { Collection } = await import('react-notion-x/build/third-party/collection')
8-
const createRecordMap = ({
9-
showPageIcon,
10-
titleVisible,
11-
legacyTitleVisible
12-
}) => ({
13-
block: {
14-
collection_view: {
15-
value: { id: 'collection_view', type: 'collection_view',
16-
collection_id: 'collection', view_ids: ['gallery_view'] }
17-
},
18-
page: {
19-
value: { id: 'page', type: 'page', parent_table: 'collection',
20-
properties: { title: [['Gallery item']] },
21-
format: { page_icon: '📄' } }
22-
}
23-
},
24-
collection: {
25-
collection: {
26-
value: { id: 'collection', name: [['Gallery']],
27-
schema: { title: { name: 'Name', type: 'title' } } }
28-
}
29-
},
30-
collection_view: {
31-
gallery_view: {
32-
value: { id: 'gallery_view', type: 'gallery',
33-
format: {
34-
collection_pointer: { id: 'collection' },
35-
...(showPageIcon === undefined ? {} : { show_page_icon: showPageIcon }),
36-
...(legacyTitleVisible === undefined
37-
? {}
38-
: { gallery_title_visible: legacyTitleVisible }),
39-
gallery_cover: { type: 'none' },
40-
gallery_cover_size: 'medium',
41-
gallery_cover_aspect: 'cover',
42-
gallery_properties:
43-
titleVisible === undefined
44-
? []
45-
: [{ property: 'title', visible: titleVisible }]
46-
} }
47-
}
48-
},
49-
collection_query: {
50-
collection: {
51-
gallery_view: { collection_group_results: { blockIds: ['page'] } }
52-
}
53-
},
54-
signed_urls: {}
55-
})
56-
const renderGallery = options =>
57-
renderToStaticMarkup(
58-
React.createElement(NotionRenderer, {
59-
recordMap: createRecordMap(options),
60-
components: { Collection }
61-
})
62-
)
63-
process.stdout.write(JSON.stringify({
64-
hidden: renderGallery({ titleVisible: false }),
65-
titleVisible: renderGallery({ titleVisible: true }),
66-
enabled: renderGallery({ showPageIcon: true, titleVisible: true }),
67-
legacy: renderGallery({ legacyTitleVisible: true })
68-
}))
69-
`
3+
import { galleryVisibilityClassName } from '@/lib/notion/galleryVisibilityClassName'
704

71-
describe('Notion Gallery visibility settings', () => {
72-
const result = JSON.parse(
73-
execFileSync(process.execPath, [
74-
'--input-type=module',
75-
'-e',
76-
renderGalleryScript
77-
])
78-
)
5+
const galleryView = format => ({ type: 'gallery', format })
796

7+
describe('Notion Gallery visibility settings', () => {
808
it('hides omitted page icons and an explicitly hidden title', () => {
81-
expect(result.hidden).toContain(
82-
'notion-gallery notion-gallery-hide-page-icons notion-gallery-hide-titles'
83-
)
9+
expect(
10+
galleryVisibilityClassName(
11+
galleryView({
12+
gallery_properties: [{ property: 'title', visible: false }]
13+
})
14+
)
15+
).toBe('notion-gallery-hide-page-icons notion-gallery-hide-titles')
8416
})
8517

8618
it('keeps a visible title while the omitted page-icon setting stays hidden', () => {
87-
expect(result.titleVisible).toContain(
88-
'notion-gallery notion-gallery-hide-page-icons'
89-
)
90-
expect(result.titleVisible).not.toContain('notion-gallery-hide-titles')
19+
expect(
20+
galleryVisibilityClassName(
21+
galleryView({
22+
gallery_properties: [{ property: 'title', visible: true }]
23+
})
24+
)
25+
).toBe('notion-gallery-hide-page-icons')
9126
})
9227

9328
it('keeps page icons visible when Notion explicitly enables them', () => {
94-
expect(result.enabled).toContain('class="notion-gallery"')
95-
expect(result.enabled).not.toContain('notion-gallery-hide-page-icons')
96-
expect(result.enabled).not.toContain('notion-gallery-hide-titles')
29+
expect(
30+
galleryVisibilityClassName(
31+
galleryView({
32+
show_page_icon: true,
33+
gallery_properties: [{ property: 'title', visible: true }]
34+
})
35+
)
36+
).toBe('')
9737
})
9838

9939
it('preserves legacy Gallery data without the page-icon setting', () => {
100-
expect(result.legacy).toContain('class="notion-gallery"')
101-
expect(result.legacy).not.toContain('notion-gallery-hide-page-icons')
40+
expect(
41+
galleryVisibilityClassName(galleryView({ gallery_title_visible: true }))
42+
).toBe('')
10243
})
10344
})

components/NotionCollection.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { galleryVisibilityClassName } from '@/lib/notion/galleryVisibilityClassName'
2+
import { Collection } from 'react-notion-x/build/third-party/collection'
3+
4+
export default function NotionCollection(props) {
5+
const className = galleryVisibilityClassName(props.collectionView)
6+
7+
if (!className) return <Collection {...props} />
8+
9+
return (
10+
<div className={className}>
11+
<Collection {...props} />
12+
</div>
13+
)
14+
}

components/NotionPage.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,7 @@ const AdEmbed = dynamic(
282282
)
283283

284284
const Collection = dynamic(
285-
() =>
286-
import('react-notion-x/build/third-party/collection').then(
287-
m => m.Collection
288-
),
285+
() => import('@/components/NotionCollection'),
289286
{
290287
ssr: true
291288
}

docs/user-guide/update.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ NotionNext教程
134134
操作方式,联系小助理告知”代码付费升级“,定价是¥**9.9/**次。
135135
:::
136136

137-
- 更多手动方案,感谢网友们的分享!
138-
[NotionNext更新冲突手动解决方案 | 凌云·LinYun](https://www.linyunlink.top/article/post-240629)
139-
140137
NotionNext更新冲突?网上教程还要VS code和git?通通不需要,马上解决冲突!
141138
[047 一种更新NotionNext版本的简单方法 | Dongdong’s Blog](https://ddw2019.com/047)
142139

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function galleryVisibilityClassName(collectionView) {
2+
if (collectionView?.type !== 'gallery') return ''
3+
4+
const {
5+
gallery_properties,
6+
gallery_title_visible,
7+
show_page_icon
8+
} = collectionView.format || {}
9+
const titleProperty = gallery_properties?.find(
10+
property => property.property === 'title'
11+
)
12+
13+
return [
14+
(show_page_icon === false ||
15+
(show_page_icon == null && gallery_title_visible == null)) &&
16+
'notion-gallery-hide-page-icons',
17+
(titleProperty
18+
? titleProperty.visible === false
19+
: gallery_title_visible === false) && 'notion-gallery-hide-titles'
20+
]
21+
.filter(Boolean)
22+
.join(' ')
23+
}

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
"translate:all": "node scripts/translate/index.js --batch",
6464
"translate:check": "node scripts/translate/index.js --check-drift",
6565
"translate:backfill": "node scripts/translate/index.js --backfill",
66-
"translate:diagnose": "node scripts/translate/index.js --diagnose",
67-
"postinstall": "patch-package"
66+
"translate:diagnose": "node scripts/translate/index.js --diagnose"
6867
},
6968
"dependencies": {
7069
"@clerk/localizations": "^3.37.8",
@@ -128,7 +127,6 @@
128127
"marked": "^18.0.6",
129128
"marked-highlight": "^2.2.4",
130129
"next-sitemap": "^1.9.12",
131-
"patch-package": "^8.0.1",
132130
"postcss": "^8.5.15",
133131
"prettier": "^3.8.3",
134132
"sharp": "^0.35.0",

patches/react-notion-x+7.10.0.patch

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)