Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions packages/nreact/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,25 @@ export const NotionContextProvider: React.FC<PartialNotionContext> = ({
}) => {
for (const key of Object.keys(rest)) if (rest[key] === undefined) delete rest[key]

const wrappedThemeComponents = React.useMemo(
() => ({
...themeComponents
}),
[themeComponents]
)
const wrappedThemeComponents = React.useMemo(() => {
const components = { ...themeComponents }

if (components.nextImage) components.Image = wrapNextImage(components.nextImage)

if (components.nextLink) {
const nextLink = wrapNextLink(components.nextLink)
components.nextLink = nextLink

if (wrappedThemeComponents.nextImage) wrappedThemeComponents.Image = wrapNextImage(themeComponents.nextImage)
if (!components.PageLink) components.PageLink = nextLink
if (!components.Link) components.Link = nextLink
}

if (wrappedThemeComponents.nextLink) wrappedThemeComponents.nextLink = wrapNextLink(themeComponents.nextLink)
// ensure the user can't override default components with falsy values
// since it would result in very difficult-to-debug react errors
for (const key of Object.keys(components)) if (!components[key]) delete components[key]

// ensure the user can't override default components with falsy values
// since it would result in very difficult-to-debug react errors
for (const key of Object.keys(wrappedThemeComponents)) if (!wrappedThemeComponents[key]) delete wrappedThemeComponents[key]
return components
}, [themeComponents])

const value = React.useMemo(
() => ({
Expand Down