Skip to content

Chainlit 2.6.0 - Pasting Content Has Several Additional Issues After Newlines Fix #2264

@AidanShipperley

Description

@AidanShipperley

Describe the bug

The latest Chainlit 2.6.0 release had a PR to fix input spacing issues (#2246), which attempted to address newline issues by switching from insertHTML to insertText with HTML escaping, but this created a cascade of new problems (see below). This is the fourth major issue (#1890, #2032, #2087) with input handling in the main message composer since v2.0.5 introduced inline commands, which at the time mimicked how ChatGPT rendered commands in their UI as in line with the text at the beginning of the composed message.

When we look at the Edit Message Composer in the UserMessage.tsx file, which has had no issues dealing with pasting content at all, we can see it is using AutoResizeTextarea - which is essentially a <textarea> element.

The Main Message Composer (Input.tsx), however, uses a contentEditable div with tons of custom logic for handling escaping html elements, handling pasted content properly, allowing undoing/redoing properly, spacing, etc.

The use of contentEditable is solely to support rendering the name of the user's selected command in line with the text - a feature that ChatGPT does not even use anymore. There have been continual issues in each release since v2.0.5 that significantly impact the ability for users to use Chainlit across different platforms for editing and understanding content pasted by them. It seems reasonable at this point for Chainlit to adopt an approach for commands similar to what ChatGPT does today (using buttons in combination with a toolbox under the chat input) as properly working with contentEditable across all browsers and for all content will explode the complexity of the Input.tsx file and it seems unreasonable to expect the code to handle all possible edge cases perfectly.

I will do my best to work on a PR that stops rendering the selected command inline without breaking backwards compatibility or worsening the user experience, but if there is some easy solution I missed, please feel free to let me know.


 
Below are the newly introduced issues in 2.6.0:

To Reproduce

Issue 1: HTML entities shown in composer

When pasting code containing <> or quotes, they appear as &lt;&gt; and &#039; in the composer, making it impossible to edit pasted code.

Example:

-- Pasted:
WHERE DEF <> ''

-- Shows in composer as:
WHERE DEF &lt;&gt; &#039;&#039;

Issue 2: Multiple consecutive newlines in pasted content are invisible in the composer, though they render correctly after sending

Given the following code snippet:

print("Line 1")

print("Line 3")


print("Line 6")

When pasted into the message composer, all lines are rendered right next to each other, like so:

print(&quot;Line 1&quot;)
print(&quot;Line 3&quot;)
print(&quot;Line 6&quot;)

You can also see issue 1 at work here.

Issue 3: Undo/redo broken

Undo and Redo after pasting content is now broken again, an issue previously broken and addressed.


These are just a few obvious ones I found after testing. There are several other minor issues and discrepancies with user pasted content that were not present pre-v2.0.5, when we were not using commands.

Expected behavior

Chainlit should be able to match the content pasted into it, and render user content consistently with what the user sent.

Desktop

  • OS: Windows 11
  • Browser: Microsoft Edge
  • Version: 137.0.3296.93 (Official build) (64-bit)

Sub-issues

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfrontendPertains to the frontend.staleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions