question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Ionic component styles do not apply in Next.js application

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

SSR/SSG of Nextjs do not work with ionic/react: “^6.0.0”. The version worked well with ionic/react 5. I have reached out to ionic community in discord and was suggested creating the issue. The styles do not apply the behaviour is odd when we use SSR or SSG. It works well on client side though.

Expected Behavior

I expect the code to work similar as it worked on version 5.9.3. All the styles do apply there.

Steps to Reproduce

  1. git clone https://github.com/MarianDabrowski/next-app
  2. cd next-app
  3. npm i
  4. npm run dev

Code Reproduction URL

https://github.com/MarianDabrowski/next-app

Ionic Info

[WARN] You are not in an Ionic project directory. Project context may be missing.

Ionic:

Ionic CLI : 6.19.0

Utility:

cordova-res : 0.15.4 native-run : not installed globally

System:

NodeJS : v17.3.1 npm : 8.5.3 OS : macOS Monterey

Additional Information

Based on the discussion with @sean-perkins I believe Sean is right saying: “…custom elements should workin SSR/SSG, so the fact that it isn’t, is a little concerning. The root issue is likely Stencil, if the styles are not being applied, but I would recommend creating a ticket in ionic-framework, since the UI kit should support Next.js.”

_app.tsx is rendered before each page render As i understand setupIonicReact shall be called at the initial stage.

Altering pages/index.tsx to

const Home: NextPage = () => {
  const [component, setComponent] = useState(<div>I Am a placeholder</div>);

  useEffect(() => {
    setTimeout(() => {
      setComponent(<App />);
    }, 3000);
  });
  return component;
};

makes the code work properly

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
sean-perkinscommented, Apr 11, 2022

Context from my discovery & our discord conversation:

The web components are being defined/registered/detected correctly when served through Next.js. The style tag for each web component is not being rendered though. There is an inline comment where the style blocks should be. This results in all the components being in a broken/styleless state.

The fact that it worked < v6, suggests it is an issue with the custom elements build.

I’ve confirmed that nothing in the Next.js project configuration points at an issue with the reproduction app, so my thoughts are that:

  1. Next.js is somehow stripping out those styles
  2. Stencil is unable to apply the styles in the right execution context with Next.js.
0reactions
MarianDabrowskicommented, Nov 9, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

css - Ionic React styles not rendering even after importing the ...
I've included the core.css file from ionic. But the components render without styles. Following is the code in my App.js import React ...
Read more >
Building a Native Mobile App with Next.js and Capacitor
In this tutorial we will start with a new Next.js app and move into native land using Capacitor and eventually also add Ionic...
Read more >
Next.js and Styled-Components: style loading issue
js app but can't get the styles to load properly? This is because the server-side rendering does not fetch the styles before rendering...
Read more >
The Correct Way to Use Ionicons in Your React Project
You will also have access to every Ionic framework component in addition to the Ionic icons. You can do dope things like use...
Read more >
Set Up Swiper.js for Angular Slides [Example] - Ionic Framework
By default, Swiper for Angular does not import any additional modules. To use modules such as Navigation or Pagination, you need to import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found