How to get Xterm.js resize properly?How do JavaScript closures work?How to horizontally center a <div>?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How to disable text selection highlighting?How to check whether a string contains a substring in JavaScript?How to disable resizable property of textarea?How do I remove a particular element from an array in JavaScript?
Mapping a function f[xi_,xj_] over a list x1, ...., xn with the i < j restriction
Why teaching kids Torah is the only forbidden profession for singles Yihud-wise?
How does one "dump" or deplete propellant without changing spacecraft attitude or trajectory?
What are the slash markings on Gatwick's 08R/26L?
Can you move on your turn, and then use the Ready Action to move again on another creature's turn?
What is the 中 in ダウンロード中?
Do you play the upbeat when beginning to play a series of notes, and then after?
Term for checking piece whose opponent daren't capture it
How to prevent bad sectors?
What does it mean when you think without speaking?
Intuition behind eigenvalues of an adjacency matrix
Can a non-EU citizen travel within the Schengen area without identity documents?
Could IPv6 make NAT / port numbers redundant?
Is there an evolutionary advantage to having two heads?
find the Integer value after a string from a file
Why does the 6502 have the BIT instruction?
Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?
What is/are this/these giant NASA box(es)?
chmod would set file permission to 000 no matter what permission i try to set
What caused the tendency for conservatives to not support climate change regulations?
Can a helicopter mask itself from Radar?
Biblical Basis for 400 years of silence between old and new testament
60s (or earlier) short story where each colony has one person who doesn't connect well with others who is there for being able to absorb knowledge
Select row of data if next row contains zero
How to get Xterm.js resize properly?
How do JavaScript closures work?How to horizontally center a <div>?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How to disable text selection highlighting?How to check whether a string contains a substring in JavaScript?How to disable resizable property of textarea?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
tl;dr
I've created a React wrapper to render an array of log messages into a terminal but resizing is giving a weird output (see screenshot). (There is a React-Wrapper on NPM but that wasn't working for my use-case - caused screen flickering)
I'm working on a feature for Guppy where I'm adding Xterm.js for the terminal output.
The PR can be found here.
I've added xterm because of hyperlink scanning/parsing and that is working.
But I'm stuck with getting resize to work. If I'm starting the devServer in the app and wait for some text it will display with correct letter width.
If I reduce the size I'm getting an output with an incorrect letter width.
Like in the following screenshot:
It is always looking correct in the not resized state but after resize it will get the wrong display - so this will happen for enlarging & shrinking the screen width.
The output should look similar to the following screenshot (maybe with some wrapped lines):
I think this is caused by Fit addon or the way I'm handling resizing with the resize observer but I'm not sure.
The span style of xterm letter are getting a width of NaNpx
like in the following screenshot:
Is this caused by a media query I'm using? I haven't seen that yet maybe I have to temporarily disable all media queries to see if that's causing the behaviour.
What I have tried so far:
- Wrapped
this.xterm.fit()
into asetTimeout(func, 0)
but with-out an effect - Modified some of the styles I'm using but I haven't found the cause.
Code
The code I'm using can be found on Github branch feature-terminal-links but here I'd like to extract the parts I've added to get Xterm to work with React:
- I created a styled-component
XtermContainer
as a div so I can add Xterm styles and own styling. The following code is insiderender
and will be our xterm.js container (innerRef
will be used later inComponentDidMount
to intialize Xterm with that container):
<XtermContainer
width=width
height=height
innerRef=node => (this.node = node)
/>
- Init xterm in
componentDidMount
with the container above:
componentDidMount()
Terminal.applyAddon(webLinks);
Terminal.applyAddon(localLinks);
Terminal.applyAddon(fit);
this.xterm = new Terminal(
convertEol: true,
fontFamily: `'Fira Mono', monospace`,
fontSize: 15,
rendererType: 'dom', // default is canvas
);
this.xterm.setOption('theme',
background: COLORS.blue[900],
foreground: COLORS.white,
);
this.xterm.open(this.node);
this.xterm.fit();
/* ... some addon setup code here (not relevant for the problem) ... */
- Added react-resize-observer inside of the wrapper that is also containing the terminal container so I can trigger
this.xterm.fit()
if the size changes (in the repo there is asetTimeout
wrapper around for testing).
<ResizeObserver onResize=() => this.xterm && this.xterm.fit() />
- Using
componentDidUpdate(prevProps, prevState)
to update the terminal and scroll the terminal to the bottom if the component is getting new logs:
componentDidUpdate(prevProps, prevState)
if (prevProps.task.logs !== this.state.logs)
if (this.state.logs.length === 0)
this.xterm.clear();
for (const log of this.state.logs)
/*
We need to track what we have added to xterm - feels hacky but it's working.
`this.xterm.clear()` and re-render everything caused screen flicker that's why I decided to not use it.
Todo: Check if there is a react-xterm wrapper that is not using xterm.clear or
create a wrapper component that can render the logs array (with-out flicker).
*/
if (!this.renderedLogs[log.id])
this.writeln(log.text);
this.xterm.scrollToBottom();
this.renderedLogs[log.id] = true;
Ideas I have to find the cause:
Check ResizeObserver code.(see update below)- Try to find why xterm css is getting a NaN width. Is Xterm.js using the style width of the container? If yes, maybe that's not correctly set.
Update
OK, the resize obeserver is probably not needed as I'm getting the same behaviour after commenting out the <ResizeObserver/>
in render. So I think it's caused by xterm.js or the css in Guppy.
javascript css reactjs xtermjs
add a comment |
tl;dr
I've created a React wrapper to render an array of log messages into a terminal but resizing is giving a weird output (see screenshot). (There is a React-Wrapper on NPM but that wasn't working for my use-case - caused screen flickering)
I'm working on a feature for Guppy where I'm adding Xterm.js for the terminal output.
The PR can be found here.
I've added xterm because of hyperlink scanning/parsing and that is working.
But I'm stuck with getting resize to work. If I'm starting the devServer in the app and wait for some text it will display with correct letter width.
If I reduce the size I'm getting an output with an incorrect letter width.
Like in the following screenshot:
It is always looking correct in the not resized state but after resize it will get the wrong display - so this will happen for enlarging & shrinking the screen width.
The output should look similar to the following screenshot (maybe with some wrapped lines):
I think this is caused by Fit addon or the way I'm handling resizing with the resize observer but I'm not sure.
The span style of xterm letter are getting a width of NaNpx
like in the following screenshot:
Is this caused by a media query I'm using? I haven't seen that yet maybe I have to temporarily disable all media queries to see if that's causing the behaviour.
What I have tried so far:
- Wrapped
this.xterm.fit()
into asetTimeout(func, 0)
but with-out an effect - Modified some of the styles I'm using but I haven't found the cause.
Code
The code I'm using can be found on Github branch feature-terminal-links but here I'd like to extract the parts I've added to get Xterm to work with React:
- I created a styled-component
XtermContainer
as a div so I can add Xterm styles and own styling. The following code is insiderender
and will be our xterm.js container (innerRef
will be used later inComponentDidMount
to intialize Xterm with that container):
<XtermContainer
width=width
height=height
innerRef=node => (this.node = node)
/>
- Init xterm in
componentDidMount
with the container above:
componentDidMount()
Terminal.applyAddon(webLinks);
Terminal.applyAddon(localLinks);
Terminal.applyAddon(fit);
this.xterm = new Terminal(
convertEol: true,
fontFamily: `'Fira Mono', monospace`,
fontSize: 15,
rendererType: 'dom', // default is canvas
);
this.xterm.setOption('theme',
background: COLORS.blue[900],
foreground: COLORS.white,
);
this.xterm.open(this.node);
this.xterm.fit();
/* ... some addon setup code here (not relevant for the problem) ... */
- Added react-resize-observer inside of the wrapper that is also containing the terminal container so I can trigger
this.xterm.fit()
if the size changes (in the repo there is asetTimeout
wrapper around for testing).
<ResizeObserver onResize=() => this.xterm && this.xterm.fit() />
- Using
componentDidUpdate(prevProps, prevState)
to update the terminal and scroll the terminal to the bottom if the component is getting new logs:
componentDidUpdate(prevProps, prevState)
if (prevProps.task.logs !== this.state.logs)
if (this.state.logs.length === 0)
this.xterm.clear();
for (const log of this.state.logs)
/*
We need to track what we have added to xterm - feels hacky but it's working.
`this.xterm.clear()` and re-render everything caused screen flicker that's why I decided to not use it.
Todo: Check if there is a react-xterm wrapper that is not using xterm.clear or
create a wrapper component that can render the logs array (with-out flicker).
*/
if (!this.renderedLogs[log.id])
this.writeln(log.text);
this.xterm.scrollToBottom();
this.renderedLogs[log.id] = true;
Ideas I have to find the cause:
Check ResizeObserver code.(see update below)- Try to find why xterm css is getting a NaN width. Is Xterm.js using the style width of the container? If yes, maybe that's not correctly set.
Update
OK, the resize obeserver is probably not needed as I'm getting the same behaviour after commenting out the <ResizeObserver/>
in render. So I think it's caused by xterm.js or the css in Guppy.
javascript css reactjs xtermjs
add a comment |
tl;dr
I've created a React wrapper to render an array of log messages into a terminal but resizing is giving a weird output (see screenshot). (There is a React-Wrapper on NPM but that wasn't working for my use-case - caused screen flickering)
I'm working on a feature for Guppy where I'm adding Xterm.js for the terminal output.
The PR can be found here.
I've added xterm because of hyperlink scanning/parsing and that is working.
But I'm stuck with getting resize to work. If I'm starting the devServer in the app and wait for some text it will display with correct letter width.
If I reduce the size I'm getting an output with an incorrect letter width.
Like in the following screenshot:
It is always looking correct in the not resized state but after resize it will get the wrong display - so this will happen for enlarging & shrinking the screen width.
The output should look similar to the following screenshot (maybe with some wrapped lines):
I think this is caused by Fit addon or the way I'm handling resizing with the resize observer but I'm not sure.
The span style of xterm letter are getting a width of NaNpx
like in the following screenshot:
Is this caused by a media query I'm using? I haven't seen that yet maybe I have to temporarily disable all media queries to see if that's causing the behaviour.
What I have tried so far:
- Wrapped
this.xterm.fit()
into asetTimeout(func, 0)
but with-out an effect - Modified some of the styles I'm using but I haven't found the cause.
Code
The code I'm using can be found on Github branch feature-terminal-links but here I'd like to extract the parts I've added to get Xterm to work with React:
- I created a styled-component
XtermContainer
as a div so I can add Xterm styles and own styling. The following code is insiderender
and will be our xterm.js container (innerRef
will be used later inComponentDidMount
to intialize Xterm with that container):
<XtermContainer
width=width
height=height
innerRef=node => (this.node = node)
/>
- Init xterm in
componentDidMount
with the container above:
componentDidMount()
Terminal.applyAddon(webLinks);
Terminal.applyAddon(localLinks);
Terminal.applyAddon(fit);
this.xterm = new Terminal(
convertEol: true,
fontFamily: `'Fira Mono', monospace`,
fontSize: 15,
rendererType: 'dom', // default is canvas
);
this.xterm.setOption('theme',
background: COLORS.blue[900],
foreground: COLORS.white,
);
this.xterm.open(this.node);
this.xterm.fit();
/* ... some addon setup code here (not relevant for the problem) ... */
- Added react-resize-observer inside of the wrapper that is also containing the terminal container so I can trigger
this.xterm.fit()
if the size changes (in the repo there is asetTimeout
wrapper around for testing).
<ResizeObserver onResize=() => this.xterm && this.xterm.fit() />
- Using
componentDidUpdate(prevProps, prevState)
to update the terminal and scroll the terminal to the bottom if the component is getting new logs:
componentDidUpdate(prevProps, prevState)
if (prevProps.task.logs !== this.state.logs)
if (this.state.logs.length === 0)
this.xterm.clear();
for (const log of this.state.logs)
/*
We need to track what we have added to xterm - feels hacky but it's working.
`this.xterm.clear()` and re-render everything caused screen flicker that's why I decided to not use it.
Todo: Check if there is a react-xterm wrapper that is not using xterm.clear or
create a wrapper component that can render the logs array (with-out flicker).
*/
if (!this.renderedLogs[log.id])
this.writeln(log.text);
this.xterm.scrollToBottom();
this.renderedLogs[log.id] = true;
Ideas I have to find the cause:
Check ResizeObserver code.(see update below)- Try to find why xterm css is getting a NaN width. Is Xterm.js using the style width of the container? If yes, maybe that's not correctly set.
Update
OK, the resize obeserver is probably not needed as I'm getting the same behaviour after commenting out the <ResizeObserver/>
in render. So I think it's caused by xterm.js or the css in Guppy.
javascript css reactjs xtermjs
tl;dr
I've created a React wrapper to render an array of log messages into a terminal but resizing is giving a weird output (see screenshot). (There is a React-Wrapper on NPM but that wasn't working for my use-case - caused screen flickering)
I'm working on a feature for Guppy where I'm adding Xterm.js for the terminal output.
The PR can be found here.
I've added xterm because of hyperlink scanning/parsing and that is working.
But I'm stuck with getting resize to work. If I'm starting the devServer in the app and wait for some text it will display with correct letter width.
If I reduce the size I'm getting an output with an incorrect letter width.
Like in the following screenshot:
It is always looking correct in the not resized state but after resize it will get the wrong display - so this will happen for enlarging & shrinking the screen width.
The output should look similar to the following screenshot (maybe with some wrapped lines):
I think this is caused by Fit addon or the way I'm handling resizing with the resize observer but I'm not sure.
The span style of xterm letter are getting a width of NaNpx
like in the following screenshot:
Is this caused by a media query I'm using? I haven't seen that yet maybe I have to temporarily disable all media queries to see if that's causing the behaviour.
What I have tried so far:
- Wrapped
this.xterm.fit()
into asetTimeout(func, 0)
but with-out an effect - Modified some of the styles I'm using but I haven't found the cause.
Code
The code I'm using can be found on Github branch feature-terminal-links but here I'd like to extract the parts I've added to get Xterm to work with React:
- I created a styled-component
XtermContainer
as a div so I can add Xterm styles and own styling. The following code is insiderender
and will be our xterm.js container (innerRef
will be used later inComponentDidMount
to intialize Xterm with that container):
<XtermContainer
width=width
height=height
innerRef=node => (this.node = node)
/>
- Init xterm in
componentDidMount
with the container above:
componentDidMount()
Terminal.applyAddon(webLinks);
Terminal.applyAddon(localLinks);
Terminal.applyAddon(fit);
this.xterm = new Terminal(
convertEol: true,
fontFamily: `'Fira Mono', monospace`,
fontSize: 15,
rendererType: 'dom', // default is canvas
);
this.xterm.setOption('theme',
background: COLORS.blue[900],
foreground: COLORS.white,
);
this.xterm.open(this.node);
this.xterm.fit();
/* ... some addon setup code here (not relevant for the problem) ... */
- Added react-resize-observer inside of the wrapper that is also containing the terminal container so I can trigger
this.xterm.fit()
if the size changes (in the repo there is asetTimeout
wrapper around for testing).
<ResizeObserver onResize=() => this.xterm && this.xterm.fit() />
- Using
componentDidUpdate(prevProps, prevState)
to update the terminal and scroll the terminal to the bottom if the component is getting new logs:
componentDidUpdate(prevProps, prevState)
if (prevProps.task.logs !== this.state.logs)
if (this.state.logs.length === 0)
this.xterm.clear();
for (const log of this.state.logs)
/*
We need to track what we have added to xterm - feels hacky but it's working.
`this.xterm.clear()` and re-render everything caused screen flicker that's why I decided to not use it.
Todo: Check if there is a react-xterm wrapper that is not using xterm.clear or
create a wrapper component that can render the logs array (with-out flicker).
*/
if (!this.renderedLogs[log.id])
this.writeln(log.text);
this.xterm.scrollToBottom();
this.renderedLogs[log.id] = true;
Ideas I have to find the cause:
Check ResizeObserver code.(see update below)- Try to find why xterm css is getting a NaN width. Is Xterm.js using the style width of the container? If yes, maybe that's not correctly set.
Update
OK, the resize obeserver is probably not needed as I'm getting the same behaviour after commenting out the <ResizeObserver/>
in render. So I think it's caused by xterm.js or the css in Guppy.
javascript css reactjs xtermjs
javascript css reactjs xtermjs
edited Mar 24 at 10:26
AWolf
asked Mar 24 at 10:04
AWolfAWolf
6,54722233
6,54722233
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I have a fix for the issue. It's now working in the above mentioned feature branch. Not sure if there is a better solution but it's working for me.
I like to explain how I have fixed the resizing issue:
The problem was the OnlyOn
component that was used in DevelopmentServerPane
. It always rendered two TerminalOutput
components. One terminal was hidden with display: none
and the other was displayed with display: inline
- the style change was handled with a media query inside a styled-component.
After replacing OnlyOn
with React-responsive and using the render props to check mdMin
breakpoint it was working as expected. React-responsive is removing the not displayed mediaquery component from DOM so only one terminal in DOM at the same time.
I still don't know why there was a problem with the letter width but probably the two instances collided somehow. I couldn't create a minimal reproduction. I tried to recreate the issue in this Codesandbox but I have only resized one Terminal at a time and so I haven't got the issue there.
The code that fixed the problem (simplified version from the above mentioned repo):
import MediaQuery from 'react-responsive';
const BREAKPOINT_SIZES =
sm: 900,
;
const BREAKPOINTS =
mdMin: `(min-width: $BREAKPOINT_SIZES.sm + 1px)`,
;
const DevelopmentServerPane = () => (
<MediaQuery query=BREAKPOINTS['mdMin']>
matches =>
matches ? (
<div>/* ... render Terminal for matching mdMin and above */</div>
) : (
<div> /* ... render Terminal for small screens */</div>
)
</MediaQuery>
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322629%2fhow-to-get-xterm-js-resize-properly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have a fix for the issue. It's now working in the above mentioned feature branch. Not sure if there is a better solution but it's working for me.
I like to explain how I have fixed the resizing issue:
The problem was the OnlyOn
component that was used in DevelopmentServerPane
. It always rendered two TerminalOutput
components. One terminal was hidden with display: none
and the other was displayed with display: inline
- the style change was handled with a media query inside a styled-component.
After replacing OnlyOn
with React-responsive and using the render props to check mdMin
breakpoint it was working as expected. React-responsive is removing the not displayed mediaquery component from DOM so only one terminal in DOM at the same time.
I still don't know why there was a problem with the letter width but probably the two instances collided somehow. I couldn't create a minimal reproduction. I tried to recreate the issue in this Codesandbox but I have only resized one Terminal at a time and so I haven't got the issue there.
The code that fixed the problem (simplified version from the above mentioned repo):
import MediaQuery from 'react-responsive';
const BREAKPOINT_SIZES =
sm: 900,
;
const BREAKPOINTS =
mdMin: `(min-width: $BREAKPOINT_SIZES.sm + 1px)`,
;
const DevelopmentServerPane = () => (
<MediaQuery query=BREAKPOINTS['mdMin']>
matches =>
matches ? (
<div>/* ... render Terminal for matching mdMin and above */</div>
) : (
<div> /* ... render Terminal for small screens */</div>
)
</MediaQuery>
);
add a comment |
I have a fix for the issue. It's now working in the above mentioned feature branch. Not sure if there is a better solution but it's working for me.
I like to explain how I have fixed the resizing issue:
The problem was the OnlyOn
component that was used in DevelopmentServerPane
. It always rendered two TerminalOutput
components. One terminal was hidden with display: none
and the other was displayed with display: inline
- the style change was handled with a media query inside a styled-component.
After replacing OnlyOn
with React-responsive and using the render props to check mdMin
breakpoint it was working as expected. React-responsive is removing the not displayed mediaquery component from DOM so only one terminal in DOM at the same time.
I still don't know why there was a problem with the letter width but probably the two instances collided somehow. I couldn't create a minimal reproduction. I tried to recreate the issue in this Codesandbox but I have only resized one Terminal at a time and so I haven't got the issue there.
The code that fixed the problem (simplified version from the above mentioned repo):
import MediaQuery from 'react-responsive';
const BREAKPOINT_SIZES =
sm: 900,
;
const BREAKPOINTS =
mdMin: `(min-width: $BREAKPOINT_SIZES.sm + 1px)`,
;
const DevelopmentServerPane = () => (
<MediaQuery query=BREAKPOINTS['mdMin']>
matches =>
matches ? (
<div>/* ... render Terminal for matching mdMin and above */</div>
) : (
<div> /* ... render Terminal for small screens */</div>
)
</MediaQuery>
);
add a comment |
I have a fix for the issue. It's now working in the above mentioned feature branch. Not sure if there is a better solution but it's working for me.
I like to explain how I have fixed the resizing issue:
The problem was the OnlyOn
component that was used in DevelopmentServerPane
. It always rendered two TerminalOutput
components. One terminal was hidden with display: none
and the other was displayed with display: inline
- the style change was handled with a media query inside a styled-component.
After replacing OnlyOn
with React-responsive and using the render props to check mdMin
breakpoint it was working as expected. React-responsive is removing the not displayed mediaquery component from DOM so only one terminal in DOM at the same time.
I still don't know why there was a problem with the letter width but probably the two instances collided somehow. I couldn't create a minimal reproduction. I tried to recreate the issue in this Codesandbox but I have only resized one Terminal at a time and so I haven't got the issue there.
The code that fixed the problem (simplified version from the above mentioned repo):
import MediaQuery from 'react-responsive';
const BREAKPOINT_SIZES =
sm: 900,
;
const BREAKPOINTS =
mdMin: `(min-width: $BREAKPOINT_SIZES.sm + 1px)`,
;
const DevelopmentServerPane = () => (
<MediaQuery query=BREAKPOINTS['mdMin']>
matches =>
matches ? (
<div>/* ... render Terminal for matching mdMin and above */</div>
) : (
<div> /* ... render Terminal for small screens */</div>
)
</MediaQuery>
);
I have a fix for the issue. It's now working in the above mentioned feature branch. Not sure if there is a better solution but it's working for me.
I like to explain how I have fixed the resizing issue:
The problem was the OnlyOn
component that was used in DevelopmentServerPane
. It always rendered two TerminalOutput
components. One terminal was hidden with display: none
and the other was displayed with display: inline
- the style change was handled with a media query inside a styled-component.
After replacing OnlyOn
with React-responsive and using the render props to check mdMin
breakpoint it was working as expected. React-responsive is removing the not displayed mediaquery component from DOM so only one terminal in DOM at the same time.
I still don't know why there was a problem with the letter width but probably the two instances collided somehow. I couldn't create a minimal reproduction. I tried to recreate the issue in this Codesandbox but I have only resized one Terminal at a time and so I haven't got the issue there.
The code that fixed the problem (simplified version from the above mentioned repo):
import MediaQuery from 'react-responsive';
const BREAKPOINT_SIZES =
sm: 900,
;
const BREAKPOINTS =
mdMin: `(min-width: $BREAKPOINT_SIZES.sm + 1px)`,
;
const DevelopmentServerPane = () => (
<MediaQuery query=BREAKPOINTS['mdMin']>
matches =>
matches ? (
<div>/* ... render Terminal for matching mdMin and above */</div>
) : (
<div> /* ... render Terminal for small screens */</div>
)
</MediaQuery>
);
answered Apr 24 at 21:22
AWolfAWolf
6,54722233
6,54722233
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322629%2fhow-to-get-xterm-js-resize-properly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown