Determine canonical way to declare optional dependency on store from another package. #39987
Labels
Developer Experience
Ideas about improving block and theme developer experience
[Status] Duplicate
Used to indicate that a current issue matches an existing one and can be closed
[Type] Discussion
For issues that are high-level and not yet ready to implement.
What problem does this address?
In several places of the codebase, you can see something like this:
gutenberg/packages/block-library/src/calendar/edit.js
Lines 51 to 54 in 6821d29
Technically, there's no bug to "fix" in this exact use case.
editorSelectors
will simply benull
when thecore/editor
store is not available, and the code that follows handles the null case.Still, it is awkward to access the store via string literal rather than an imported store object, and one would think that the former should be deprecated eventually. It seems like the ideal solution would be to somehow declare an optional dependency on the
@wordpress/editor
package, importing itsstore
export if available, and defaulting tonull
(orundefined
) otherwise.But how would this be done in practice? A normal ESM import declaration doesn't handle optional dependencies.
What is your proposed solution?
Dynamic imports exist, and it looks like they may be the solution. However, I do not know if our current build tooling would work with them, and them being async may pose a problem. I picture using them like so:
I'm curious what other people think of this idea.
The text was updated successfully, but these errors were encountered: