Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Fix for Next.js #2

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

Fix for Next.js #2

wants to merge 12 commits into from

Conversation

Velenir
Copy link
Member

@Velenir Velenir commented Nov 23, 2020

The package doesn't work with Next.js because the way it's built it includes many dependencies in the bundle compiled for browser. So those dependencies try to access window and other stuff available in browser only, which break during SSR in Next.js

This PR includes:

  1. Some of those bundled dependencies include react (bad idea to bundle it -- causes conflicts with user version, 16 vs 17), web3 -- accesses window.btoa, popper.js used by an old version of semantic-ui would try to do something with window, and even style-loader -- for injecting styles into document.head
    For Next.js those dependencies either have to work equally in browser and in server, or -- the easier way -- leave their compilation to Next.js build (670ac93) and extract css to be included separately
  2. Put react into peerDependencies to make PWidget build independent of react version, user can use react v17 for example (a0c3d94)
  3. For reasons of Global CSS cannot be imported from files other than your Custom <App> error we have to extract all css (as semantic-ui-css is global) and leave it to the user to import 'paraswap-widget/dist/PSWidget.css' somewhere (0dc7ef7)
  4. Token images provider by the old paraswap dependency returned 404, so I updated that, which caused updatesto types and typescript(to accomodate a newer asserts type syntax in ts-essentials) (e7d63aa)
  5. Old link to logo returned 404 (362be0f)
  6. Condition in PSWidget::currentProvider was wrong and never returned window.ethereum when it was available, thus preventing any provider connection (05df2f9)
  7. types weren't exported (f74b518, 05cd029)
  8. sourcemaps weren't properly included (f74b518)

Here are example repos built with my fork of PWidget:
Next.js
Create-react-app

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

Successfully merging this pull request may close these issues.

1 participant