Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All Products block: Try hydrating #21

Merged
merged 12 commits into from
Aug 4, 2022

Conversation

ockham
Copy link
Collaborator

@ockham ockham commented Jul 26, 2022

WIP. Some early experiments, applying techniques from https://github.com/WordPress/block-hydration-experiments to the All Products block. See #20 for a vague roadmap.

To test, insert the "All Products" block into a page of your choice. View it on the frontend, and verify that it renders correctly and reacts to user interaction.

TODO:

  • Attributes aren't being serialized (as data-gutenberg-attributes). Find out why, fix.
  • Add frontend logic

@github-actions
Copy link
Contributor

The following is a bit hacky. If we stick with this techn...

The following is a bit hacky. If we stick with this technique, we might want to change apply_block_supports() to accepts a block as its argument.


// TODO: The following is a bit hacky. If we stick with this technique, we might
// want to change apply_block_supports() to accepts a block as its argument.
\WP_Block_Supports::$block_to_render = $block;
$block_supports_attributes = \WP_Block_Supports::get_instance()->apply_block_supports();
\WP_Block_Supports::$block_to_render = $previous_block_to_render;
$block_wrapper = sprintf(
'<gutenberg-interactive-block ' .
'data-gutenberg-block-type="%1$s" ' .
'data-gutenberg-uses-block-context="%2$s" ' .
'data-gutenberg-provides-block-context="%3$s" ' .
'data-gutenberg-attributes="%4$s" ' .
'data-gutenberg-sourced-attributes="%5$s" ' .
'data-gutenberg-block-props="%6$s" ' .

🚀 This comment was generated by the automations bot based on a todo comment in d7204a8 in #21. cc @ockham

@github-actions
Copy link
Contributor

Guard against unset.

Guard against unset.


"selector" => $definition['selector'], // TODO: Guard against unset.
"source" => $definition['source']
);
} else {
if ( array_key_exists ( $attr, $block['attrs'] ) ) {
$attributes[ $attr ] = $block['attrs'][$attr];
} else if ( isset( $definition['default'] ) ) {
$attributes[ $attr ] = $definition['default'];
}
}
}
}

🚀 This comment was generated by the automations bot based on a todo comment in d7204a8 in #21. cc @ockham

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2022

Size Change: -99 B (0%)

Total Size: 878 kB

Filename Size Change
build/active-filters-frontend.js 7.34 kB -2 B (0%)
build/all-products-frontend.js 18 kB -57 B (0%)
build/all-products.js 33.7 kB +29 B (0%)
build/attribute-filter-frontend.js 25.1 kB -2 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 5.06 kB -6 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB +1 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB -1 B (0%)
build/cart-blocks/filled-cart-frontend.js 782 B +2 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.62 kB -3 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.13 kB +2 B (0%)
build/cart-blocks/order-summary-fee-frontend.js 272 B -1 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.36 kB -3 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 426 B -2 B (0%)
build/cart-blocks/order-summary-subtotal-frontend.js 273 B -1 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 433 B -1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.16 kB -2 B (0%)
build/cart-frontend.js 47 kB -19 B (0%)
build/checkout-blocks/actions-frontend.js 1.41 kB -3 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.11 kB -2 B (0%)
build/checkout-blocks/billing-address-frontend.js 889 B -1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.83 kB +2 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.36 kB -4 B (0%)
build/checkout-blocks/fields-frontend.js 344 B -1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.08 kB -1 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.78 kB +2 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.25 kB -1 B (0%)
build/checkout-blocks/order-summary-fee-frontend.js 275 B -1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 605 B +3 B (0%)
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B -1 B (0%)
build/checkout-blocks/order-summary-taxes-frontend.js 432 B -1 B (0%)
build/checkout-blocks/payment-frontend.js 7.67 kB +1 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.76 kB +4 B (0%)
build/checkout-blocks/terms-frontend.js 1.22 kB +2 B (0%)
build/checkout-blocks/totals-frontend.js 325 B -1 B (0%)
build/checkout-frontend.js 49.2 kB -20 B (0%)
build/mini-cart-component-frontend.js 16.6 kB -2 B (0%)
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.68 kB +1 B (0%)
build/mini-cart-contents-block/footer-frontend.js 6.99 kB -2 B (0%)
build/mini-cart-frontend.js 1.72 kB +1 B (0%)
build/price-filter-frontend.js 13.1 kB -2 B (0%)
build/product-add-to-cart-frontend.js 6.95 kB -8 B (0%)
build/product-button-frontend.js 1.84 kB -2 B (0%)
build/product-image-frontend.js 1.84 kB -3 B (0%)
build/product-price-frontend.js 1.94 kB +4 B (0%)
build/product-sale-badge-frontend.js 1.09 kB -2 B (0%)
build/product-stock-indicator-frontend.js 1.03 kB +4 B (0%)
build/product-tag-list-frontend.js 917 B +2 B (0%)
build/product-title-frontend.js 1.29 kB +2 B (0%)
build/reviews-frontend.js 7.01 kB -4 B (0%)
build/single-product-frontend.js 21.4 kB +12 B (0%)
build/stock-filter-frontend.js 7.39 kB -2 B (0%)
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB +1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.74 kB -1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 19.1 kB -7 B (0%)
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters.js 7.99 kB
build/all-reviews.js 7.8 kB
build/attribute-filter.js 14.4 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-line-items-frontend.js 430 B
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/empty-cart-frontend.js 346 B
build/cart-blocks/order-summary-heading-frontend.js 455 B
build/cart.js 44.3 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.66 kB
build/checkout-blocks/order-summary-frontend.js 1.1 kB
build/checkout-blocks/shipping-address-frontend.js 993 B
build/checkout.js 45.5 kB
build/featured-category.js 13.2 kB
build/featured-product.js 13.5 kB
build/handpicked-products.js 7.38 kB
build/legacy-template.js 2.8 kB
build/mini-cart-contents-block/empty-cart-frontend.js 364 B
build/mini-cart-contents-block/filled-cart-frontend.js 229 B
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 289 B
build/mini-cart-contents-block/shopping-button-frontend.js 288 B
build/mini-cart-contents-block/title-frontend.js 367 B
build/mini-cart-contents.js 22.9 kB
build/mini-cart.js 6.62 kB
build/price-filter.js 9.04 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B
build/product-add-to-cart--product-button--product-image--product-title.js 2.65 kB
build/product-add-to-cart--product-button.js 564 B
build/product-add-to-cart.js 6.64 kB
build/product-best-sellers.js 7.71 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 500 B
build/product-button.js 1.09 kB
build/product-categories.js 2.78 kB
build/product-category-list-frontend.js 921 B
build/product-category-list.js 501 B
build/product-category.js 8.69 kB
build/product-image.js 1.07 kB
build/product-new.js 7.72 kB
build/product-on-sale.js 8.04 kB
build/product-price.js 1.5 kB
build/product-rating-frontend.js 1.15 kB
build/product-rating.js 731 B
build/product-sale-badge.js 678 B
build/product-search.js 2.18 kB
build/product-sku-frontend.js 380 B
build/product-sku.js 382 B
build/product-stock-indicator.js 621 B
build/product-summary-frontend.js 1.33 kB
build/product-summary.js 917 B
build/product-tag-list.js 495 B
build/product-tag.js 8.09 kB
build/product-title.js 912 B
build/product-top-rated.js 7.96 kB
build/products-by-attribute.js 8.64 kB
build/reviews-by-category.js 11.2 kB
build/reviews-by-product.js 12.3 kB
build/single-product.js 10.1 kB
build/stock-filter.js 7.3 kB
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB
build/vendors--product-add-to-cart-frontend.js 7.53 kB
build/wc-blocks-data.js 9.87 kB
build/wc-blocks-editor-style-rtl.css 5.04 kB
build/wc-blocks-editor-style.css 5.04 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-style-rtl.css 22.1 kB
build/wc-blocks-style.css 22.1 kB
build/wc-blocks-vendors-style-rtl.css 1.26 kB
build/wc-blocks-vendors-style.css 1.26 kB
build/wc-blocks-vendors.js 58.8 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@luisherranz
Copy link
Collaborator

Hey @ockham, would you mind updating the code (nomenclature) once we merge this PR? I don't want the gunteberg-xxx naming to spread if we are not finally going to use that 🙂

Thanks!!

@ockham
Copy link
Collaborator Author

ockham commented Jul 26, 2022

FWIW, I spun off a PR against the upstream repo to carry over the migration of the All Products block to block.json: woocommerce/woocommerce-blocks#6754

@ockham
Copy link
Collaborator Author

ockham commented Jul 26, 2022

Hey @ockham, would you mind updating the code (nomenclature) once we merge this PR? I don't want the gunteberg-xxx naming to spread if we are not finally going to use that 🙂

Thanks!!

Ooh, looks like I'd missed that! 😅

Sure, I'll update that once it's in!

@ockham ockham changed the title Try/hydrating all products block All Products block: Try hydrating Jul 26, 2022
@michalczaplinski michalczaplinski mentioned this pull request Jul 27, 2022
5 tasks
@ockham
Copy link
Collaborator Author

ockham commented Jul 27, 2022

Hey @ockham, would you mind updating the code (nomenclature) once we merge this PR? I don't want the gunteberg-xxx naming to spread if we are not finally going to use that 🙂
Thanks!!

Ooh, looks like I'd missed that! 😅

Sure, I'll update that once it's in!

Done in 6ade0cf.

@ockham ockham force-pushed the try/hydrating-all-products-block branch 2 times, most recently from 31ec78d to fe64a58 Compare July 28, 2022 10:34
@ockham ockham force-pushed the try/hydrating-all-products-block branch from fe64a58 to d77049b Compare July 28, 2022 10:36
@github-actions
Copy link
Contributor

Add cases for other source types.

Add cases for other source types.


// TODO: Add cases for other source types.
case 'text':
return text( sourceConfig.selector );
}
};

🚀 This comment was generated by the automations bot based on a todo comment in 23b0f51 in #21. cc @ockham

@ockham
Copy link
Collaborator Author

ockham commented Jul 29, 2022

@michalczaplinski I've merged your branch from #39 into this one and applied some minor changes (23b0f51) to use 'our' hydration technique (from the Block Hydration Experiments repo). I think it's basically working. Hooray? 🎉 😄

(I should say that it's not a very big feat since the it's not that different from the hydration technique that was previously used by the block.)

(Edit: Currently getting a block validation error in the editor -- TBH I didn't care much for backcompat and proper deprecations for the sake of this experiment 😬 )

cc/ @sunyatasattva @gigitux

@michalczaplinski
Copy link
Collaborator

Currently getting a block validation error in the editor

I think this is because of the changes to the save.js. You're not serializing the attributes in the save() anymore which makes sense because it would be redundant but at at the same time the saved markup is now different hence the validation error. I don't know which is more important: not being redundant or not showing validation errors but we can ask Woo and deal with it later 🙂

I see that some e2e tests are also failing but I think that they are failing for all PRs so this is probably unrelated. I ll try to pull the latest changes from upstream woocommerce-blocks repo to see if this was resolved.

Also, I have manually disabled (from the github UI) the generate-zipgithub action because it seems to depend on some secrets that we don't have in this repo.

@michalczaplinski
Copy link
Collaborator

In any case, it does indeed seem to work just fine 👏 😄 Nice work @ockham

Are you planning to add more changes before we can merge this?

@ockham
Copy link
Collaborator Author

ockham commented Aug 2, 2022

Currently getting a block validation error in the editor

I think this is because of the changes to the save.js. You're not serializing the attributes in the save() anymore which makes sense because it would be redundant but at at the same time the saved markup is now different hence the validation error. I don't know which is more important: not being redundant or not showing validation errors but we can ask Woo and deal with it later 🙂

Oh yeah, that's certainly the reason -- what I meant to say is that I haven't bothered to write a block deprecation to handle this just yet. I might do that though so we can merge the PR without sacrificing backwards compatibility -- should be fairly straight-forward 😄

I see that some e2e tests are also failing but I think that they are failing for all PRs so this is probably unrelated. I ll try to pull the latest changes from upstream woocommerce-blocks repo to see if this was resolved.

Thank you! AFAICS, they've been failing consistently in the upstream repo for a while 😬 (They sure were when I filed my block.json refactor PR last week.)

Also, I have manually disabled (from the github UI) the generate-zipgithub action because it seems to depend on some secrets that we don't have in this repo.

👍

@ockham
Copy link
Collaborator Author

ockham commented Aug 2, 2022

In any case, it does indeed seem to work just fine 👏 😄 Nice work @ockham

Thank you! 😊

Are you planning to add more changes before we can merge this?

I'll add that block deprecation I mentioned in my other comment 😄

@ockham
Copy link
Collaborator Author

ockham commented Aug 2, 2022

I now get

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

every now and then on the frontend. Looks like some race condition to me, probably related to registerBlockType and the StoreNoticesProvider wrapper... 😕

@michalczaplinski
Copy link
Collaborator

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

I have seen it one time as well when I ran your PR locally for the first time. But I restarted webpack and wp-env and it went away so I shrugged it off. Sounds like a race condition indeed.

Could it be that the Comp is not yet set in the blockTypes registry by the time that we run the hydration code?

@michalczaplinski
Copy link
Collaborator

michalczaplinski commented Aug 2, 2022

I can confirm that there is indeed a race condition:

2022-08-02_11-50-56.mp4

Whenever the all-products-frontend file is served from the memory cache of the browser there is no error. But when it's served from the network, there is an error.

Also, you can just put a console.log(Comp) after this line

const Comp = window.blockTypes.get( blockType );
and you'll see that whenever the error appears it will log undefined but if there's no error it will log the Comp

So, in conclusion, we have to ensure that the block registration is always run before the hydration 🙂.

@ockham
Copy link
Collaborator Author

ockham commented Aug 3, 2022

I can confirm that there is indeed a race condition:

2022-08-02_11-50-56.mp4
Whenever the all-products-frontend file is served from the memory cache of the browser there is no error. But when it's served from the network, there is an error.

Thanks a lot for confirming!

Also, you can just put a console.log(Comp) after this line

const Comp = window.blockTypes.get( blockType );

and you'll see that whenever the error appears it will log undefined but if there's no error it will log the Comp
So, in conclusion, we have to ensure that the block registration is always run before the hydration 🙂.

Fun fact, I had a console.log(Comp) on that line, but on my Intel-based Mac, it always logged the component (and no error was triggered). I think that console.log() slowed down execution enough that the component ended up being registered just in time 😅

Now on my new M1 Pro, I get undefined sometimes 😌

@michalczaplinski
Copy link
Collaborator

So, I see two ways of handling this:

  1. We could solve it ourselves by making the registerBlock asynchronous and then define a function like whenRegistered that resolves a promise when a particular block gets registered. This might look something like:
diff --git a/assets/js/base/utils/bhe-frontend.tsx b/assets/js/base/utils/bhe-frontend.tsx
index 318f02ce4..ba122be7f 100644
--- a/assets/js/base/utils/bhe-frontend.tsx
+++ b/assets/js/base/utils/bhe-frontend.tsx
@@ -72,7 +72,10 @@ Children.shouldComponentUpdate = () => false;
 
 class WpBlock extends HTMLElement {
 	connectedCallback() {
-		setTimeout( () => {
+		setTimeout( async () => {
+			const blockType = this.getAttribute( 'data-wp-block-type' );
+			await whenRegistered( blockType );
+
 			// ping the parent for the context
 			const event = new CustomEvent( 'wp-block-context', {
 				detail: {},

The caveat is that we might have to add a timeout of sorts in case the block fails to register so that this await does not get stuck forever. But that should not be a big issue (I guess) because if the block never gets registered for some reason (script fails to load, etc.) then we cannot hydrate anyway.

  1. We could make sure that the frontend.js which contains the registerBlock(MyBlock) is enqueued before the frontend file that contains the wp-block and the hydration code. I don't know enough about those enqueing mechanisms to know if this is feasible or a good idea.

What do you think @ockham ? 🙂

@ockham
Copy link
Collaborator Author

ockham commented Aug 3, 2022

Thanks a lot for your investigation @michalczaplinski -- much appreciated! ❤️

When I was thinking about the issue earlier, I was also wondering if manually introducing some asynchronicity could solve the problem. TBH I didn’t quite see how we can create a promise during block registration that the custom element listens to 🙈 but I’m super curious to see what solution you come up with! 😄

I think I was personally leaning more towards solution #2. IIRC, the block’s frontend.js is run differently (via an existing Woo-specific mechanism) than we do in BHE, so it’s no surprise if it’s not quite compatible with our approach.

@ockham
Copy link
Collaborator Author

ockham commented Aug 3, 2022

I think I was personally leaning more towards solution #2. IIRC, the block’s frontend.js is run differently (via an existing Woo-specific mechanism) than we do in BHE, so it’s no surprise if it’s not quite compatible with our approach.

I looked it up: So in BHE, we're using the block.json's viewScript field to load frontend.js (e.g.).

I haven't totally tracked it down in Woo Blocks, but I've found at least some related Webpack logic and documentation.

It seems like those frontend scripts get enqueued via AbstractBlocks (and its derived classes). Maybe this happens a bit "late"? Might be worth a try using viewScript instead 🤔

- The registry is now the instance of a BlockRegistry class.
- The BlockRegistry class has a `whenDefined()` method which is used to
 await the registration of a block with a given name.
@michalczaplinski
Copy link
Collaborator

Thanks for digging a bit deeper @ockham !

We took a look with Carlos and this is what we found:

  1. We tried to use the to use the block.json's viewScript field but to no avail. I think this might be because Woocommerce overrides the default webpack configuration so it doesn't look for those files defined in the viewScript anymore.

  2. We pinned down the problem a little more precisely. The issue is that the registerBlockType() ends up in the all-products-frontend bundle but for some reason it's placed in the bundle after the customElements.define('wp-block', WpBlock);:

    2022-08-03_22-16-31.mp4

I can't couldn't think of another way to solve this problem today so I went ahead and wrapped the block registry in a class that implements a whenRegistered() method (akin to the whenDefined() method of the customElementRegistry. The diff is in 8edc7b2.

It solves the bug and I think the code is not all that terrible 😅 I can also put it a separate PR!

@ockham
Copy link
Collaborator Author

ockham commented Aug 4, 2022

Thanks for digging a bit deeper @ockham !

We took a look with Carlos and this is what we found:

  1. We tried to use the to use the block.json's viewScript field but to no avail. I think this might be because Woocommerce overrides the default webpack configuration so it doesn't look for those files defined in the viewScript anymore.

Indeed: Woo seems to have an allowlist of scripts to look out for in a given block directory, and only those files will be built by Webpack. (Here's the code for frontend.js, for example.)

  1. We pinned down the problem a little more precisely. The issue is that the registerBlockType() ends up in the all-products-frontend bundle but for some reason it's placed in the bundle after the customElements.define('wp-block', WpBlock);:

Great sleuthing! 👍 🕵️

I can't couldn't think of another way to solve this problem today so I went ahead and wrapped the block registry in a class that implements a whenRegistered() method (akin to the whenDefined() method of the customElementRegistry. The diff is in 8edc7b2.

It solves the bug and I think the code is not all that terrible 😅 I can also put it a separate PR!

Impressive, thanks for that solution!

@ockham
Copy link
Collaborator Author

ockham commented Aug 4, 2022

Being somewhat of a die-hard minimalist (occam's razor and all 😉), I had another look at the problem, based on your findings above 😬

Essentially, customElements.define('wp-block', WpBlock); isn't wrapped in any function or class, so it's run as a side-effect whenever bhe-frontend.tsx is imported by another file. This seems problematic, since our registerBlockType() definition also lives in that file.

However, the same is true of the corresponding file in BHE, so apparently, simply importing registerBlockType() is not a problem (it's going to be used by the file that imports it to register the relevant block type, which I guess happens in time before the customElements.define() call.)

What would seem more problematic is if bhe-frontend.tsx was imported by a file that doesn't call registerBlockType() right away, since that would certainly run the customElements.define() side effect before the block is registered.

Well, turns out we're kinda doing that: https://github.com/woocommerce/woocommerce-blocks-hydration-experiments/pull/21/files#diff-b1f2eacd00a094cfdf9ca09fbfb8ea734306805ada4af1ef6042bec87c617405R10 😬

That utils file is imported by a lot of blocks. Does that mean we end up with a ton of customElements.define() calls all over the place in our build?

image

Looks like 😬

For this PR, we're only importing registerBlockType directly from bhe-frontend though, not via util -- so that line in util isn't really needed. What happens if we remove it?

diff --git a/assets/js/base/utils/index.js b/assets/js/base/utils/index.js
index 5f1aa8fd1..802954efe 100644
--- a/assets/js/base/utils/index.js
+++ b/assets/js/base/utils/index.js
@@ -7,5 +7,5 @@ export * from './get-valid-block-attributes';
 export * from './product-data';
 export * from './derive-selected-shipping-rates';
 export * from './get-icons-from-payment-methods';
-export * from './bhe-frontend';
+//export * from './bhe-frontend';
 export * from './bhe-element';

image

Better 😄


If this solution seems fragile (loading order and all), I'm pretty sure we can make it solid: We can isolate the customElements.define() side effect in a file that's never directly imported by the block developer, but only used by "the framework" (eventually Gutenberg, but for now WooCommerce Blocks) upon loading the frontend (think some wp_enqueue_script). In any case, I think we can do without a dedicated block registry 😅

@ockham ockham marked this pull request as ready for review August 4, 2022 15:16
@michalczaplinski
Copy link
Collaborator

Awesome work @ockham ! 👏

I had a lingering suspicion that this should be solved by being careful about importing modules but I didn't see how to approach it, major kudos! 🙂

With that out of the way, I think we can merge it now 🙂

@michalczaplinski michalczaplinski self-requested a review August 4, 2022 19:00
@luisherranz
Copy link
Collaborator

Sorry for being a bit late to the party, but this race condition was expected, and it is what I meant with the Make sure Frontend components are automatically hydrated even if their component is registered after the connectedCallback execution task in the BHE Tracking issue.

I'll open an issue in the BHE repository.

@luisherranz
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants