Skip to content
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

feat: support next.js out-of-the-box #3702

Closed
sebastianvitterso opened this issue Dec 10, 2024 · 0 comments · Fixed by #3703
Closed

feat: support next.js out-of-the-box #3702

sebastianvitterso opened this issue Dec 10, 2024 · 0 comments · Fixed by #3703

Comments

@sebastianvitterso
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, using the library in a Next.js-application is a bit of a hassle. In short, it simply does not allow them. There are workarounds, and generally they still require users to put the styled components inside "use client" components.

A dear friend of ours, however, recommended a solution like this:

"use client"
import styled from 'styled-components'
import { Button as EdsButton } from '@equinor/eds-core-react'

export Button as styled(EdsButton)``

In their project, that worked well.

We experimented further with this, and found that this works just as well:

"use client"
export { Button } from '@equinor/eds-core-react'

Further experimentation found that we could also just do:

"use client"
export * from '@equinor/eds-core-react'

Which let us just import EDS components from this file instead of directly from @equinor/eds-core-react.

I've made PR #3701 to solve this exact issue. However, because npm run build runs rollup before this is published as an npm package, all directives are stripped away, so the "use client" addition is removed in the js bundle.

A simple fix to this is to use Ephem/rollup-plugin-preserve-directives, (found here), which seems to be an alright rollup-plugin for keeping directives in the bundles.

Describe the solution you'd like

"use client" at the top of index.js in the bundle.

This requires:

  1. "use client" at the top of index.ts in the repo.
  2. Rollup-plugin for keeping directives in bundled code.

Describe alternatives you've considered

No others, I suppose.

Additional context

A reddit thread shortly describing nextjs, SSR and styled-components.

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

Successfully merging a pull request may close this issue.

1 participant