mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 13:06:00 +03:00
[GH-ISSUE #562] You can't test the app which uses useTerminalDimensions() #920
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#920
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jcubic on GitHub (Jan 20, 2026).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/562
Originally assigned to: @msmps on GitHub.
I was creating a new project with Opus 4.5 using OpenTUI skills.
I wanted to test an app that renders figlet and I needed useTerminalDimensions to make the text responsive.
LLM found a bug; here is a repro:
https://github.com/jcubic/open-tui-bug
It throws: "Renderer not found"
Here is the explanation of the bug and how to fix it. You probably know the project better, so you will know if this is correct. I'm not brave enough to create a PR using LLM.
OpenTUI Bug:
testRenderCannot Test Components UsinguseTerminalDimensionsSummary
When using
testRenderfrom@opentui/react/test-utilsto test components that calluseTerminalDimensions(), the test fails with "Renderer not found" error, even though the same component works correctly in production.Environment
Reproduction
Expected Behavior
testRendershould set up the renderer context so that hooks likeuseTerminalDimensions()can access the test renderer and return the configured dimensions (e.g.,{ width: 80, height: 24 }).Actual Behavior
Components that call
useTerminalDimensions()throw:Root Cause
The bug is caused by duplicate React contexts created during bundling.
The Problem
The
test-utils.jsbundle creates its ownAppContext:This is a separate object from the
AppContextin the mainindex.jsbundle:Why This Causes the Bug
When
testRenderis called, it creates a root and wraps the component withAppContext.Providerfrom test-utils.js:When the component calls
useTerminalDimensions(), it internally callsuseAppContext()which reads from theAppContextin index.js:Since
AppContextin test-utils.js andAppContextin index.js are different objects (created by separatecreateContext()calls), the provider from test-utils.js does not satisfy the consumer in index.js.The component receives the default context value
{ renderer: null }instead of the test renderer, causing the "Renderer not found" error.Visual Diagram
Suggested Fix
The
test-utilsbundle should import theAppContextfrom the main package instead of creating its own. This ensures both the provider (in testRender) and consumer (in hooks) use the same context object.Option 1: Export
AppContextfrom the main package and import it in test-utils:Option 2: Adjust the build configuration to prevent duplicating the context module when bundling test-utils.
Workaround
Until this is fixed, components can accept dimensions as props and only fall back to the hook when props aren't provided:
However, this is a hack and defeats the purpose of having a test renderer that simulates the real environment.
@msmps commented on GitHub (Jan 22, 2026):
Thanks for reporting this @jcubic ! I'll publish the fix later today 👍