Skip to content

fix::notion-client - Replace ky with got || fix::react-notion-x - LazyImageFull.tsx updated #646

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mustaqimarifin
Copy link

Description

Replaced KY with GOT

  • KY seems to loop infinitely in localhost for Next 15 bricking the entire session.
  • Latest version of GOT is a near 1:1 replacement

React Lazy Images

  • Very old dependencies and console warnings when using with NextJS
  • Lifted code from react-lazy-images and placed updated code and types in components/lazy-images-full.tsx
  • added react-intersection-observer and unionize

Notion Test Page ID

Can test with a local build of this fork with the examples in the monorepo.

Mustaqim Arifin and others added 2 commits June 26, 2025 19:57
1 - Replaced `KY` with `GOT` to address looping issues in NextJS
2 - Replaced `React-Lazy-Images` wtih Native Image Component
Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-notion-x ✅ Ready (Inspect) Visit Preview Aug 10, 2025 7:46am
react-notion-x-minimal-demo ✅ Ready (Inspect) Visit Preview Aug 10, 2025 7:46am

@rimonhanna
Copy link
Contributor

rimonhanna commented Jun 28, 2025

@mustaqimarifin
Copy link
Author

mustaqimarifin commented Jun 30, 2025

@mustaqimarifin collections are no longer loading: react-notion-x-minimal-demo-5sgdlsrby-saasify.vercel.app/9cb9716c93164c6c8b4cd0bac3879aeb

i think the minimal demo doesn't import 'Collections', but the full demo does? Because the full demo does indeed load Collections on my end. Thx

Left: Current React-Notion-X Test Suite || Right: Localhost

s22.mp4

@rimonhanna
Copy link
Contributor

true, double checked and all good on the full example including my personal problematic page

@rimonhanna
Copy link
Contributor

@transitive-bullshit can we merge this too?

@rimonhanna
Copy link
Contributor

@transitive-bullshit kind reminder :)

@zsolteszku
Copy link

any update?

@transitive-bullshit
Copy link
Member

there are too many unrelated changes to merge this PR.

#653 was the main fix for collection issues

@transitive-bullshit
Copy link
Member

i'm really hesitant to switch from ky to got without understanding the underlying cause of the infinite loop bug which I haven't been able to repro

@mustaqimarifin
Copy link
Author

i'm really hesitant to switch from ky to got without understanding the underlying cause of the infinite loop bug which I haven't been able to repro

totally understand. tbf, i tested it with native fetch and it works just as well. I'm not sure whats causing KY to stall out..

@Euruson
Copy link

Euruson commented Aug 5, 2025

I also met this problem with NextJS App Router.

#657 shows the details.

Comment on lines 391 to 392
image.addEventListener('load', resolve)
image.addEventListener = reject
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a critical bug in the image loading error handling. Line 387 incorrectly assigns the reject function to the addEventListener method itself instead of adding an error event listener:

image.addEventListener = reject  // incorrect

This should be changed to:

image.addEventListener('error', reject)  // correct

Without this fix, image loading errors won't be properly caught and handled, potentially causing silent failures in the application.

Suggested change
image.addEventListener('load', resolve)
image.addEventListener = reject
image.addEventListener('load', resolve)
image.addEventListener('error', reject)

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines 739 to 745
return got
.post(url, {
...kyOptions,
json: body,
headers
})
.json()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original implementation separated the HTTP request and JSON parsing with a comment noting this was to avoid sporadic errors with body reuse:

// Separate awaits to avoid sporadic errors
const res = await ky.post(url, {...});
return res.json<T>();

The new implementation with got.post().json() combines these steps, which might reintroduce the issue that was previously fixed. Consider maintaining the two-step approach:

const res = await got.post(url, {...});
return res.json();

This preserves the original fix while still using the new HTTP client.

Suggested change
return got
.post(url, {
...kyOptions,
json: body,
headers
})
.json()
const res = await got
.post(url, {
...kyOptions,
json: body,
headers
})
return res.json()

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@mustaqimarifin
Copy link
Author

mustaqimarifin commented Aug 6, 2025

Hey guys,

Had some time and tested the various fetch packages out there and ofetch works pretty well with the latest react+next packages.

Got is comparatively huge vs ky or ofetch

Screenshot 2025-08-06 at 2 02 45 PM

Very few changes needed to use ofetch over ky

/*       kyOptions: {
        timeout: {
          request: 60_000
        },
        ...kyOptions,
        searchParams: {
          src: 'initial_load'
        }
      } */

      oFetchOptions: {
        timeout: 60_000,
        ...oFetchOptions,
        params: {
          src: 'initial_load'
        }
      }


   /* const res = await ky.post(url, {
      mode: 'no-cors',
      ...this._kyOptions,
      ...kyOptions,
      json: body,
      headers
    })
    return res.json<T>()
  } */

    const res = ofetch(url, {
      method: "POST",
      mode: 'no-cors',
      ...this._oFetchOptions,
      ...oFetchOptions,
      body,
      headers
    })
    return res

Let me know if this works for everyone.

…ocal dependencies. (Fix) Replace KY with OFetch. (Fix) Cleaned up unnceccesary and erroneous changes
@mustaqimarifin
Copy link
Author

there are too many unrelated changes to merge this PR.

#653 was the main fix for collection issues

Hi all @transitive-bullshit @rimonhanna @Euruson @zsolteszku ,

Yes, apologies for the messy PR. I've rebased the PR from the latest master with just the additions as originally intended.

Happy to help if possible.

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

Successfully merging this pull request may close these issues.

5 participants