Skip to content

Prevent instantiating more than one ChatAssistant per UI #59

Description

@coderabbitai

Feature Request

It is not the intended design of the add-on to have two ChatAssistant instances loaded at the same time on the same page/UI. This should be enforced at the component level to prevent misuse and avoid subtle bugs (e.g., shared global state in client-side listeners).

Problem

Currently, nothing prevents a developer from adding multiple ChatAssistant instances to the same Vaadin UI. This can lead to unexpected behavior, including conflicts in client-side JavaScript markers (e.g., document[flag] collisions) and overlapping event listeners.

Proposed Solution

Add a guard in ChatAssistant that checks whether an instance is already registered for the current Vaadin UI and either:

  • Throws an IllegalStateException if a second instance is attached, or
  • Logs a warning and prevents initialization of the duplicate.

This check could be implemented in the onAttach lifecycle method by storing a UI-scoped reference.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions