transitive-bullshit / nextjs-notion-starter-kit

Deploy your own Notion-powered website in minutes with Next.js and Vercel.
https://transitivebullsh.it/nextjs-notion-starter-kit
MIT License
6.28k stars 5.29k forks source link

Deadly loop in getPage #634

Closed LinXueyuanStdio closed 1 month ago

LinXueyuanStdio commented 1 month ago

Description

The page that includes itself as child will cause a deadly loop.

https://www.notion.so/timecat/09636d31-6408-4f0a-84d9-ca8f1bf2d47a

{
  block: {
    '09636d31-6408-4f0a-84d9-ca8f1bf2d47a': { value: [Object], role: 'comment_only' },
    '8fb667ed-25ea-407a-839f-6f752a1298b5': { value: [Object], role: 'comment_only' },
    'd11887f4-4146-4dc9-9de1-0407ebdd4528': { value: [Object], role: 'comment_only' },
    'db0dd589-07fb-4dc7-a447-f00e938257dc': { value: [Object], role: 'comment_only' },
    'b2fce87f-4179-45d3-8f3c-06c7d8ea4caf': { value: [Object], role: 'comment_only' },
    'a2715d1a-63ff-4ae9-995f-f88580ff1e82': { value: [Object], role: 'comment_only' }
  },
  collection: {
    '42c4b602-881b-4d01-b739-0f19534993b7': { value: [Object], role: 'comment_only' },
    'acd042e6-216e-47e9-a8af-6f5031d969d1': { value: [Object], role: 'comment_only' }
  },
  collection_view: {
    'b16fd60a-6cd9-40a1-bb29-ef294a5860d6': { value: [Object], role: 'comment_only' },
    '43de0fa7-2289-4fb5-bab3-2945cb30b3a0': { value: [Object], role: 'comment_only' },
    '551d3416-16f1-4d9b-a885-3325188e59b9': { value: [Object], role: 'comment_only' },
    '92ee640c-678a-4a1e-8cb2-0efaf8b70241': { value: [Object], role: 'comment_only' },
    'f6f47f66-697c-4eec-86cf-c2104e2cdf51': { value: [Object], role: 'comment_only' },
    'd7be7d9b-35ef-4861-90b5-61a09d8e71e8': { value: [Object], role: 'comment_only' },
    '80cc1f60-b9ab-4c01-b80f-ce7a30a3a833': { value: [Object], role: 'comment_only' },
    'c334d301-aeca-4c57-aeb5-62f2b61337a2': { value: [Object], role: 'comment_only' }
  },
  notion_user: {},
  collection_query: {},
  signed_urls: {}
}

Notion Test Page ID

https://www.notion.so/timecat/09636d31-6408-4f0a-84d9-ca8f1bf2d47a

I fix it by removing its children.

get-site-map.ts

const getPage = async (pageId: string, ...args) => {
console.log('\nnotion getPage', uuidToId(pageId))
const p = await notion.getPage(pageId, ...args)
if (pageId in p.block) {
// avoiding deadly loop
p.block = {}
}
return p
}
LinXueyuanStdio commented 1 month ago

sorry