Skip to content

A Gutenberg site's dev server serves before npm run dev has rebuilt build/, so the first wp-admin load fails #488

Closed

Description

@juanmaguitar

Description

On a Gutenberg site, Start dev server hands out the site URL while the build watcher is still wiping and regenerating build/. Opening wp-admin in the first ~20 seconds shows one of two failures, depending on the second you land on:

  • a red admin notice, Gutenberg development mode requires files to be built. Run npm install… (the plugin found no build/scripts/blocks, so it did not load lib/), or
  • a PHP fatal on any admin page: Call to undefined function gutenberg_override_style() in wp-content/plugins/gutenberg/lib/client-assets.php:148.

Reloading after the watcher prints Watching for changes fixes both. Nothing tells the contributor that, and this is the first thing they see after creating their first Gutenberg site.

Root cause. Starting the dev server starts the watcher first and hangs the server start off its readiness (startBuildWatch({ onReady }) in src/renderer/index.jsx). On a site that already has a build, readiness is immediate: startWatchProcess() runs and onReady() fires in the same tick. That is right for Core, whose grunt -- _watch touches nothing on start. Gutenberg's npm run dev is different: tools/build-scripts/dev.mjs runs clean.mjs --packages first, which removes build/ entirely, then rebuilds for about 20 s, and the generated PHP registries (build/build.php, build/styles.php, where gutenberg_override_style() is defined) are the last files written. Every request Playground serves in that window loads a complete lib/ against a missing or half-written build/.

The same window reopens whenever the watcher is started by hand while the server is up.

Step-by-step reproduction instructions

  1. Create a Gutenberg site and let the wizard finish (clone, install, build). Build watcher stopped.
  2. Click Start dev server.
  3. As soon as the URL appears, click wp-admin.

Expected: the dashboard, with Gutenberg active. Actual: the notice or the fatal above, until about 20 s later.

Fix

Gate the server start on the watcher's real readiness when the target's watcher rebuilds on start. Gutenberg gives two signals: wp-build --watch prints Watching for changes once its initial build is done, and dev.mjs writes a .dev-ready marker at the checkout root at the same moment. Core keeps starting immediately. While the watcher rebuilds, the tab reads Build watcher (building) and the dev-server button stays on Starting…; a watcher that exits before it is ready never starts the server.

Operating system

macOS (Apple Silicon). Not platform specific.

App version

Trunk at 4dbfaff, unreleased (the Gutenberg target ships in v1.2.0). Part of #251.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions