Overview

Running canvas push after pulling pages with an older version of the CLI clears the URL alias for those pages on the remote site, making them inaccessible.

The bug was introduced in the commit that added path and description to the page spec format. Spec files pulled before that change have no path key. In packages/cli/src/utils/prepare-pages-push.ts, preparePages() reads the local spec and defaults the missing field with spec.path ?? '', producing an empty string. pushPages() then calls apiService.updatePage() with path: ''. Because the key is present in the request body, the PHP-side guard (if (!\array_key_exists($field_name, $body)) { continue; }) does not skip it, and Drupal clears the alias.

The homepage is the most visible victim: a user pulls pages, edits component props, and pushes — the homepage becomes a 404.

Proposed resolution

TypeScript — packages/cli/src/utils/prepare-pages-push.ts

In pushPages(), fall back to the remote page's path when the local spec path is empty:

await apiService.updatePage(remotePage.id, {
  title: page.title,
  description: page.description,
  status: remotePage.status,
  path: page.path || remotePage.path,
  components: page.components,
});

This preserves the existing alias for specs that pre-date the path field, and still allows the path to be updated when a new value is present in the spec.

Tests — packages/cli/src/utils/prepare-pages-push.test.ts

Add a regression test that writes an old-format spec (no path field), runs preparePages() + pushPages(), and asserts that updatePage is called with the remote path rather than an empty string.

Integration tests — packages/cli/src/services/api.integration.test.ts

Add a page operations suite covering:

  • Create a page with a path alias and verify the response includes the path.
  • List pages and confirm the created page appears with the correct path.
  • Get a single page and verify its component tree and description are returned.
  • Update a page title while keeping the same path and verify the alias is preserved.
  • Update a page's publish status and verify it is preserved.
  • Call updatePage with path: '' and assert the alias is cleared — documenting the pre-fix API behaviour.

User interface changes

None.

Issue fork canvas-3589077

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Title: canvas push clears page URL alias when spec was pulled with an older CLI version » canvas push clears the URL alias of an existing page when the local spec has no path field

wim leers’s picture

Status: Active » Needs review

Non-draft MR so setting to Needs review.

wim leers’s picture

Title: canvas push clears the URL alias of an existing page when the local spec has no path field » `canvas push` clears the URL alias of an existing page when the local spec has no path field
Issue tags: +AI-accelerated