Skip to content

Conversation

@edmundhung
Copy link
Contributor

@edmundhung edmundhung commented Nov 10, 2025

Fixes #15781.
Closes #15881.

This fixes an issue where calling bindCLIShortcuts() multiple times would create duplicate readline instances and lose custom shortcuts from previous calls. This is useful for plugins adding their own shortcuts while Vite CLI continues to print the help message.

Now when you bind shortcuts multiple times, they are properly merged, with new custom shortcuts taking priority:

server.bindCLIShortcuts({
  customShortcuts: [
    { key: 's', description: 'My shortcut', action: () => console.log('foo') },
    { key: 'g', description: 'Greeting', action: () => console.log('Hello World') },
  ]
});

// The "enter + g" shortcut will remain available after binding
server.bindCLIShortcuts({
  customShortcuts: [
    // This overrides the previous "enter + s" shortcut
    { key: 's', description: 'my updated shortcut', action: () => console.log('foobar') },
  ]
});

This works for both dev and preview server.

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Nov 11, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

Looks good thanks!

await vi.waitFor(() => expect(xUpdatedAction).toHaveBeenCalledOnce())

// Ensure original xAction is not called again
expect(xAction).not.toBeCalled()
Copy link
Member

Choose a reason for hiding this comment

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

It's probably a miss-understanding of the mocking system but I don't understand this assertion. Does using toHaveBeenCalledOnce above "reset" the counter? Otherwise I would have use toHaveBeenCalledOnce again

Copy link
Contributor Author

@edmundhung edmundhung Nov 11, 2025

Choose a reason for hiding this comment

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

I reset the counter with xAction.mockClear() right before calling bindCLIShortcuts again. If you find it confusing, happy to remove that and just assert whether xAction is still only called once.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I missed that line. Ok makes more sense thanks. I think it just taste then so no need to change

@sapphi-red sapphi-red merged commit 5909efd into vitejs:main Nov 12, 2025
17 checks passed
@edmundhung
Copy link
Contributor Author

Thanks for the review, @sapphi-red and @ArnaudBarre 🙌🏼

renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 20, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 21, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 22, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 23, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 24, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 25, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 26, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.2.2 | 7.2.4 |


## [v7.2.4](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-724-2025-11-20-small)

##### Bug Fixes

- revert "perf(deps): replace debug with obug ([#21107](vitejs/vite#21107))" ([2d66b7b](vitejs/vite@2d66b7b))


## [v7.2.3](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-723-2025-11-20-small)

##### Bug Fixes

- allow multiple `bindCLIShortcuts` calls with shortcut merging ([#21103](vitejs/vite#21103)) ([5909efd](vitejs/vite@5909efd))
- **deps:** update all non-major dependencies ([#21096](vitejs/vite#21096)) ([6a34ac3](vitejs/vite@6a34ac3))
- **deps:** update all non-major dependencies ([#21128](vitejs/vite#21128)) ([4f8171e](vitejs/vite@4f8171e))

##### Performance Improvements

- **deps:** replace debug with obug ([#21107](vitejs/vite#21107)) ([acfe939](vitejs/vite@acfe939))

##### Miscellaneous Chores

- **deps:** update dependency [@rollup/plugin-commonjs](https://github.com/rollup/plugin-commonjs) to v29 ([#21099](vitejs/vite#21099)) ([02ceaec](vitejs/vite@02ceaec))
- **deps:** update rolldown-related dependencies ([#21095](vitejs/vite#21095)) ([39a0a15](vitejs/vite@39a0a15))
- **deps:** update rolldown-related dependencies ([#21127](vitejs/vite#21127)) ([5029720](vitejs/vite@5029720))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bindCLIShortcuts need a new option to disable default shortcuts

3 participants