Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upg: improve builder UX when using a template for instructions #6722

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

Fraggle
Copy link
Contributor

@Fraggle Fraggle commented Aug 9, 2024

Description

Animate as a typewriter the instructions for an assistant when using a template, then focus on it and put cursor at the end.

In respect to this comment we investigated a bit more and found a couple things:

  • editor from useEditor will mutate (eg: as part of hook dependencies) on content change (doc)
  • even when using an extension with a lower access to the input component, it still mutate.
  • hence, useMemo() (such as for xxxEditorService) will probably not do what we expect.
  • other solutions to achieve the typewriter effect will not work for multi-lines content (we cannot access individual letters)

We decided to keep the implementation like that for now and revisit later.

Enregistrement.de.l.ecran.2024-08-09.a.09.21.16.mov

Risk

A bug could led the input box to be uneditable.

Deploy Plan

Deploy front

@Fraggle Fraggle requested review from flvndvd and fontanierh August 9, 2024 09:05
Copy link
Contributor

@fontanierh fontanierh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@flvndvd flvndvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gif is 🔥, left a global comment as it might create too many re-renderings.

},
});
const editorService = useInstructionEditorService(editor);

const [letterIndex, setLetterIndex] = useState(0);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more at this, it's pretty heavy re-rendering. For each letter we will re-render this component. Either you move this outside of this component so the useEffect is not part of a rendered component but only uses the TipTap API to play the animation. This use case is also often achieve using requestanimationframe. Also I'm wondering if we could not leverage CSS styles here, with something like this:

    editor.chain()
      .setContent(`<span class="typewriter-effect">${textContent}</span>`)
      .focus("end")
      .run();

    // Set editable to false while typewriter effect is running
    editor.setEditable(false);

    // Once the animation is complete, set editable to true
    const animationDuration = 4000; // Duration should match the CSS animation duration
    const timeoutId = setTimeout(() => {
      editor.setEditable(true);
      setDoTypewriterEffect(false);
    }, animationDuration);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments and we transcript our findings in PR description.

@Fraggle Fraggle force-pushed the 1069-ux-inserting-template-instruction-text branch from 342b083 to 95c168b Compare August 9, 2024 15:25
@Fraggle Fraggle merged commit 78f7cd9 into main Aug 9, 2024
8 checks passed
@Fraggle Fraggle deleted the 1069-ux-inserting-template-instruction-text branch August 9, 2024 15:31
albandum pushed a commit that referenced this pull request Aug 28, 2024
* Upg: improve builder UX when using a template for instructions

* fix lint

* Add: comment about re-rendering cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants