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 styles not available in custom React components with prod build

See original GitHub issue

Prerequisites

Ionic Framework Version

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

Current Behavior

We have 2 applications. We also created our own UI library of components (we store it in a separate repository and use it as an npm dependency). In UI library we use ionic components, add the styles we need and use these custom components in our applications. In applications and the UI library, we use React v17.0.2.

The problem is that if we use a component from our UI library in one of our applications, styles for ionic components disappear after build application in production. Global and additional ionic styles in applications are imported. If we run the application in development mode, everything is good with the styles. But as soon as the project is built, the styles that ionic uses disappear.

Expected Behavior

We expect that by using our custom components based on ionic components, we will be able to use them in our applications and their styles will be saved after the project is built in production.

Steps to Reproduce

Example UI component:

const SegmentWrapper = styled(IonSegment)'
    min-height: 32px; 
    --background: #d6f2f9;
';

export const SegmentLabel = styled(IonLabel)'
    font-weight: 400;
    font-size: 14px;
    line-height: 16px;
    color: #1d201f;
';

type SegmentType = {
    id: string;
    label: string;
};

type SegmentProps = {
    segments: SegmentType[];
    selected?: string;
    onChange?: (id: string) => void;
};

const Segment: FC<SegmentProps> = ({ segments, selected, onChange }) => {
  return (
    <SegmentWrapper
      scrollable
      mode="ios"
      value={selected}
      onIonChange={(e) => onChange?.(e.detail.value as string)}
    >
      {segments.map((item) => (
        <IonSegmentButton key={item.id} value={item.id}>
          <SegmentLabel>{item.label}</SegmentLabel>
        </IonSegmentButton>
      ))}
    </SegmentWrapper>
  );
};

export default Segment;

In application we use this component:

const segments: SegmentType[] = [
  { id: 'feed', label: 'Tab 1' },
  { id: 'info', label: 'Tab 2' },
];

<Segment
  segments={segments}
  selected={selectedSegment}
  onChange={setSelectedSegment}
/>

If we run npm run start we will see that the component is displayed as needed and :host styles are applied:

image image

But if we run npm run build and open production build we will see that our custom styles are present but ionic component styles are gone:

image image

Code Reproduction URL

No response

Ionic Info

image

Additional Information

Our UI library was tried to build in different ways: with rollup, only with TS, with react-script. But it doesn’t affect the build production application.

Noticed only one feature. If in our application, in any place, we use the ionic component and in another place use our custom component, then the styles do not disappear and everything is OK. But that’s not what we want, we want to use our UI

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stasdrecommented, Jul 24, 2022

Thanks. It’s really work after added setupIonicReact in our UI lib. Thank you fore help!

1reaction
liamdebeasicommented, Jul 12, 2022

Thanks. The problem appears to be that you are not calling setupIonicReact in mindly-test-ui, causing the mode to not be setup correctly. Can you add that to mindly-test-ui and let me know if that resolves the issue?

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 >
The 9 Most Common Mistakes That Ionic Developers Make
Yes, you could commit the platforms and plugins folders, but it is not recommended. When using Ionic CLI to install platforms ionic platform...
Read more >
Solve App Runtime Issues: Blank App, Plugins Not Working, etc.
Read how to solve issues such as a blank app, plugins not working, Angular change detection, and more ... Why is my custom...
Read more >
Theming & customization with Ionic - LogRocket Blog
Although the components are built to match their native counterparts, the default styles can be easily customized and themed since the framework ...
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
Unsaved Files in the Source Folder Consider an example: Suppose you want to create separate folders for each kind of file: public for...
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