-
Notifications
You must be signed in to change notification settings - Fork 11
Export different code depending on the context (Edit, Save, or View) #11
Comments
For context, we need this (or an alternative solution to this) to be able to do things like:
|
We talked about that idea agains with @sgomes in the last week.
It's definitely something that would provide better developer experience. It must be a real struggle for plugin developers. The most recent example where it created confusion: WordPress/gutenberg#43201. |
I was just answering to that issue 😄 |
This would make me so happy 🥹
Have you considered having different, well-known paths instead ( These could be complemented with custom entries in resolve: {
mainFields: [ 'block:view', 'browser', 'module', 'main' ],
} This would then make it easier to still have variation within each directory based on the other suffixes you've mentioned. |
Yeah, I thought about it, but it seemed less flexible to me, especially when the code differences are deep inside the package and not at the root. But we could try it as well 🙂 |
Yes, it's definitely less flexible in that situation! If that turns out to be the case, then the original approach is a better fit 👍 |
Due to the direction we have taken in this initiative, exporting different code depending on the context is no longer necessary, at least for now. In addition, it could be the case that the method we use to share components between contexts is not the one based on imports as proposed in the initial post, but one closer to the directive-based templating, such as: <div class="wp-block-some-block">
<wp-rich-text text="attributes.text" />
</div> |
I've been thinking a bit about this, and the best idea that comes to my mind is to use suffixes:
file.env.js
notation, like the one used by React Native (file.native.js
,file.ios.js
andfile.android.js
) or React Server Components (file.client.js
andfile.server.js
).For example, if a person imports
RichText
like this:Webpack would bundle this:
@wordpress/block-editor/src/components/rich-text/index.edit.js
@wordpress/block-editor/src/components/rich-text/index.save.js
@wordpress/block-editor/src/components/rich-text/index.view.js
We would need to figure out:
file.native.js
)? Is there a precedent?Apart from that, does anyone have any other idea about doing this?
The text was updated successfully, but these errors were encountered: