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

Make the DOM ready before executing the Script #61724

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/how-to-guides/data-basics/1-data-basics-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ function MyFirstApp() {
return <span>Hello from JavaScript!</span>;
}

const root = createRoot( document.getElementById( 'my-first-gutenberg-app' ) );
window.addEventListener(
'load',
function () {
const rootDomElement = document.getElementById( 'my-first-gutenberg-app' );
const root = createRoot( rootDomElement );
root.render(
<MyFirstApp />,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,13 @@ function PagesList( { hasResolved, pages } ) {
);
}

const root = createRoot(
document.querySelector( '#my-first-gutenberg-app' )
);
window.addEventListener(
'load',
function () {
const rootDomElement = document.getElementById( 'my-first-gutenberg-app' );
const root = createRoot( rootDomElement );
root.render(
<MyFirstApp />
<MyFirstApp />,
);
},
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,5 @@ function EditPageForm( { pageId, onCancel, onSaveFinished } ) {
## What's next?

* **Previous part:** [Building a list of pages](/docs/how-to-guides/data-basics/2-building-a-list-of-pages.md)
* **Next part:** Building a *New Page* form (coming soon)
* **Next part:** [Building a *Create page form*](/docs/how-to-guides/data-basics/4-building-a-create-page-form.md)
* (optional) Review the [finished app](https://github.com/WordPress/block-development-examples/tree/trunk/plugins/data-basics-59c8f8) in the block-development-examples repository
Loading