Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notion teamspace page images not rendering #119

Open
peguimasid opened this issue Mar 19, 2024 · 0 comments
Open

Notion teamspace page images not rendering #119

peguimasid opened this issue Mar 19, 2024 · 0 comments

Comments

@peguimasid
Copy link

Issue: Notion teamspace page images not rendering

Description

Notion introduced a feature called Notion Teamspace, allowing users to create subgroups and manage access to specific pages within those subgroups. However, React Notion does not currently handle images from pages within Teamspace correctly, leading to rendering issues.

Problem

When attempting to display images from pages within Notion Teamspace using React Notion, the images fail to render. This issue specifically affects uploaded images; images such as icons or those selected from Unsplash render correctly.

Solution

To address this issue, a custom function can be implemented to override React Notion's default image URL handling. The following function modifies the image URL parameters to ensure proper rendering within React Notion:

export const toNotionImageUrl: MapImageUrl = (url, block) => {
  let notionUrl = url

  if (!url.startsWith('https://www.notion.so')) {
    notionUrl = 'https://www.notion.so'.concat(
      url.startsWith('/image') ? url : `/image/${encodeURIComponent(url)}`,
    )
  }

  const imageUrl = new URL(notionUrl)

  if (block) {
     // Changed here, to switch from `table=team` to `table=block` in the url
    const table = ['space', 'team'].includes(block.value.parent_table)
      ? 'block'
      : block.value.parent_table
    imageUrl.searchParams.set('table', table)
    imageUrl.searchParams.set('id', block.value.id)
    imageUrl.searchParams.set('cache', 'v2')
  }

  return imageUrl.toString()
}

and used here:

<NotionRenderer
    blockMap={data}
    fullPage
    hideHeader
    mapImageUrl={toNotionImageUrl} // <--- Here
/>

Note: This solution has worked for me, but I cannot guarantee it is the correct one.

Additional Information

This issue affects users who utilize Notion Teamspace and attempt to display images from pages within Teamspace using React Notion. Implementing the provided solution can serve as a temporary workaround until the issue is officially resolved by the React Notion development team.

Links for Reference

These links demonstrate that the image works fine in Notion but not in React Notion, highlighting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant