-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update platform docs intro #61341
Update platform docs intro #61341
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @aks30498. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 @stokesman I've closed my PR (#60087) in favor of yours here as your PR is more comprehensive. Since #61486 has been merged, it's probably unnecessary to include the point about |
platform-docs/docs/intro.md
Outdated
if ( | ||
! registeredBlockTypes.length || | ||
! registeredBlockTypes.some((blockType) => blockType.name.startsWith('core/')) | ||
) registerCoreBlocks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a simpler way to do this. We're trying to teach people how to build a block editor, we should try to keep things as simple as possible. For instance is there something like ! isHMR && registerCoreBlocks()
instead of using the block package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn’t see a simple way to branch for HMR but could have missed something. Reregistering the blocks was not any fatal issue but it polluted the console quite a bit. Now that I’ve tested with the latest @wordpress
packages I’m not seeing console messages output for blocks and I don’t know why. Still, there is one that gets output for the core/footnote
format. The simplest way I thought of to avoid this is instructing that the registerCoreBlocks
call be made in src/main.jsx
.
platform-docs/docs/intro.md
Outdated
${ blocksCommonStyles } | ||
${ blocksStyles } | ||
${ blocksEditorStyles } | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we should do this for "content styles", some of these styles shouldn't be injected into the iframe and others should be injected inside and outside the iframe:
- components (in both places because of placeholders and buttons)
- block-editor/style style shouldn't be loaded in the iframe IMO (if something is not working we should fix it in gutenberg), instead it should be loaded in the app directly (so direct import here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I’d meant to revisit this and get it right.
- (if something is not working we should fix it in gutenberg)
Agreed. I can’t quite recall what style issues I’d noted. Perhaps the default block appender was not getting styled but since #66630 that doesn’t appear to be an issue.
platform-docs/docs/intro.md
Outdated
onInput={setBlocks} | ||
> | ||
<> | ||
<style>{ styles }</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid this and just do import
for the two stylesheets that need to load here. We should clarify what things are "content" styles and what things are "UI styles". I think we should add a paragraph to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. This style
tag is gone. This reason it was this way was because I’d added the ?raw
param to the their import path to tell Vite not to process them and due to that Vite won’t automatically inject them. I can’t remember if there was any issue with Vite processing them or if I just thought it was better dev performance. Now instead of doing an import
for those files I’ve instructed that they be added to index.html
(the vite-ignore
attribute will also keep them from being processed).
I know it’s not quite as simple that way but I think it may help express the difference with these UI styles versus the content styles. I also added a note hoping to help explain it, not sure if it suffices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, especially the content styles part.
platform-docs/docs/intro.md
Outdated
import blockEditorContentStyles from "@wordpress/block-editor/build-style/content.css?raw"; | ||
|
||
// Default styles that are needed for the core blocks. | ||
import blocksCommonStyles from "@wordpress/block-library/build-style/common.css?raw"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized this one was extra, it is @import
‘d in the block library’s style (the one on the next line).
platform-docs/docs/intro.md
Outdated
*/ } | ||
<BlockCanvas | ||
height="500px" | ||
styles={ [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there's any performance value in putting a stable array here (maybe define this array outside the component)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I didn't actually try the code, but this looks good to me.
I think this closes #67048 |
…61341) Unlinked contributors: aks30498. Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
closes #67048
What?
Updates the
intro.md
with some critical things that were missing for a workable build to be produced when following the guide. Among those:React
variant as part ofnpm create vite@latest
as without this JSX won’t work by default and react dependencies won’t be installed. The React variant also installs some other nice defaults like eslint with react related plugins.Details that@wordpress/block-library
expectsIS_GUTENBERG_PLUGIN
and how to provide it as without this a runtime error makes for a broken app.@wordpress/block-editor/build-style/content.css
styles
prop ofBlockCanvas
with imported content styles as without this various things won’t be styled in the canvas.Less important changes:
?raw
param to style imports to avoid Vite ever trying to process them.registerCoreBlocks()
be put insrc/main.jsx
so it won’t execute during HMR and cause errors (they are non-fatal but they sure clutter up the console).src/App.jsx
instead ofindex.jsx
because it’s what’ll exist when using theReact
variant and it also means thecreateRoot
/render
bits can be removed from the code sample.Along with that there were a some minor edits to either fix typos or try to make it read a little better.
Why?
To hopefully approach the expectation that following this guide will produce a working example in 10 minutes. From the docs homepage:
You’ll probably go well over 10 minutes if you have to discover how to fix all the gotchas you'll hit by following the guide as is.
How?
I think this is mostly covered in What. I may add some review comments.
Testing Instructions
Ensure it all looks good.