You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: Store changes doesn't trigger re-render of a component on dist-custom-elements build #4135
Store's state changes trigger the re-render of the components when necessary regardless of what the output target's type is or whether the component uses a local state.
Build a component that uses store with the output target's type set to dist-custom-elements
OR set the type to dist, without(!) using the local @State variable in components.
Include the library in the HTML file with a script tag
Provided Code Reproduction URL contains 3 different Stencil projects to be sure all stores are independent and don't affect components in some unexpected way.
I could work around the issue by using dist build and adding a local dummy state. Unfortunately, the component library built using Stencil is used by a third-party Angular app. That app needs to manage assets' location. Since setAssetPath is exported only in dist-custom-elements build, dist is a no-go.
If you have any ideas for workarounds or temporary solutions please share them, and I'll gladly try them out.
Thank You!
@shtolcers thank you for providing the detailed and thorough reproduction, it really helps to figure out what's going on!
I was able to confirm the issue is present, I'm going to label this so it gets ingested into our internal backlog for prioritization and whatnot.
One question - was this previously not happening in your project with earlier versions of Stencil? It would be good to know if this is a regression or a longer-standing bug.
@alicewriteswrongs Thank You! And yes, the bug was noticed on the project with "@stencil/core": "^2.17.4" and "@stencil/store": "^2.0.0", The first obvious approach was to try upgrading Stencil and store to the latest.
Hey, @alicewriteswrongs do you have some rough idea, when a fix for this could become available? We would like to understand whether we can afford to wait for a fix or we need to drop store for our particular functionality and create some workaround.
This is very crucial and impacts pretty much all minimally large Stencil components.
A position from the team would be very appreciated. Maybe community can help with this one, but as @EdgarsJoja said, we may want to drop stencil and use something else.
Confirmed we are having the same issue. It never occurred to me until I saw @rjborba 's comment about externalRuntime but setting this to false breaks the store's reactivity for us as well. That at least solves one puzzle - we had recently upgraded our React output target to take advantage of the fix posted by @christian-bromann in #4135, but that update now throws an error that externalRuntime must now be set to false there. Unfortunately that means the fix in #4135 is not actually usable yet, despite being released. I would report this there but that thread is now locked.
It looks like until this is resolved we will have to version-pin to an older release:
Pin @stencil/react-output-target to 0.6.0 in main StencilJS project.
Remove @stencil/react-output-target version ^0.7.4 from React output target project.
Revert reactOutputTarget config settings changes back to the old broken (but tolerable) settings:
...
reactOutputTarget({
// Broken in 0.7.4:
// outDir: '../verdocs-web-sdk-react/src',
// Works in 0.6.0, with hand editing between builds:
componentCorePackage: '@verdocs/web-sdk',
proxiesFile: '../verdocs-web-sdk-react/src/components.ts',
includeImportCustomElements: true,
customElementsDir: 'dist/components',
}),
{
...
// Breaks @stencil/store in recent StencilJS releases, when used with reactOutputTarget:
// externalRuntime: false,
},
...
Reacted by Rodrigo José Borba Fernandes and Fausto Quaggia
I’ve made a solution to fix that, I’ll share shortly
Basically created a decorator in the components that share stores and this
decorator became responsible to subscribe to the events and then send the
update using forceUpdate(this.host) ( element created reference)
Done that a long time ago, sorry not getting back at you earlier
I wouldn't call this a fix or workaround, but just reporting back, we "solved" this by dropping the Stencil Store completely and using a different store. Our use-case was simple so fortunately this wasn't a difficult change. We used https://tinybase.org/ for this, and "subscribe" to it in componentDidMount and "unsubscribe" in disconnectedCallback. I wouldn't call this a very "Stencil-y" way but it's working well for us so far.
I mention this only because Tinybase is a pretty sophisticated library with some additional nice-to-have functionality. Somebody with more time might perhaps come up with a decorator-style approach to provide a more streamlined integration for it in Stencil? Perhaps some day it might even replace the need to maintain the extra stencil-store library - one less burden for the core team. Just a thought.
Reacted by Christian Bromann and Rodrigo José Borba Fernandes
@christian-bromann Hi! I would love to look into it, but I'll be unable to do so for at least next month. Looks like the right approach for us will be unfortunately get rid of Stencil Store.
If this issue won't be fixed til next month, I'll start digging into it.
@christian-bromann Should this be re-marked "will not implement" or similar to assist future devs in understanding what is going on? This is not completed/fixed.
We have hit this issue (or at least a closely-related effect) and have found an acceptable workaround. We use the dist build but we've checked the workaround still works with dist-custom-elements.
Our diagnosis:
The Stencil store guidance suggests statically initializing the store in the top-level scope of the module, example). The store is therefore created at module-load time.
The store internals are set up immediately upon creation. A check made as part of this fails as getRenderingRef returns an empty object because renderingRef is not yet populated. This means that the subscriptions required to enable rerendering on store updates are never created.
Our assumption is that there is a race going on, and store initialization is occurring before callRender starts and/or completes.
Our workaround:
We delay initialization of the store until the start of globalScript execution.
Activity
alicewriteswrongs commentedon Mar 8, 2023
@shtolcers thank you for providing the detailed and thorough reproduction, it really helps to figure out what's going on!
I was able to confirm the issue is present, I'm going to label this so it gets ingested into our internal backlog for prioritization and whatnot.
One question - was this previously not happening in your project with earlier versions of Stencil? It would be good to know if this is a regression or a longer-standing bug.
shtolcers commentedon Mar 9, 2023
@alicewriteswrongs Thank You! And yes, the bug was noticed on the project with "@stencil/core": "^2.17.4" and "@stencil/store": "^2.0.0", The first obvious approach was to try upgrading Stencil and store to the latest.
EdgarsJoja commentedon Mar 13, 2023
Hey, @alicewriteswrongs do you have some rough idea, when a fix for this could become available? We would like to understand whether we can afford to wait for a fix or we need to drop store for our particular functionality and create some workaround.
malarahfelipe commentedon Apr 21, 2023
news on this? @rwaskiewicz
TheRoadSouth commentedon Oct 24, 2024
Any update on this? I think we are bumping into a similar issue.
rjborba commentedon Nov 5, 2024
This is very crucial and impacts pretty much all minimally large Stencil components.
A position from the team would be very appreciated. Maybe community can help with this one, but as @EdgarsJoja said, we may want to drop stencil and use something else.
rjborba commentedon Nov 6, 2024
FYI Issue only happens when externalRuntime is set to false
crrobinson14 commentedon Nov 20, 2024
Confirmed we are having the same issue. It never occurred to me until I saw @rjborba 's comment about
externalRuntimebut setting this to false breaks the store's reactivity for us as well. That at least solves one puzzle - we had recently upgraded our React output target to take advantage of the fix posted by @christian-bromann in #4135, but that update now throws an error thatexternalRuntimemust now be set to false there. Unfortunately that means the fix in #4135 is not actually usable yet, despite being released. I would report this there but that thread is now locked.It looks like until this is resolved we will have to version-pin to an older release:
@stencil/react-output-targetto0.6.0in main StencilJS project.@stencil/react-output-targetversion^0.7.4from React output target project.rjborba commentedon Dec 25, 2024
Should this one be closed indeed? I believe we still have this problem
christian-bromann commentedon Dec 25, 2024
@rjborba mind raising a new issue providing a reproduction case? Happy to take a look.
7 remaining items
rjborba commentedon Jan 15, 2025
@malarahfelipe I'm re-reading it now, so this solution is a workaround or something that will be integrated in Stencil core code?
christian-bromann commentedon Jan 15, 2025
@rjborba we would appreciated any contributions in this area. @malarahfelipe can you maybe share an example of your workaround?
crrobinson14 commentedon Jan 15, 2025
I wouldn't call this a fix or workaround, but just reporting back, we "solved" this by dropping the Stencil Store completely and using a different store. Our use-case was simple so fortunately this wasn't a difficult change. We used https://tinybase.org/ for this, and "subscribe" to it in
componentDidMountand "unsubscribe" indisconnectedCallback. I wouldn't call this a very "Stencil-y" way but it's working well for us so far.I mention this only because Tinybase is a pretty sophisticated library with some additional nice-to-have functionality. Somebody with more time might perhaps come up with a decorator-style approach to provide a more streamlined integration for it in Stencil? Perhaps some day it might even replace the need to maintain the extra stencil-store library - one less burden for the core team. Just a thought.
rjborba commentedon Jan 16, 2025
@christian-bromann Hi! I would love to look into it, but I'll be unable to do so for at least next month. Looks like the right approach for us will be unfortunately get rid of Stencil Store.
If this issue won't be fixed til next month, I'll start digging into it.
crrobinson14 commentedon Jan 24, 2025
@christian-bromann Should this be re-marked "will not implement" or similar to assist future devs in understanding what is going on? This is not completed/fixed.
christian-bromann commentedon Jan 24, 2025
Can you elaborate on this?
johnjenkins commentedon Jan 24, 2025
is it 'cos the fix hasn't been released yet?
crrobinson14 commentedon Jan 24, 2025
Ah maybe. Sorry, will re-check against the next release.
christian-bromann commentedon Jan 25, 2025
A fix for this has been released today as part of Stencil v4.25.1!
glennverschooren commentedon Mar 4, 2025
I'm on version 4.27.1 and still having this issue, am I the only one?
christian-bromann commentedon Mar 4, 2025
@glennverschooren can you share a minimal reproducible example?
jurienhamaker commentedon Aug 13, 2025
Still not fixed... Any updates on this?
johnjenkins commentedon Aug 13, 2025
@jurienhamaker the original reproduction use-case was fixed.
Can you open a new issue with a new repro? 🙏
stachow commentedon Sep 3, 2025
We have hit this issue (or at least a closely-related effect) and have found an acceptable workaround. We use the
distbuild but we've checked the workaround still works withdist-custom-elements.Our diagnosis:
getRenderingRefreturns an empty object becauserenderingRefis not yet populated. This means that the subscriptions required to enable rerendering on store updates are never created.callRenderstarts and/or completes.Our workaround: