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
DeepChatand pass stable references. - Move static props to module-scope constants.
- Move the
connecthandler intouseCallback; it reads the latest values via refs. - Back the
onComponentRenderguard 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:
- Open a page with Canvas AI.
- Type a prompt without submitting.
- Edit the page meta description.
- Confirm the prompt text is still present.
- Submit and confirm the request works.
AI disclosure
Drafted with AI assistance; reviewed and tested by a human.
Edited by Matt Glaman