Skip to content

refactor: retain renderer state in a frame context - #169

Merged
cowboyd merged 1 commit into
mainfrom
spike/frame-ownership
Dec 1, 2026
Merged

cowboyd merged 1 commit into
mainfrom
spike/frame-ownership

Conversation

@cowboyd

@cowboyd cowboyd commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Lays the groundwork re-using element renders from previous frames. What this does is split the architecture into two separate frames, the current frame and the previous frame. This also fixes stale bounds for removed elements and caret cursors remaining visible after a resize. What it allows us to do is to "look back" at previous renders and just byte-copy entire rendered descriptions of elements.

There is already a bunch of "look back" happening already such as what the caret and the pointer were doing in the previous frame, so this just make a lot of that explicit.

Details

FrameContext owns the two frames, their current/previous roles, and the shared open-element stack and output buffer.

Rendering prepares the runlist, executes layout, resolves metadata and pointer hits, draws cells, emits differences, then swaps the frames. Bounds remain lazy. Resize rebuilds viewport storage while retaining directive bytes and emitted state.

This does almost double the amount of memory used because we store two runlists instead of one so that we can crib off the previous runlets. However, this is because we preallocate the entire maximum runlets size for the maximum number of elements. We could grow this memory according to usage, but that would be a separate change.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (deno task test: 29 suites, 400 steps)
  • Files are formatted (deno task fmt)
  • I have added/updated tests for my changes
  • I have added a changeset

Also checked the WASM build, deno task verify, deno lint, and targeted native
checks for rejected-input preservation, resize and capacity recovery, and
allocation boundaries.

AI-generated code disclosure

  • This PR includes AI-generated code

@bombshell-cooper

bombshell-cooper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Changeset suggestion

The current changeset no longer matches this PR. This review contains a corrected replacement.

Why: Changeset package scope does not match the affected packages confidently. Changeset is not sufficiently consumer-focused.

View the proposed changeset
---
'@bomb.sh/tty': patch
---

Fixes `result.info.get(id)` returning stale bounds for elements omitted from the latest render, including an empty render — those lookups now return `undefined`.

Fixes a visible caret remaining on screen after a resize when the next render in default mode has no `caret` declared on any `text()` directive.

Review this changeset manually

If this draft is correct, react with 🚀 and Cooper will commit it to this branch.

@cowboyd
cowboyd added this pull request to stack #165 October 27, 2026 14:42
@@ -0,0 +1,7 @@
---

@bombshell-cooper bombshell-cooper Bot Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changeset needs revision.

Changeset package scope does not match the affected packages confidently. Changeset is not sufficiently consumer-focused.

View the proposed replacement
---
'@bomb.sh/tty': patch
---

Fixes `result.info.get(id)` returning stale bounds for elements omitted from the latest render, including an empty render — those lookups now return `undefined`.

Fixes a visible caret remaining on screen after a resize when the next render in default mode has no `caret` declared on any `text()` directive.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tty@169

commit: 0317a14

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Size Increased — +1.2 KB

133.6 KB unpacked

@cowboyd
cowboyd force-pushed the spike/frame-ownership branch 3 times, most recently from dd5d958 to 201083e Compare October 27, 2026 15:30
@cowboyd
cowboyd force-pushed the spike/frame-ownership branch 2 times, most recently from f8b8a6e to 1fdcef2 Compare December 1, 2026 02:30
@cowboyd
cowboyd force-pushed the spike/frame-ownership branch from 1fdcef2 to 0f3500f Compare December 1, 2026 02:34
Base automatically changed from feat/state-only-update to main December 1, 2026 02:37
@cowboyd
cowboyd force-pushed the spike/frame-ownership branch from 0f3500f to 0317a14 Compare December 1, 2026 02:37
@cowboyd
cowboyd merged commit 326f86e into main Dec 1, 2026
13 checks passed
@cowboyd
cowboyd deleted the spike/frame-ownership branch December 1, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants