Fix Canvas AI prompt reset on metadata changes

Issue

https://www.drupal.org/project/canvas/issues/3558257

Root cause

DeepChat received inline object and function props — images, requestBodyLimits, the connect handler, and the style objects — recreated on every render. Editing page metadata re-rendered the component, so DeepChat saw new prop references, rebuilt its input, and cleared the typed prompt.

Change

  • Memoize DeepChat and pass stable references.
  • Move static props to module-scope constants.
  • Move the connect handler into useCallback; it reads the latest values via refs.
  • Back the onComponentRender guard with a ref-backed flag instead of a render-local variable.

Handler logic is unchanged. The branch is now a single commit on current 1.x (force-pushed f6fd3076). Original work by scottfalconer and mglaman, credited via Co-authored-by.

Testing

  • Type-check, eslint, and vitest pass locally with no new failures.

Steps:

  1. Open a page with Canvas AI.
  2. Type a prompt without submitting.
  3. Edit the page meta description.
  4. Confirm the prompt text is still present.
  5. Submit and confirm the request works.

AI disclosure

Drafted with AI assistance; reviewed and tested by a human.

Edited by Matt Glaman

Merge request reports

Loading