-
Notifications
You must be signed in to change notification settings - Fork 219
Interactivity API: make current filter blocks (client-side rendered) work with client-side navigation #8456
Comments
@luisherranz, do you know how to consume a bundle as a module from a different bundle (if that's possible in Webpack)? 🤔 |
So |
I mean, are you trying to import it using something similar to this? import { navigate } from "@woocommerce/interactivity"; |
That's exactly what I'd like to do. 😅 However, by doing so, each block contains its own copy of the Interactivity API runtime―even using React instead of Preact, because the bundling process is different for these blocks. |
BTW, I did a quick test assigning EDIT: not 100% right, there are cases where the filters disappear. It happens occasionally with multiple filters at the same time |
So it seems like something is not working as expected, right? We should ping someone from Woo to take a look at why an import to |
Do you think that problem is related to the bundling or it's something different? |
It should be something different. I'm assigning the global
|
Well... we probably would have to add But don't spend time on this because we won't use full-page client-side navigation in Woo and that problem should disappear once we refactor the router to work only on the inner HTML of the Products block. Luigi, Albert: if you don't know what may be the problem, please ping someone else from Woo. Thanks 🙂 |
If the problem is very complex to solve, we can use the global variable solution. But we should name it something like |
I'm not sure I understand the issue, but it seems there is an issue with the webpack configuration. |
I'm not an expert either, but one idea would be to try using I see |
Thanks @Aljullu, I'll explore that approach. 🙏 |
Exactly what Albert said, in order to have a singleton you need to either assign the instance to some global variable (in window) or move the script to its own output build file that gets enqueued. If it's not a large file I think doing window global is better? while also making sure you're not overriding it or trying to initiate several different instances. |
This issue has been marked as |
Hi @DAreRodz Just realized this task was created awhile ago. We're currently working on this as well in our Epic woocommerce/woocommerce#42255 So checking with you if you're still working on this? |
Hey @roykho, thanks for the ping. I'm not working on this anymore (in fact, it's been a lot since I set this issue "on hold" in the Tracking Issue). I'll close this, as you're already working on your implementation for the Filter blocks. |
We must ensure that current filter blocks can use
navigate
from the Block Interactivity API to update the Products block content.The filters we need to modify are these:
They all call a function named
changeUrl()
inutils/filters.ts
.woocommerce-blocks/assets/js/utils/filters.ts
Lines 30 to 41 in 41a40fb
By modifying that function in a way that it calls the
navigate()
function from the Interactivity API when client-side navigations are enabled, we would be making all blocks update the Products block content without having to reload the whole page.The challenge here will be to make these block import
navigate
from a different bundle (the Interactivity API'sruntime
bundle).The text was updated successfully, but these errors were encountered: