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

add initial guide for using @wordpress packages on the frontend #15

Merged
merged 5 commits into from
Mar 17, 2022

Conversation

fabiankaegy
Copy link
Member

@fabiankaegy fabiankaegy commented Mar 3, 2022

This is the first draft of the best practice guide for working with @wordpress/packages on the frontend.

I have some questions for @nicholasio on how we can actually achieve what I am talking about here within 10up-toolkit

@fabiankaegy fabiankaegy self-assigned this Mar 3, 2022
@fabiankaegy
Copy link
Member Author

I chatted about this initial draft with @nicholasio and his main points are:

The main issue is that it feels like those packages are great for admin apps but not really websites as they aren’t very optimized

If there are a list of packages that we deem “safe” I’d be more comfortable strictly allowing them instead of being more general about using the @wordpress packages

He also uncovered that at least currently the api-fetch package depends on the url package that uses lodash which would make it not so nice to use. I will create an upstream ticket for that and see whether we can get that removed.

I will also revise the first draft to be much more conservative.

@fabiankaegy
Copy link
Member Author

I have created an issue on the Gutenberg repo for the API Fetch package relying on lodash: WordPress/gutenberg#39495

@fabiankaegy fabiankaegy requested a review from nicholasio March 16, 2022 11:13
@fabiankaegy
Copy link
Member Author

@nicholasio I have reworded the guide to what we had talked about. Would love to get your review.

Copy link
Member

@nicholasio nicholasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking good and aligned with what we discussed.

Left two minor comments,


### [`@wordpress/html-entities`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-html-entities/)

The [`@wordpress/html-entities`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-html-entities/) package is super useful when working with data from the WordPress REST API when you manually need to decode html entities because you may not want to use the `rendered` value due to having to use `innerHTML` or `dangerouslySetInnerHTML` if you are using react.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package seems to be "safe" to use on the front-end.

However, I'm not sure about the suggested use case, since the raw value that comes from the API does not include the rendered blocks AND doesn't go through WP filters it feels like this might not be a real use case. Thoughts?


There are some packages that suit themselves very well for being used outside of the editor. This list is not comprehensive and if something is not listed here it doesn't mean that it cannot be used on the frontend. These are just some good examples of packages that showed they work well on the frontend.

### [`@wordpress/dom-ready`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dom-ready/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on including a dependency for such simple utility functions versus adding it in the scaffold?

Additionally, do you know the benefits of the additional checks? I'm guessing it's accounting for a situation where the DOM is already loaded by the time your script runs so you don't need to add the callback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicholasio Yeah that exactly was my understanding of the checks.

And from my perspective, the reason why I like to use the package is just 100% consistency. I've gotten used to it in the editor and instead of having to manually use different approaches just using this simple helper just reduces the mental overload.

@fabiankaegy fabiankaegy merged commit 6ab9211 into main Mar 17, 2022
@fabiankaegy fabiankaegy deleted the add/using-wordpress-packages-on-the-frontend-guide branch November 9, 2022 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants