developit / nextjs-preact-demo

Next.js 9.3 + Preact = 21kB
https://nextjs-preact.now.sh
384 stars 25 forks source link

Why do you use a rather old preact-compat version? #8

Closed manuschillerdev closed 4 years ago

manuschillerdev commented 4 years ago

Hey!

I noticed, that you explicitly use a rather outdated preact-compat version. Is there any reason, why you didn't chose a current preact x version?

https://github.com/developit/nextjs-preact-demo/blob/master/package.json#L13

Thanks! :)

JoviDeCroock commented 4 years ago

This isn't the preact-compat you normally know from npm, this is a github dependency. The name might be confusing yes

https://github.com/preact-compat

manuschillerdev commented 4 years ago

@JoviDeCroock thanks.

Not sure I am understanding this yet. When I use preact compact, I alias react to compat from the regular preact/compat package like so:

"resolve": { 
    "alias": { 
      "react": "preact/compat",
      "react-dom/test-utils": "preact/test-utils",
      "react-dom": "preact/compat",
    },
  }

The package github.com/preact-compat/react used here in nextjs-preact-demo seems to be rather outdated:

Bildschirmfoto 2020-04-09 um 09 40 08

So to me it remains unclear why this github dependency was used for such a "bleeding edge" nextjs example. Just curious! :)

Thanks!

developit commented 4 years ago

@manuschillerdev the package used as an alias here is itself just an alias. It is a "proxy package" that just imports preact/compat and re-exports it:

This is necessary because npm aliases (the aliasing technique in use here) don't support subpackages (paths within packages). That meant I couldn't alias react directly to preact/compat (the compat directory inside the preact package). Instead, I aliased it to the preact-compat/react package, which just re-exports preact/compat.

It's convoluted and may be unnecessary if you copy this change.

developit commented 4 years ago

Closing for now since this might mislead folks, but I think ultimately the "fix" here is to not use npm aliases. They're nice and minimal in terms of setup, but probably confusing for updates. They also don't apply to transient dependencies, which has been causing issues for folks.

manuschillerdev commented 4 years ago

thanks! that cleared things up for me @developit Sorry for the confusion @JoviDeCroock 😄