@lethevimlet/sshift 1.4.0 → 1.4.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -1175,12 +1175,14 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
1175
1175
  return false;
1176
1176
  }
1177
1177
 
1178
- // Guard: refuse to fit if the container has zero or near-zero dimensions.
1178
+ // Guard: refuse to fit if the container has near-zero dimensions.
1179
1179
  // A zero-size container produces bogus col/row counts that propagate to
1180
1180
  // the remote PTY and cause narrow-wrap / garbled output bugs.
1181
+ // We use 2px as the threshold to catch truly collapsed containers while
1182
+ // allowing containers that are mid-layout-transition but already have
1183
+ // meaningful size.
1181
1184
  const rect = container.getBoundingClientRect();
1182
- if (rect.width < 10 || rect.height < 10) {
1183
- console.warn(`[SSHIFT] Container too small to fit (${rect.width.toFixed(1)}x${rect.height.toFixed(1)}px), deferring`);
1185
+ if (rect.width < 2 || rect.height < 2) {
1184
1186
  session.needsResize = true;
1185
1187
  if (retryCount < 3) {
1186
1188
  requestAnimationFrame(() => this._fitTerminal(session, retryCount + 1));
@@ -4158,10 +4160,11 @@ const wheelHandler = (e) => {
4158
4160
  if (!session.terminal || !session.fitAddon || !session.isController) return;
4159
4161
  try {
4160
4162
  session.isResyncing = true;
4161
- this._fitTerminal(session);
4163
+ const fitted = this._fitTerminal(session);
4162
4164
  session.isResyncing = false;
4163
4165
 
4164
- if (session.terminal && session.connected) {
4166
+ // Only send the resize if we actually fitted successfully.
4167
+ if (fitted && session.terminal && session.connected) {
4165
4168
  this.socket.emit('ssh-resize', {
4166
4169
  sessionId: data.sessionId,
4167
4170
  cols: session.terminal.cols,
@@ -4175,9 +4178,9 @@ const wheelHandler = (e) => {
4175
4178
  session.isResyncing = true;
4176
4179
  const prevCols = session.terminal.cols;
4177
4180
  const prevRows = session.terminal.rows;
4178
- this._fitTerminal(session);
4181
+ const corrected = this._fitTerminal(session);
4179
4182
  session.isResyncing = false;
4180
- if (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows) {
4183
+ if (corrected && (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows)) {
4181
4184
  this.socket.emit('ssh-resize', {
4182
4185
  sessionId: data.sessionId,
4183
4186
  cols: session.terminal.cols,
@@ -4250,10 +4253,15 @@ const wheelHandler = (e) => {
4250
4253
  if (!session.terminal || !session.fitAddon || !session.isController) return;
4251
4254
  try {
4252
4255
  session.isResyncing = true;
4253
- this._fitTerminal(session);
4256
+ const fitted = this._fitTerminal(session);
4254
4257
  session.isResyncing = false;
4255
4258
 
4256
- if (session.terminal && session.connected) {
4259
+ // Only send the resize to the server if we actually fitted the
4260
+ // terminal. If _fitTerminal returned false (container too small,
4261
+ // not visible, etc.), the cols/rows are stale and would confuse
4262
+ // the remote PTY. A successful retry will trigger onResize
4263
+ // which emits ssh-resize via the debounced handler.
4264
+ if (fitted && session.terminal && session.connected) {
4257
4265
  this.socket.emit('ssh-resize', {
4258
4266
  sessionId: data.sessionId,
4259
4267
  cols: session.terminal.cols,
@@ -4267,9 +4275,9 @@ const wheelHandler = (e) => {
4267
4275
  session.isResyncing = true;
4268
4276
  const prevCols = session.terminal.cols;
4269
4277
  const prevRows = session.terminal.rows;
4270
- this._fitTerminal(session);
4278
+ const corrected = this._fitTerminal(session);
4271
4279
  session.isResyncing = false;
4272
- if (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows) {
4280
+ if (corrected && (session.terminal.cols !== prevCols || session.terminal.rows !== prevRows)) {
4273
4281
  this.socket.emit('ssh-resize', {
4274
4282
  sessionId: data.sessionId,
4275
4283
  cols: session.terminal.cols,
@@ -7772,12 +7780,18 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
7772
7780
  // hold. The PTY on the server wraps at those bogus dimensions.
7773
7781
  const sendResize = () => {
7774
7782
  if (session.fitAddon) {
7775
- this._fitTerminal(session);
7776
- this.socket.emit('ssh-resize', {
7777
- sessionId: data.sessionId,
7778
- cols: session.terminal.cols,
7779
- rows: session.terminal.rows
7780
- });
7783
+ const fitted = this._fitTerminal(session);
7784
+ // Only send the resize to the server if we actually fitted
7785
+ // successfully — otherwise the remote PTY would get stale
7786
+ // dimensions. A deferred retry will trigger onResize which
7787
+ // sends ssh-resize via the debounced handler.
7788
+ if (fitted) {
7789
+ this.socket.emit('ssh-resize', {
7790
+ sessionId: data.sessionId,
7791
+ cols: session.terminal.cols,
7792
+ rows: session.terminal.rows
7793
+ });
7794
+ }
7781
7795
  }
7782
7796
  };
7783
7797
 
@@ -8804,7 +8818,23 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
8804
8818
  session.needsResize = false;
8805
8819
  }
8806
8820
 
8807
- this._fitTerminal(session);
8821
+ const fitted = this._fitTerminal(session);
8822
+
8823
+ // If fitting failed (e.g. container not yet laid out), retry
8824
+ // with delays until the browser commits the layout change.
8825
+ if (!fitted) {
8826
+ console.log('[SSHIFT] Initial fit failed during tab switch, scheduling retries');
8827
+ let retriesLeft = 4;
8828
+ const retryFit = () => {
8829
+ if (!session.terminal || !session.fitAddon || !session.isController) return;
8830
+ const ok = this._fitTerminal(session);
8831
+ if (!ok && retriesLeft > 0) {
8832
+ retriesLeft--;
8833
+ setTimeout(retryFit, 100);
8834
+ }
8835
+ };
8836
+ setTimeout(retryFit, 50);
8837
+ }
8808
8838
 
8809
8839
  // Focus the terminal so user can type
8810
8840
  if (session.terminal) {