Skip to content

Comments

refactor(dom): removes double buffering from DomBackend#138

Merged
junkdog merged 28 commits intoratatui:mainfrom
benoitlx:main
Jan 19, 2026
Merged

refactor(dom): removes double buffering from DomBackend#138
junkdog merged 28 commits intoratatui:mainfrom
benoitlx:main

Conversation

@benoitlx
Copy link
Contributor

@benoitlx benoitlx commented Nov 26, 2025

Summary

This PR reworks the DOM backend to fix several bugs and simplify its implementation.

Details

Before After
Capture d'écran 2025-11-25 115036 Capture d'écran 2025-11-25 115258

Test

TODO

Explanation

  • rendering of the content:

    • Initialize the <span> elements once with the populate function (similar to the prerender function)
    • When new content is given to the draw function:
      • if it's a two width char render it and add width: 2ch to style attribute of the corresponding <span>, render a blank char to the following span with width 0.
      • otherwise just render the content
  • resizing:

    • added a get_size function in utils.rs (that works like get_sized_buffer)
    • added a size field in DomBackend initialized to the output of get_size
    • reupdate the size so ratatui modify it's buffer size in the size function with get_size
  • cursor:

    • added a last_cursor_position field to DomBackend
    • directly modify the style of the span at cursor_position and last_cursor_position

@benoitlx benoitlx changed the title refactor(dom): remove double buffering from DomBackend struct refactor(dom): removes double buffering from DomBackend struct Nov 26, 2025
@benoitlx benoitlx changed the title refactor(dom): removes double buffering from DomBackend struct refactor(dom): removes double buffering from DomBackend Nov 26, 2025
@benoitlx benoitlx mentioned this pull request Nov 28, 2025
5 tasks
@orhun
Copy link
Member

orhun commented Nov 30, 2025

Nice, looking pretty good already. Let me know when this is ready for a review :)

@benoitlx
Copy link
Contributor Author

benoitlx commented Dec 1, 2025

I added the example from #121.

image

Also I removed this

if cell.modifier.contains(HYPERLINK_MODIFIER) {
    continue;
}

so that hyperlinks are rendered even if they are not supported after this PR. (the create_anchor function is unused for now)
If this PR is merged, I might submit another one to add proper hyperlink support.

I’m excited to hear your feedback!

@benoitlx benoitlx marked this pull request as ready for review December 1, 2025 13:17
@benoitlx
Copy link
Contributor Author

benoitlx commented Jan 6, 2026

Hi, let me know when you can review this. I have some time to work on changes if needed :)

junkdog

This comment was marked as duplicate.

@junkdog
Copy link
Member

junkdog commented Jan 6, 2026

there's a slight perf regression - framerate is 10-15% lower

but also more stable framerate

@orhun orhun self-requested a review January 6, 2026 20:59
Copy link
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I'm experiencing some issues while running this. (see the video that I attached)

@orhun
Copy link
Member

orhun commented Jan 9, 2026

I'm running from aeec0fe now and the unicode example looks like this (still):

Peek.2026-01-09.17-42.mp4

Only the DOM backend is a bit broken.

Environment:

  • Mozilla Firefox 146.0
  • rustc 1.94.0-nightly (f52090008 2025-12-10)
  • trunk 0.21.14

@benoitlx
Copy link
Contributor Author

I'm running from aeec0fe now and the unicode example looks like this (still):
Peek.2026-01-09.17-42.mp4

Only the DOM backend is a bit broken.

Environment:

* Mozilla Firefox 146.0

* rustc 1.94.0-nightly (f52090008 2025-12-10)

* trunk 0.21.14

Uhm, that's bad, I can't reproduce this issue. I'm using trunk and rustc with the same version you specified. However, I'm running Firefox version 146.0.1 (I can't install a specific version at the moment).

Do you have any other idea that can help me reproduce this bug ?

@orhun
Copy link
Member

orhun commented Jan 12, 2026

Okay I figured it out... nothing wrong with the code.

I had the Translate Web Pages plugin installed which automatically translates the Japanese characters which then breaks the layout...

I disabled the plugin and now it all works fine!

@benoitlx
Copy link
Contributor Author

I disabled the plugin and now it all works fine!

Nice !

I will refactor the update_css_field function and write unit tests for it. I will request a new review when I'm done.

@orhun
Copy link
Member

orhun commented Jan 12, 2026

cool, thanks!

@benoitlx benoitlx requested review from junkdog and orhun January 14, 2026 08:56
Copy link
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

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

Looks pretty good!

Would love to get another review from @junkdog and it should be good to go :)

@benoitlx
Copy link
Contributor Author

Everything should be fixed now, but let's see if junkdog will spot something :)
Thanks for your helpful review, Ohrun and Junkdog. It's not always easy to spot our own mistakes when writing code.

Also, no pressure, but when do you plan to publish the next release Ohrun?

@orhun
Copy link
Member

orhun commented Jan 15, 2026

Not sure, probably soon after we finish this one :)

Copy link
Member

@junkdog junkdog left a comment

Choose a reason for hiding this comment

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

looking good!

@junkdog
Copy link
Member

junkdog commented Jan 15, 2026

image

i noticed there's a very minor gap between full-size block chars

image

and blocks appear to overlap by a few pixels, but seemingly w/o breaking the layout anywhere.

i think both the above however are things that will be addressed once we have proper font handling for the dom backend.

@junkdog
Copy link
Member

junkdog commented Jan 15, 2026

Also, no pressure, but when do you plan to publish the next release Ohrun?

i'm trying to wrap up beamterm 0.13.0 but it's maybe a week away.

@benoitlx
Copy link
Contributor Author

i noticed there's a very minor gap between full-size block chars

Are the examples you are running available somewhere ?

i think both the above however are things that will be addressed once we have proper font handling for the dom backend.

Don't hesitate to ping me for things related to this backend in the future.

i'm trying to wrap up beamterm 0.13.0 but it's maybe a week away.

Nice !

@junkdog
Copy link
Member

junkdog commented Jan 17, 2026

Are the examples you are running available somewhere ?

oh, that's just ratzilla's demo example.

Don't hesitate to ping me for things related to this backend in the future.

please do :) i don't think we have an issue for it (or maybe we do), i just know that canvas and dom backends have hard-coded fonts (and font cell metrics are more like guesses, but that might be partially fixed now).

it would be nice, if we in the future could just call Terminal::set_font(...), regardless of backend.

@junkdog junkdog merged commit 1a60025 into ratatui:main Jan 19, 2026
7 checks passed
This was referenced Jan 23, 2026
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.

Bugs with Multiple Width Glyphs Hyperlink in DOM backend does not update and disappears on window resize

3 participants