@rstreamlabs/react 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,9 @@ function WebTTYTerminal(props) {
46
46
  let disposeOnResize = null;
47
47
  let disposeOnTitleChange = null;
48
48
  let resizeObserver = null;
49
+ let connected = false;
50
+ let syncedRows = 0;
51
+ let syncedCols = 0;
49
52
  const clear = () => {
50
53
  disposeOnData?.dispose();
51
54
  disposeOnData = null;
@@ -55,6 +58,9 @@ function WebTTYTerminal(props) {
55
58
  disposeOnTitleChange = null;
56
59
  resizeObserver?.disconnect();
57
60
  resizeObserver = null;
61
+ connected = false;
62
+ syncedRows = 0;
63
+ syncedCols = 0;
58
64
  };
59
65
  const terminal = new Terminal({
60
66
  allowProposedApi: true,
@@ -72,6 +78,31 @@ function WebTTYTerminal(props) {
72
78
  console.warn("WebGL addon could not be loaded:", err);
73
79
  }
74
80
  terminal.open(ref.current);
81
+ const fit = () => {
82
+ const container = ref.current;
83
+ if (!container) return false;
84
+ if (container.clientWidth === 0 || container.clientHeight === 0) {
85
+ return false;
86
+ }
87
+ try {
88
+ fitAddon.fit();
89
+ } catch {
90
+ return false;
91
+ }
92
+ return true;
93
+ };
94
+ const syncRemoteSize = (rows, cols) => {
95
+ if (!connected) return;
96
+ if (rows < 1 || cols < 1) return;
97
+ if (rows === syncedRows && cols === syncedCols) return;
98
+ syncedRows = rows;
99
+ syncedCols = cols;
100
+ try {
101
+ webtty.resize(rows, cols);
102
+ } catch (e) {
103
+ console.error("Cannot resize remote TTY:", e);
104
+ }
105
+ };
75
106
  onTerminalCreated?.(terminal);
76
107
  disposeOnTitleChange = terminal.onTitleChange((title) => {
77
108
  onTitleChange?.(title);
@@ -97,13 +128,11 @@ function WebTTYTerminal(props) {
97
128
  onStderrEos?.();
98
129
  },
99
130
  onConnect: () => {
131
+ connected = true;
100
132
  onConnect?.();
101
133
  terminal.focus();
102
- try {
103
- webtty.resize(terminal.rows, terminal.cols);
104
- } catch (e) {
105
- console.error("Cannot resize remote TTY:", e);
106
- }
134
+ fit();
135
+ syncRemoteSize(terminal.rows, terminal.cols);
107
136
  disposeOnData = terminal.onData((data) => {
108
137
  try {
109
138
  webtty.writeStdin(new TextEncoder().encode(data));
@@ -112,11 +141,7 @@ function WebTTYTerminal(props) {
112
141
  }
113
142
  });
114
143
  disposeOnResize = terminal.onResize((size) => {
115
- try {
116
- webtty.resize(size.rows, size.cols);
117
- } catch (e) {
118
- console.error("Cannot resize remote TTY:", e);
119
- }
144
+ syncRemoteSize(size.rows, size.cols);
120
145
  });
121
146
  },
122
147
  onComplete: (code) => {
@@ -139,11 +164,13 @@ Process exited with code ${code}.`);
139
164
  resizeObserver = new ResizeObserver((entries) => {
140
165
  for (const entry of entries) {
141
166
  if (entry.target === ref.current) {
142
- fitAddon.fit();
167
+ if (!fit()) return;
168
+ syncRemoteSize(terminal.rows, terminal.cols);
143
169
  }
144
170
  }
145
171
  });
146
172
  resizeObserver.observe(ref.current);
173
+ fit();
147
174
  return () => {
148
175
  clear();
149
176
  webtty.disconnect();
@@ -80,6 +80,9 @@ function WebTTYTerminal(props) {
80
80
  let disposeOnResize = null;
81
81
  let disposeOnTitleChange = null;
82
82
  let resizeObserver = null;
83
+ let connected = false;
84
+ let syncedRows = 0;
85
+ let syncedCols = 0;
83
86
  const clear = () => {
84
87
  disposeOnData?.dispose();
85
88
  disposeOnData = null;
@@ -89,6 +92,9 @@ function WebTTYTerminal(props) {
89
92
  disposeOnTitleChange = null;
90
93
  resizeObserver?.disconnect();
91
94
  resizeObserver = null;
95
+ connected = false;
96
+ syncedRows = 0;
97
+ syncedCols = 0;
92
98
  };
93
99
  const terminal = new import_xterm2.Terminal({
94
100
  allowProposedApi: true,
@@ -106,6 +112,31 @@ function WebTTYTerminal(props) {
106
112
  console.warn("WebGL addon could not be loaded:", err);
107
113
  }
108
114
  terminal.open(ref.current);
115
+ const fit = () => {
116
+ const container = ref.current;
117
+ if (!container) return false;
118
+ if (container.clientWidth === 0 || container.clientHeight === 0) {
119
+ return false;
120
+ }
121
+ try {
122
+ fitAddon.fit();
123
+ } catch {
124
+ return false;
125
+ }
126
+ return true;
127
+ };
128
+ const syncRemoteSize = (rows, cols) => {
129
+ if (!connected) return;
130
+ if (rows < 1 || cols < 1) return;
131
+ if (rows === syncedRows && cols === syncedCols) return;
132
+ syncedRows = rows;
133
+ syncedCols = cols;
134
+ try {
135
+ webtty.resize(rows, cols);
136
+ } catch (e) {
137
+ console.error("Cannot resize remote TTY:", e);
138
+ }
139
+ };
109
140
  onTerminalCreated?.(terminal);
110
141
  disposeOnTitleChange = terminal.onTitleChange((title) => {
111
142
  onTitleChange?.(title);
@@ -131,13 +162,11 @@ function WebTTYTerminal(props) {
131
162
  onStderrEos?.();
132
163
  },
133
164
  onConnect: () => {
165
+ connected = true;
134
166
  onConnect?.();
135
167
  terminal.focus();
136
- try {
137
- webtty.resize(terminal.rows, terminal.cols);
138
- } catch (e) {
139
- console.error("Cannot resize remote TTY:", e);
140
- }
168
+ fit();
169
+ syncRemoteSize(terminal.rows, terminal.cols);
141
170
  disposeOnData = terminal.onData((data) => {
142
171
  try {
143
172
  webtty.writeStdin(new TextEncoder().encode(data));
@@ -146,11 +175,7 @@ function WebTTYTerminal(props) {
146
175
  }
147
176
  });
148
177
  disposeOnResize = terminal.onResize((size) => {
149
- try {
150
- webtty.resize(size.rows, size.cols);
151
- } catch (e) {
152
- console.error("Cannot resize remote TTY:", e);
153
- }
178
+ syncRemoteSize(size.rows, size.cols);
154
179
  });
155
180
  },
156
181
  onComplete: (code) => {
@@ -173,11 +198,13 @@ Process exited with code ${code}.`);
173
198
  resizeObserver = new ResizeObserver((entries) => {
174
199
  for (const entry of entries) {
175
200
  if (entry.target === ref.current) {
176
- fitAddon.fit();
201
+ if (!fit()) return;
202
+ syncRemoteSize(terminal.rows, terminal.cols);
177
203
  }
178
204
  }
179
205
  });
180
206
  resizeObserver.observe(ref.current);
207
+ fit();
181
208
  return () => {
182
209
  clear();
183
210
  webtty.disconnect();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WebTTYTerminal
3
- } from "../chunk-6EXRCHLM.mjs";
3
+ } from "../chunk-HTAKPV7E.mjs";
4
4
  export {
5
5
  WebTTYTerminal
6
6
  };
package/dist/index.js CHANGED
@@ -83,6 +83,9 @@ function WebTTYTerminal(props) {
83
83
  let disposeOnResize = null;
84
84
  let disposeOnTitleChange = null;
85
85
  let resizeObserver = null;
86
+ let connected = false;
87
+ let syncedRows = 0;
88
+ let syncedCols = 0;
86
89
  const clear = () => {
87
90
  disposeOnData?.dispose();
88
91
  disposeOnData = null;
@@ -92,6 +95,9 @@ function WebTTYTerminal(props) {
92
95
  disposeOnTitleChange = null;
93
96
  resizeObserver?.disconnect();
94
97
  resizeObserver = null;
98
+ connected = false;
99
+ syncedRows = 0;
100
+ syncedCols = 0;
95
101
  };
96
102
  const terminal = new import_xterm2.Terminal({
97
103
  allowProposedApi: true,
@@ -109,6 +115,31 @@ function WebTTYTerminal(props) {
109
115
  console.warn("WebGL addon could not be loaded:", err);
110
116
  }
111
117
  terminal.open(ref.current);
118
+ const fit = () => {
119
+ const container = ref.current;
120
+ if (!container) return false;
121
+ if (container.clientWidth === 0 || container.clientHeight === 0) {
122
+ return false;
123
+ }
124
+ try {
125
+ fitAddon.fit();
126
+ } catch {
127
+ return false;
128
+ }
129
+ return true;
130
+ };
131
+ const syncRemoteSize = (rows, cols) => {
132
+ if (!connected) return;
133
+ if (rows < 1 || cols < 1) return;
134
+ if (rows === syncedRows && cols === syncedCols) return;
135
+ syncedRows = rows;
136
+ syncedCols = cols;
137
+ try {
138
+ webtty.resize(rows, cols);
139
+ } catch (e) {
140
+ console.error("Cannot resize remote TTY:", e);
141
+ }
142
+ };
112
143
  onTerminalCreated?.(terminal);
113
144
  disposeOnTitleChange = terminal.onTitleChange((title) => {
114
145
  onTitleChange?.(title);
@@ -134,13 +165,11 @@ function WebTTYTerminal(props) {
134
165
  onStderrEos?.();
135
166
  },
136
167
  onConnect: () => {
168
+ connected = true;
137
169
  onConnect?.();
138
170
  terminal.focus();
139
- try {
140
- webtty.resize(terminal.rows, terminal.cols);
141
- } catch (e) {
142
- console.error("Cannot resize remote TTY:", e);
143
- }
171
+ fit();
172
+ syncRemoteSize(terminal.rows, terminal.cols);
144
173
  disposeOnData = terminal.onData((data) => {
145
174
  try {
146
175
  webtty.writeStdin(new TextEncoder().encode(data));
@@ -149,11 +178,7 @@ function WebTTYTerminal(props) {
149
178
  }
150
179
  });
151
180
  disposeOnResize = terminal.onResize((size) => {
152
- try {
153
- webtty.resize(size.rows, size.cols);
154
- } catch (e) {
155
- console.error("Cannot resize remote TTY:", e);
156
- }
181
+ syncRemoteSize(size.rows, size.cols);
157
182
  });
158
183
  },
159
184
  onComplete: (code) => {
@@ -176,11 +201,13 @@ Process exited with code ${code}.`);
176
201
  resizeObserver = new ResizeObserver((entries) => {
177
202
  for (const entry of entries) {
178
203
  if (entry.target === ref.current) {
179
- fitAddon.fit();
204
+ if (!fit()) return;
205
+ syncRemoteSize(terminal.rows, terminal.cols);
180
206
  }
181
207
  }
182
208
  });
183
209
  resizeObserver.observe(ref.current);
210
+ fit();
184
211
  return () => {
185
212
  clear();
186
213
  webtty.disconnect();
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WebTTYTerminal
3
- } from "./chunk-6EXRCHLM.mjs";
3
+ } from "./chunk-HTAKPV7E.mjs";
4
4
  import "./chunk-2JFL7TS5.mjs";
5
5
  import {
6
6
  RstreamProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/react",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "React hooks and components for building rstream-enabled UIs.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -50,7 +50,7 @@
50
50
  "typescript": "5.9.3"
51
51
  },
52
52
  "dependencies": {
53
- "@rstreamlabs/rstream": "1.8.0",
53
+ "@rstreamlabs/rstream": "1.8.1",
54
54
  "@rstreamlabs/webtty": "1.6.2",
55
55
  "@xterm/addon-fit": "^0.11.0",
56
56
  "@xterm/addon-unicode11": "^0.9.0",