From 8a84e0084fed9e5d4ee700c4887ccecf53bb83af Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 7 Mar 2024 11:42:43 +1100 Subject: [PATCH 1/2] Enqueue cable_ready actions to perform at end of reflex I think this resolves [this discussion](https://github.com/openfoodfoundation/openfoodnetwork/pull/11163#discussion_r1260531844) I guess we just didn't know [how it works](https://docs.stimulusreflex.com/guide/cableready.html#order-of-operations) before.. --- app/reflexes/products_reflex.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/reflexes/products_reflex.rb b/app/reflexes/products_reflex.rb index e6dd59e41d..dd56972517 100644 --- a/app/reflexes/products_reflex.rb +++ b/app/reflexes/products_reflex.rb @@ -116,11 +116,11 @@ class ProductsReflex < ApplicationReflex producer_options: producers, producer_id: @producer_id, category_options: categories, category_id: @category_id, flashes: flash }) - ).broadcast + ) cable_ready.replace_state( url: current_url, - ).broadcast_later + ) morph :nothing end @@ -133,7 +133,7 @@ class ProductsReflex < ApplicationReflex cable_ready.replace( selector: "#products-form", html: render(partial: "admin/products_v3/table", locals:) - ).broadcast + ) morph :nothing # dunno why this doesn't work. From 63549b3dcaac17f9404be32437b3c8c0c330b13c Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 7 Mar 2024 12:07:35 +1100 Subject: [PATCH 2/2] Add comment I still don't know why the morph method doesn't work in this context.. --- app/reflexes/products_reflex.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/reflexes/products_reflex.rb b/app/reflexes/products_reflex.rb index dd56972517..b312c74205 100644 --- a/app/reflexes/products_reflex.rb +++ b/app/reflexes/products_reflex.rb @@ -136,9 +136,8 @@ class ProductsReflex < ApplicationReflex ) morph :nothing - # dunno why this doesn't work. - # morph "#products-form", render(partial: "admin/products_v3/table", - # locals: { products: products }) + # dunno why this doesn't work. The HTML stops after the first `` element, wtf?! + # morph "#products-form", render(partial: "admin/products_v3/table", locals:) end def producers