Skip to content

OCPBUGS-86491: Fix macOS Option key in pod terminal#16492

Open
logonoff wants to merge 1 commit into
openshift:mainfrom
logonoff:OCPBUGS-86491-xterm
Open

OCPBUGS-86491: Fix macOS Option key in pod terminal#16492
logonoff wants to merge 1 commit into
openshift:mainfrom
logonoff:OCPBUGS-86491-xterm

Conversation

@logonoff
Copy link
Copy Markdown
Member

@logonoff logonoff commented May 25, 2026

Closes #16486

Analysis / Root cause:

The NodePolyfillPlugin in webpack.config.ts injects a process polyfill (with additionalAliases: ['process']) that sets process.title = 'browser'. xterm.js 5.5.0 detects Node.js via typeof process !== 'undefined' && 'title' in process, which returns true due to the polyfill. This causes xterm to set isMac = false, so the macOS Option key is treated as Meta (sending ESC sequences) instead of functioning as a compose key.

Solution description:

Backport the upstream xterm.js fix via a yarn patch. The patch adds a navigator.userAgent check to the isNode detection, so that even with a process polyfill present, xterm correctly identifies the browser environment and preserves isMac = true.

Test setup:

  • macOS with a non-US keyboard layout (e.g., German QWERTZ) or any layout that uses Option as a compose key
  • Navigate to a running Pod → Terminal tab

Test cases:

  • Verify Option+key combinations produce the expected composed characters (e.g., @, {, }, |, \, ~) instead of ESC sequences
  • Verify the pod terminal still functions correctly on Linux and Windows
  • Verify the web terminal operator terminal still functions correctly

Browser conformance:

  • Chrome
  • Firefox
  • Safari (or Epiphany on Linux)

Additional info:

The upstream fix is merged into xterm.js master but not yet included in a stable release (likely @xterm/xterm 7.0.0). This yarn patch can be removed when upgrading to a future xterm.js version that includes the fix.

Summary by CodeRabbit

  • Chores
    • Updated the terminal emulator dependency to a patched reference to ensure a specific patched build is used.
    • Locking the patched package reference to maintain consistent behavior across installs and incorporate targeted fixes.

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels May 25, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@logonoff: This pull request references Jira Issue OCPBUGS-86491, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Analysis / Root cause:

The NodePolyfillPlugin in webpack.config.ts injects a process polyfill (with additionalAliases: ['process']) that sets process.title = 'browser'. xterm.js 5.5.0 detects Node.js via typeof process !== 'undefined' && 'title' in process, which returns true due to the polyfill. This causes xterm to set isMac = false, so the macOS Option key is treated as Meta (sending ESC sequences) instead of functioning as a compose key.

#16486

Solution description:

Backport the upstream xterm.js fix via a yarn patch. The patch adds a navigator.userAgent check to the isNode detection, so that even with a process polyfill present, xterm correctly identifies the browser environment and preserves isMac = true.

Test setup:

  • macOS with a non-US keyboard layout (e.g., German QWERTZ) or any layout that uses Option as a compose key
  • Navigate to a running Pod → Terminal tab

Test cases:

  • Verify Option+key combinations produce the expected composed characters (e.g., @, {, }, |, \, ~) instead of ESC sequences
  • Verify the pod terminal still functions correctly on Linux and Windows
  • Verify the web terminal operator terminal still functions correctly

Browser conformance:

  • Chrome
  • Firefox
  • Safari (or Epiphany on Linux)

Additional info:

The upstream fix is merged into xterm.js master but not yet included in a stable release. This yarn patch can be removed when upgrading to a future xterm.js version that includes the fix.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 88140244-e2be-438f-a6a7-a8e95b806100

📥 Commits

Reviewing files that changed from the base of the PR and between 0c63e33 and 6e7d2c8.

⛔ Files ignored due to path filters (2)
  • frontend/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch is excluded by !**/.yarn/**
  • frontend/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • frontend/package.json

Walkthrough

The PR changes frontend/package.json to reference @xterm/xterm@5.5.0 via a Yarn patch URL instead of the previous semver range, pointing install to a local patch file.

Changes

xterm.js Patch Application

Layer / File(s) Summary
Apply Yarn patch to xterm dependency
frontend/package.json
@xterm/xterm is updated to use a Yarn patched tarball reference (patch:@xterm/xterm@npm%3A5.5.0#~/.yarn/patches/...) instead of the semver range ^5.5.0 to apply a local patch to version 5.5.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 12
✅ Passed checks (12 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and specifically describes the main change: fixing the macOS Option key regression in the pod terminal via a yarn patch to xterm.js.
Description check ✅ Passed The description comprehensively covers root cause, solution, test setup, test cases, and browser conformance. All major template sections are filled with detailed, actionable information.
Linked Issues check ✅ Passed The PR fully addresses issue #16486 by implementing the upstream xterm.js fix via yarn patch, enabling xterm to correctly detect browser environment and preserve macOS Option key compose behavior.
Out of Scope Changes check ✅ Passed The single change—updating @xterm/xterm dependency via yarn patch—is directly scoped to fixing the macOS Option key issue outlined in issue #16486; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Stable And Deterministic Test Names ✅ Passed No Ginkgo tests found in this PR or codebase. All tests use standard Go testing.T pattern. Check for stable Ginkgo test names is not applicable.
Test Structure And Quality ✅ Passed This PR does not contain any Ginkgo test code. The 40+ test files added use standard Go testing.T, not Ginkgo, making the custom check inapplicable.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests are present in this PR. Changes are limited to frontend/package.json and a Yarn patch for xterm.js browser terminal fix, neither containing test code.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added or modified in this PR; the change is purely a frontend dependency update (xterm.js patch) unrelated to SNO test compatibility.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only frontend/package.json (xterm.js dependency); no deployment manifests, operator code, controllers, or Kubernetes scheduling constraints are modified. Check not applicable.
Ote Binary Stdout Contract ✅ Passed PR only modifies frontend/package.json (xterm.js dependency) with no Go code changes. OTE stdout contract checks apply only to Go binaries with main() functions, not frontend dependencies.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR does not add any Ginkgo e2e tests. Changes are limited to frontend dependency update and a JavaScript patch for terminal UI behavior. Check is not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from sg00dwin and spadgett May 25, 2026 18:13
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: logonoff

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 25, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@logonoff: This pull request references Jira Issue OCPBUGS-86491, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

Closes #16486

Analysis / Root cause:

The NodePolyfillPlugin in webpack.config.ts injects a process polyfill (with additionalAliases: ['process']) that sets process.title = 'browser'. xterm.js 5.5.0 detects Node.js via typeof process !== 'undefined' && 'title' in process, which returns true due to the polyfill. This causes xterm to set isMac = false, so the macOS Option key is treated as Meta (sending ESC sequences) instead of functioning as a compose key.

Solution description:

Backport the upstream xterm.js fix via a yarn patch. The patch adds a navigator.userAgent check to the isNode detection, so that even with a process polyfill present, xterm correctly identifies the browser environment and preserves isMac = true.

Test setup:

  • macOS with a non-US keyboard layout (e.g., German QWERTZ) or any layout that uses Option as a compose key
  • Navigate to a running Pod → Terminal tab

Test cases:

  • Verify Option+key combinations produce the expected composed characters (e.g., @, {, }, |, \, ~) instead of ESC sequences
  • Verify the pod terminal still functions correctly on Linux and Windows
  • Verify the web terminal operator terminal still functions correctly

Browser conformance:

  • Chrome
  • Firefox
  • Safari (or Epiphany on Linux)

Additional info:

The upstream fix is merged into xterm.js master but not yet included in a stable release. This yarn patch can be removed when upgrading to a future xterm.js version that includes the fix.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A cherrypick of xtermjs/xterm.js@b522e25

@logonoff
Copy link
Copy Markdown
Member Author

/hold

Need to discuss if we want to set a precedent of patching packages

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 25, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/package.json (1)

174-174: ⚡ Quick win

Document the patch purpose and removal timing.

Consider adding a comment in this file or in a dedicated PATCHES.md document explaining:

  1. Why the patch is needed (webpack process polyfill breaks macOS Option key)
  2. What upstream fix it backports
  3. When it can be removed (after upgrading to xterm.js version that includes the fix)
📝 Suggested inline documentation
     "`@xterm/addon-fit`": "0.10.0",
+    // Patched to fix macOS Option key handling when webpack's process polyfill is present.
+    // TODO: Remove patch when upgrading to xterm.js version that includes the upstream fix
+    // for isNode detection (adds navigator.userAgent check). See OCPBUGS-86491.
     "`@xterm/xterm`": "patch:`@xterm/xterm`@npm%3A5.5.0#~/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/package.json` at line 174, Add documentation explaining the purpose
and removal timing of the `@xterm/xterm` patch referenced as
"patch:`@xterm/xterm`@npm%3A5.5.0#~/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch":
state that the patch fixes the webpack process polyfill breaking macOS Option
key, cite the upstream PR/commit hash or link that this patch backports, and
specify the removal condition (e.g., remove this patch after upgrading to
xterm.js version that contains the upstream fix—include the minimum version
number). Put this comment either inline near the dependency entry in
package.json or in a dedicated PATCHES.md that references the exact patch
filename and the target xterm.js version to drop the patch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/package.json`:
- Line 174: The package.json references a missing Yarn patch entry for
"`@xterm/xterm`" (~/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch); add
the corresponding patch file into the repo under .yarn/patches using the
original patch contents or remove the patch entry and update the dependency to a
version that contains the upstream fix. Ensure the patch (or the replacement
xterm version) implements the upstream isNode detection using
process.versions.node-style detection (not only navigator.userAgent) so behavior
matches upstream fixes for Node v21+.

---

Nitpick comments:
In `@frontend/package.json`:
- Line 174: Add documentation explaining the purpose and removal timing of the
`@xterm/xterm` patch referenced as
"patch:`@xterm/xterm`@npm%3A5.5.0#~/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch":
state that the patch fixes the webpack process polyfill breaking macOS Option
key, cite the upstream PR/commit hash or link that this patch backports, and
specify the removal condition (e.g., remove this patch after upgrading to
xterm.js version that contains the upstream fix—include the minimum version
number). Put this comment either inline near the dependency entry in
package.json or in a dedicated PATCHES.md that references the exact patch
filename and the target xterm.js version to drop the patch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5611490e-fdf7-4841-855f-a212eab37e2a

📥 Commits

Reviewing files that changed from the base of the PR and between 6ba2a16 and 0c63e33.

⛔ Files ignored due to path filters (2)
  • frontend/.yarn/patches/@xterm-xterm-npm-5.5.0-106735eff7.patch is excluded by !**/.yarn/**
  • frontend/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • frontend/package.json

Comment thread frontend/package.json
@logonoff
Copy link
Copy Markdown
Member Author

/cherry-pick release-4.22
/cherry-pick release-4.21
/cherry-pick release-4.20

@openshift-cherrypick-robot
Copy link
Copy Markdown

@logonoff: once the present PR merges, I will cherry-pick it on top of release-4.20, release-4.21, release-4.22 in new PRs and assign them to you.

Details

In response to this:

/cherry-pick release-4.22
/cherry-pick release-4.21
/cherry-pick release-4.20

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

The NodePolyfillPlugin injects a `process` polyfill with `process.title`
set, which causes xterm.js to misidentify the browser as Node.js. This
breaks platform detection (`isMac = false`), so the Option key is treated
as Meta instead of a compose key on macOS.

Backport the upstream fix (xtermjs/xterm.js PR 5571) via yarn patch, which
adds a `navigator.userAgent` check to the `isNode` detection.
@logonoff logonoff force-pushed the OCPBUGS-86491-xterm branch from 0c63e33 to 6e7d2c8 Compare May 25, 2026 19:51
@Leo6Leo
Copy link
Copy Markdown
Contributor

Leo6Leo commented May 25, 2026

Tested this locally — the patch doesn't work as-is. Using German keyboard and type Option + 8 will produce (arg:8) instead of {

It targets src/common/Platform.ts, but webpack resolves xterm via "main": "lib/xterm.js" (a pre-compiled bundle), so the patched source is never consumed during the build.

After manually patching lib/xterm.js instead and rebuilding with a clean cache, the fix works correctly — verified with German QWERTZ layout (Option+8 → {, Option+L → @, etc.).

@logonoff

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 25, 2026

@logonoff: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@logonoff
Copy link
Copy Markdown
Member Author

Tested this locally — the patch doesn't work as-is. Using German keyboard and type Option + 8 will produce (arg:8) instead of {

It targets src/common/Platform.ts, but webpack resolves xterm via "main": "lib/xterm.js" (a pre-compiled bundle), so the patched source is never consumed during the build.

After manually patching lib/xterm.js instead and rebuilding with a clean cache, the fix works correctly — verified with German QWERTZ layout (Option+8 → {, Option+L → @, etc.).

@logonoff

Damn... so it was caching when I had patched lib/xterm.js and then reverted it cause the patch ended up being 1 MiB...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: macOS Option Key (QWERTZ) Broken in Pod Terminal since OKD 4.20

4 participants