Initial render has incorrect layout size/offset in Ratzilla WebRenderer

Open
#186 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust, wasm
Domain
frontend, web-dev

Research direction

Start at the main entry point around DomBackend::new, Terminal::new, and terminal.draw_web, then reproduce the first-load and refresh behavior in the stated Chrome, Trunk, and wasm32 environment. Inspect the initial terminal size calculation and WebRenderer initialization timing; done means the first render has the same layout and size as later renders without an unexpected scrollbar.

Written by the indexing model from the issue text.

Description

Description

When running a Ratzilla application in the browser, the first page load sometimes renders with an incorrect layout.

Symptoms:

  • UI is incorrectly scaled or shifted.
  • Unexpected browser scrollbar appears
  • Layout becomes correct after refreshing the page

The issue only happens on the first load(or refresh via ctrl+shift+R).

Environment

  • OS: Windows 11
  • Browser: Chrome (latest)
  • Target: wasm32-unknown-unknown
  • Build tool: Trunk

Versions:

[dependencies]
ratatui = { version = "0.30.1", default-features = false, features=['std'] }
color-eyre = "0.6.5"
ratzilla = "0.3.1"

Code

use std::{io, rc::Rc};

use ratatui::{
    layout::{Alignment, Constraint, Layout, VerticalAlignment},
    style::{Color, Stylize},
    widgets::{Block, BorderType, Paragraph},
    Frame, Terminal,
};

use ratzilla::{DomBackend, WebRenderer};

fn main() -> io::Result<()> {
    let backend = DomBackend::new()?;
    let terminal = Terminal::new(backend)?;

    let state = Rc::new(App::default());

    let render_state = Rc::clone(&state);
    terminal.draw_web(move |frame| {
        render_state.render(frame);
    });

    Ok(())
}

#[derive(Default)]
struct App {}

impl App {
    fn render(&self, frame: &mut Frame) {
        let [top, bottom] =
            Layout::vertical([Constraint::Percentage(60), Constraint::Percentage(40)])
                .areas(frame.area());

        // Splicing top
        let [_, art_area] =
            Layout::vertical([Constraint::Fill(1), Constraint::Length(8)]).areas(top);

        let [_, tab_area, _] = Layout::vertical([
            Constraint::Fill(1),
            Constraint::Length(2),
            Constraint::Fill(1),
        ])
        .areas(bottom);

        let block = Block::new();

        let text = format!(
            r#"
 _   _      _ _        __        __         _     _ _ 
| | | | ___| | | ___   \ \      / /__  _ __| | __| | |
| |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` | |
|  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |_|
|_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_(_)
"#
        );

        let paragraph = Paragraph::new(text)
            .block(block)
            .fg(Color::White)
            .bg(Color::Black)
            .centered();

        let block_2 = Block::new()
            .title("WORLD • HELLO • ko-KR • zh-CN • en-US • Backend • CLI")
            .title_alignment(Alignment::Center);

        frame.render_widget(paragraph, art_area);
        frame.render_widget(block_2, bottom);
    }
}

Expected behavior

The first render should have the same layout and size as subsequent renders.

Actual behavior

On the first load:

  • Layout size appears incorrect
  • Widgets may be offset
  • Scrollbar may appear unexpectedly

After refreshing:

  • The layout renders correctly.

Refresh via ctrl+shift+R:

  • Same issue as the first load

Tried solutions

  • Added overflow: hidden to html/body.
  • Changed viewport sizing from 100vh to 100dvh.
  • Removed external font loading to avoid layout shift.
  • Triggered browser resize events manually after WASM initialization.

None of these fixed the issue.

Question

Could this be related to the initial terminal size calculation or WebRenderer initialization timing?

Is there a recommended way to force Ratzilla to recalculate the terminal size after the initial DOM layout is completed?

Dominant language
Rust
Stars
1.5k
Forks
72
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ratatui/ratzilla

All issues in ratatui/ratzilla

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.