output-targets: bug: react-output-target not wrapper Ionic components since upgrade 0.6.0
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
4.22.3
Stencil Framework Output Target
React
Stencil Framework Output Target Version
0.7.4
Current Behavior
I have DS in Web Components using @ionic/core to provide wrappers to React and Vue. I am using react-ouput-target 0.5.3 and for now everything works but when I upgrade to 0.7.4 I am facing with some problems in components that use @ionic/core
Components that not uses @ionic/core is working fine
Expected Behavior
I need to keep the same current behavior
Steps to Reproduce
- Upgrade
react-output-targetto0.7.4 - Update
stencil.configto new approach - Change
tsconfigto
"module": "esnext",
"moduleResolution": "bundler",
- Generate just
esmmodules
Code Reproduction URL
Additional Information
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 14
- Comments: 25 (10 by maintainers)
@christian-bromann I’ve discovered something quite interesting that might point us in the right direction.
Looking at ionic-button, I noticed it has two distinct stylesheets -> button.md and button.ios https://github.com/ionic-team/ionic-framework/blob/2df6d2ce6ec7a16ddbeecdf748d6621b7607bc14/core/src/components/button/button.tsx#L23-L30
From what I understand, the function responsible for determining which CSS file to use is the one that gets the default Ionic “mode”: https://github.com/stenciljs/core/blob/af2acd44802b7fdc846e50846af2243d4905823c/src/runtime/mode.ts#L10 https://github.com/ionic-team/ionic-framework/blob/2df6d2ce6ec7a16ddbeecdf748d6621b7607bc14/core/src/global/ionic-global.ts#L12-L15
In the current version of react-output-target, for some reason, this default mode isn’t being set properly, which affects how component styles are selected and applied. I’ve confirmed this in the browser debugger with the new version.
When compared to the previous version’s behavior:
I’ve checked that setting the mode via stencil/core resolves this issue and restores the expected behavior.
@christian-bromann
I’ve forked the designsystem-boilerplate and created a minimal example to reproduce the issue.
Basically, I just created a global.ts to import the
"@ionic/core", added a new component my-ionic-component that uses Ionic components inside therendermethod and import it inside the React app.As you can see, the component is not rendered correctly in the React app, the wrapper of
ion-buttonis completely ignored and if check the network tab, theion-buttoncomponent is not loaded at all.This is exactly the same issue I have in my real project, where I use Ionic components inside a Stencil component and then import it into a React app. It just work well if I use a pure Stencil component without Ionic components.
But this behavior was working in the react-output-target before upgrade of 0.7.4, how you can check here
It’s enough to help you to check this issue?
@christian-bromann After further investigation, I’ve found some more important details about this issue:
In version 0.5.3, the setMode function is indeed executed by an Ionic script, as shown in the screenshots
Custom function in global script to test
The absence of defined mode and styles not being applied stems from the fact that Ionic’s global initialization function isn’t being executed in the newer version, Or more precisely, no global scripts are executed at all in the new version of the react output target.
As you can see in the new version, when I run the same setup, no global scripts isn’t executed.
In the new version, I noticed components are being defined this way:
while in the old version, the
index.js from react-output-targetexecuted the global script configured in the loaderThanks for verifying. This nails it down to this list of changes that may caused this issue. I am not entirely sure which one did cause it but it narrows down the origin of the problem.
@christian-bromann I’ve tried run with
0.6.0and I received the same errorBut if I downgraded
@stencil/react-output-targetto0.5.3it’s working wellAnother question, when trying to run my Next.js project, I encountered the following error:
Upon reviewing your designsystem-boilerplate repository, I noticed that
@stencil/react-output-targetis explicitly added within the Next.js project’s dependencies.This leads me to a question regarding best practices for distributed design systems:
Is this an ideal approach for distributed systems, given that it necessitates adding an external dependency to what is intended to be a self-contained design system?
Hi @christian-bromann, I just opened a pull request to make it easier to check the changes
Thanks!
@felipefialho thanks for providing the reproduction case. It doesn’t seem to be straightforward to mix Ionic components into Stencil components. I am seeing that Ionic components are just embedded into the projects runtime which I am not sure if that is a good thing. The biggest issue I see is that the component styles aren’t properly applied to the shadow root.
This is my current diff:
The component is loaded correctly. A shadow root was created. You can see that the Ionic component is embedded in
packages/core/components/my-ionic-component.js. The issue is that the styles aren’t applied properly.If you can provide a minimal reproducible example, I am happy to take a look.
You are making a good point here. Mind raising a separate issue for that?
@felipefialho It would be always helpful to make the reproduction case as small as possible but what you provided works to inspect the issue. I personally haven’t had the time to look into it.