transitive-bullshit/react-static-tweets

Remove next.js as peer dependency

transitive-bullshit opened this issue ยท 12 comments

react-static-tweets currently depends on next/image and next/link directly.

We should abstract these out so Next.js isn't required as a peer dependency.

There is no such package next/image, it is just a folder inside next package, so, you cannot install it separately. Moreover, you can't use it separately without NextJs because it relies on NextJs server to optimize images on demand. I guess you would need to find another solution if you want image optimization.

@sugamxp I'm aware that there's only one peer dep next.

This is just a note to myself that we need to offer a way to not depend on next directly because we currently import next/image and next/link from within react-static-tweets.

I already offer an elegant solution to working around this problem for https://github.com/NotionX/react-notion-x where the consumer of the library provides their own override for an Image and Link component instead of them being baked into the package itself. This is how I'm planning on removing next as a hard dependency from react-static-tweets while still allowing for them to be used by anyone who is using Next.js.

+1, decoupling from Next would be appreciated. Had to copy this project's source to be able to use.

Also decoupling from useSWR would be better. Personally I don't want to use it and can fetch the tweets on my own ahead of time.

There is also the problems of reading a NextJS env variable (process.env.NEXT_THING => process is undefined unless you add some webpack tweaks).

You should rather:

  • create a monorepo with multiple packages
  • have a core package that just render a tweet, allowing to customize img/link rendering with a provider (many
  • create a next specific integration package that uses the provider to inject Next Img, eventually add useSWR?

I would also vouch for removing at least next/image dependency. While I am a big fan of Vercel, I wasn't able to make next/image work with SSG (via next export). If I understand the issues (โ†“), it is not currently supported for SSG, unless a custom loader is used(?).

vercel/next.js#18356
https://github.com/vercel/next.js/discussions/19372

(It is probably possible to use SSG on the late version of next-on-netlify though: netlify/next-on-netlify@ba22d52, but I haven't test it yet.)

@slorber yep it's already a monorepo w/ multiple packages ๐Ÿ˜‰ We just need to have the core next.js parts be opt-in via a Provider as you've suggested โ€” as I've done for several of my other projects like https://github.com/NotionX/react-notion-x

Definitely lots that can be improved && very open to PRs ๐Ÿ˜„

Is this the reason why I hit an error when trying to deploy via Vercel?

image

More context around this:

  • I am developing a Next.js app (v10.0.5)
  • When installing react-static-tweets I get an error, that the package relies on Next.js 0.1.0
  • Only way to install is --force
  • Then I get the above error when trying to deploy to Vercel

@louisbarclay did you add date-fns as a dependency to your next.js app? That's what this error is saying.

@transitive-bullshit No - I didn't. Do I need to?

This would be great! We currently have a giant page of tweets and our fast-and-rough way of just embedding tweets slows it a lot.

Though i'd love to migrate the website to Next.js, we use Gatsby, so being able to use these pkgs would be great.

Is there a list of the specific changes that should be done to this project to make it Next.js-agnostic?

(Otherwise i'll have to try to extract the styled tweet component for our website. Thanks in any case!)

Since the PR title isn't very clear on this: The PR above makes this package decoupled from Next.js. #38