Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Rails console IRB's autocompletion in production by default. #46656

Merged

Conversation

st0012
Copy link
Contributor

@st0012 st0012 commented Dec 6, 2022

Motivation / Background

  1. Autocompletion increases data transmission significantly. This could cause noticeable slowdown when connecting to remote servers, which is usually the case in production.
  2. The autocompletion feature still has many issues, as listed in Autocompletion Meta Issue ruby/irb#445. They may be just annoying when happened locally, but in production they could cause real issues (e.g. typos caused by slow backspacing).

Due to these reasons, I think it's safer to disable this feature in production.

Detail

Because IRB.start doesn't take configuration arguments and rebuilds the IRB.conf object, the only way we can turn off autocompletion is through the IRB_USE_AUTOCOMPLETE env var.

The env var was added in ruby/irb#469 and will be available in IRB 1.6+ and Ruby 3.2+. The name wasn't used before so it won't cause issues with older IRB versions.

Additional information

Users can still override this by setting IRB_USE_AUTOCOMPLETE=true.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Reasons behind this change:

1. Autocompletion increases data transmission significantly. This could
   cause noticeable slowdown when connecting to remote servers, which is
   usually the case in production.
2. The autocompletion feature still has many issues, as listed in
   ruby/irb#445. They may be just annoying
   when happened locally, but in production they could cause real
   issues (e.g. typos caused by slow backspacing).

Due to these reasons, I think it's safer to disable this feature in
production.

About the implementation:

Because `IRB.start` doesn't take configuration arguments and rebuilds
the `IRB.conf` object, the only way we can turn off autocompletion is
through the `IRB_USE_AUTOCOMPLETE` env var.

The env var was added in ruby/irb#469 and will
be available for IRB 1.6+ and Ruby 3.2+.

The name wasn't used before so it won't cause issues with older IRB
versions.

Note: Users can still turn it back on with `IRB_USE_AUTOCOMPLETE=true`
@rails-bot rails-bot bot added the railties label Dec 6, 2022
@eileencodes eileencodes merged commit ba2a660 into rails:main Dec 6, 2022
@eileencodes eileencodes deleted the disable-irb-autocompletion-in-production branch December 6, 2022 15:44
eileencodes added a commit that referenced this pull request Dec 6, 2022
In #46656 we disable the IRB autocompletion if it's production. The
original PR used `== "production"` but it's cleaner if we use the
`production?` helper instead.
eileencodes added a commit that referenced this pull request Dec 6, 2022
…production

Disable Rails console IRB's autocompletion in production by default.
eileencodes added a commit that referenced this pull request Dec 6, 2022
In #46656 we disable the IRB autocompletion if it's production. The
original PR used `== "production"` but it's cleaner if we use the
`production?` helper instead.
@eileencodes
Copy link
Member

Thank you @st0012!

Backported to 7-0-stable in cc125a0 and 7163a13.

@jarthod
Copy link

jarthod commented Dec 9, 2022

Thanks @st0012, I complained a lot about this completion when connecting to production servers (and locally to a smaller extent) and wondered if I was the only one, apparently not :)

@krtschmr
Copy link

great PR. thanks!

@@ -38,6 +38,10 @@ def initialize(app, options = {})

if @console == IRB
IRB::WorkSpace.prepend(BacktraceCleaner)

if Rails.env == "production"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to not use Rails.env.production? or even reverse the logic and set this only in development so all other environments (for example I have seen staging environment used often) will not be affected by completion?

Copy link

@krtschmr krtschmr Feb 25, 2023

Choose a reason for hiding this comment

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

i would agree with the idea of reversing it and only enable it by default on development.

in a perfect world, i would disable it for all environments and let the dev decide when to enable it, explicitly. either via development.rb or ENV var

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants