The driver being used is an implementation detail of `redis-rb`.
If somehow something break on one driver but not the other, it should
be reported to redis-rb and fixed there.
Also `redis-rb` `5.0` has a totally new client and hiredis binding
so all this code no longer works with redis-rb 5.0.
Fixes https://github.com/rails/rails/issues/45489
- Adds `anchor: true` to the Action Cable server mount, so that it only strictly matches `/cable` rather than anything that starts with that.
- Uses `reverse_merge` instead of `merge` in `Mapper#mount`, so that you can override these options if you need to.
* main: (21 commits)
feat: action cable connection callbacks
fix: action cable stream_test errors
Adds test coverage for #attach method behaviour in activestorage
Address QueryCacheTest#test_query_cache_does_not_allow_sql_key_mutation failure
Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services
Fixes development Action Mailbox new mail form
Squash commits
Include the unexpected class in InvalidParameterKey message
Support unbounded time ranges for PostgreSQL
Fix CHANGELOG alignment [ci-skip]
Add ability to ignore tables by regexp for SQL schema dumps
Improve `rails s` error message when no server could be found.
Fix MySQL warning when creating Active Record's test databases
Add `--js` and --skip-javascript` options to `rails new`
Fix parsing operator classes for index columns in PostgreSQL
Fix rails test command to handle leading dot slash
Document that url_for can take classes
Don't change the encoding of frozen parameters
Update working_with_javascript_in_rails.md
Avoid query from calculations on contradictory relation
...
I am trying to find a sweet spot here.
Personally, not quite satisfied by having lib/action_cable/zeitwerk.rb. At the
same time, trying to avoid too taking much space in lib/action_cable.rb.
This patch also moves
require_relative "action_cable/version"
within ActionCable. Why? In a project, I like that the entrypoint defines the
namespace. That is the main file for that namespace.
Then, files below have it already created, and reopen it.
I just find this deliberate order of execution to be natural, hierarchical,
matching the project structure.
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.
This commit removes markup from various API references so that those
references will link to the relevant API docs.
"Overwrite" means "destructively replace", and is more suitable when,
for example, talking about writing data to a location.
"Override" means "supersede", and is more suitable when, for example,
talking about redifining methods in a subclass.
actioncable.js and actioncable.esm.js is not included to gem package. It prevented us from using the action cable when using importmaps.
This adds the missing asset files to gem package.
The current module field points to a file that isn't included in the
files field of actioncable's package.json. This leads to errors when
trying to use actioncable in bundlers that use esm modules natively
(like Vite)
A SubscriptionGuarantor maintains a set of pending subscriptions,
resending the subscribe command unless and until the subscription
is confirmed or rejected by the server or cancelled client-side.
A race condition in the ActionCable server - where an unsubscribe
is sent, followed rapidly by a subscribe, but handled in the reverse
order - necessitates this enhancement. Indeed, the subscriptions created
and torn down by Turbo Streams amplifies the existence of this race
condition.
ruby/debug is a new debugger that is going to ship with CRuby.
It makes sense for Rails to switch to this one because that is
where the language is heading, and because Byebug is not fully
compatible with Zeitwerk. See
https://github.com/deivid-rodriguez/byebug/issues/564
While ruby/debug has not been heavily tested with Zeitwerk,
casual usage seems to suggest it works without issues, including
explicit namespaces, which is where Byebug and Zeitwerk conflict.
Byebug is terrific, thanks a lot for all these years. ❤️
* Switch to a single controller option for choosing JavaScript approach
* Remove remnants of webpacker specific work within Rails
* No longer used
* Missing space
* Raise if unknown option is passed
* Style
* Use latest versions
* Make channels setup generic to all node setups
* Make Action Text installer work with any node package manager
* Explaining variables are not useless
* Rubocop pleasing
* Don't rely on Rails.root
Tests don't like it!
* Rubocopping
* Assume importmap
* No longer relevant
* Another cop
* Style
* Correct installation notice
* Add dependencies for action cable when adding a channel
* Fix paths to be relative to generator
* Just go straight to yarn, forget about binstub
* Fix tests
* Fixup installer, only yarn once
* Test generically with run
* Style
* Fix reference and reversibility
* Style
* Fix test
* Test pinning dependencies
* Remove extra space
* Add more tests
* Use latest dependencies
* Relegated this to controllers
* Refactor ChannelGenerator + more tests
Use a uniform level of abstraction
* Turbolinks is being replaced with Hotwire
* Make --webpack opt-in
* Don't use specific webpacker installers any more in preparation for next Webpacker
* Update railties/lib/rails/app_updater.rb
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
* Trailing whitespace
* Convert to Turbo data attribute for tracking
* Default is no webpack, no hotwire
* Swap out turbolinks references for hotwire
* Drop explicit return
* Only generate package.json if using webpack
* Only create package.json in webpack mode
* Only create app/javascript in webpack mode
* Generate correct style/js links based on js mode
* Fix tests from changed output format
Not sure why these are showing up in this PR, though.
* Rubocopping
* Stick with webpack for the test app for now
* Adjust tests
* Replace minitest-reporters with minitest-ci (#43016)
minitest-reporters is used to create junit xml reports on CI.
But when it loads before rails minitest plugin makes
`Rails::TestUnitReporter` not being added as a reporter.
minitest-ci is now only loaded at ci and does not interferes with
rails minitest plugins. And keeps junit reports workings
* Too heavy handed to actually run bundle
Just like we don't auto-migrate
* Pin js frameworks in importmap
Instead of having importmap preconfigure it.
* Match updated app/javascript path
* No need for the explaining comment
* Fixes test cases for replace webpack with importmapped Hotwire as default js (#42999)
* Fix rubocop issues
* Fix more railities test cases
* Fix plugin generator railties shared test cases
* Fix Action Text install generator asset pipeline spec
* They're modules, not files
* Let dev use the latest release as well
So we don't have to replace unexisting dev releases with latest release
* Make Webpack responsible for generating all the JS files it needs
Webpacker 6 has already moved from app/javascript to app/packs.
* Don't add rails/ujs by default any longer
All the ajax/form functionality has been superseded by Turbo. The rest lives in a weird inbetween land we need to address through other means.
* Use new importmap location
* Switch to using turbo-rails and stimulus-rails directly
The hotwire-rails gem does not offer enough value for its indirection
* Use latest Webpacker
* Prevent version resolution requests from getting swallowed
* Use ESM syntax for imports
* Move management of yarn, package.json, etc to Webpacker 6
* Update for Webpacker 6
* Move bin/setup addition to Webpacker as well
* Remove dead tests
* Bump to Webpacker 6.0.0.rc.2
* No longer relevant given the new default is no webpacker
* Rely on Webpacker 6
* No longer relevant
* No longer relevant
* Make cable channel generator work for both webpacker and importmap setups
* Fix tests
* For tests testing importmap way
* Use Webpacker 6 dummy
* RuboCopping
* One more bump to fix webpack-dev-server
* Another bump. Hopefully the last one!
* Also enough to not want turbo tracking on
* Fix tests
* Latest
* Fix tests
* Fix more tests
* Fix tests
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
* Output Action Cable JS without transpiling and as ESM
* Retain umd version under the old name, generate ESM version + duplicate under new name
* Precompile JavaScripts for direct asset pipeline use
* We've dropped support for IE11
* Include deprecation notice for the old file reference
Thanks @rafaelfranca 👍
* Allow app to opt out of precompiling actioncable js assets
cc @rafaelfranca
* Add changelog entries
Follow up to https://github.com/rails/rails/pull/37313
- Adds regression tests
- Logs a warning in cases where assertions are nested in a way that's likely to be confusing
We refer to `model` elsewhere in Action Cable's implementation, so use
the same in `stream_or_reject_for` as well to keep the consistency.
Simplify the docs for the method to remove the usage "intention"
(that's not up to us) and mention it rejects the "subscription", not
the "connection".
RDoc Markup does not support backticks the way Markdown does to mark up
inline code. Additionally, `<tt>` must be used to mark up inline code
that includes spaces or certain punctuation characters (e.g. quotes).
This commit makes a few changes to the Action Cable client to prevent a
"thundering herd" of client reconnects after server connectivity loss:
* The client will wait a random amount between 1x and 3x of the stale
threshold after the server's last ping before making the first
reconnection attempt.
* Subsequent reconnection attempts now use exponential backoff instead
of logarithmic backoff. To allow the delay between reconnection
attempts to increase slowly at first, the default exponentiation base
is < 2.
* Random jitter is applied to each delay between reconnection attempts.
Co-authored-by: John Williams <john@veloshots.com>
Closes#40482
Prior to this commit it was possible to subscribe with
`ActionCable::Channel::Base` as the subscription class. While it doesn't
seem possible to exploit this in away way, it also doesn't seem like
something we need to allow.
This commit swaps [Module#>=][gte] with [Module#>][gt] to prevent
subscribing to a channel when `ActionCable::Channel::Base` is the
subscription class.
[gte]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E-3D
[gt]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E
Since #37850, `config_for` returns `nil` instead of an empty Hash when
a config file does not contain configuration for the specified
environment. Thus, the return value should be converted to a Hash
before calling `with_indifferent_access`.
Fixes#40548.
The `linguist-vendored` attribute excludes the specified file from the
project's language stats on GitHub. The `linguist-generated` attribute
does the same, and also suppresses that file in diffs on GitHub.
See https://github.com/github/linguist for more information.
Follow up to c07dff7227.
Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.
I've checked all those usage and replaced all safe ones.
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
and update ActionCable guide to describe exception handling usage
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes to be committed:
# modified: actioncable/CHANGELOG.md
# modified: actioncable/lib/action_cable/connection/base.rb
# modified: actioncable/lib/action_cable/connection/subscriptions.rb
# modified: actioncable/test/connection/subscriptions_test.rb
# modified: guides/source/action_cable_overview.md
#
* You can distinguish connection among others with specific `application_name`
```sql
SELECT application_name FROM pg_stat_activity;
/*
application_name
------------------------
psql
ActionCable-PID-42
(2 rows)
*/
```
* It's possible to customize connection identification with `id` option in `cable.yml`
`ActionCable-PID-#{$$}` is the default value
* Related tests refactoring
* `ActionCable::Server#config.cable` is no mutated anymore inside Redis subscription adapter
We have run into issues in the past where the actioncable compiled
javascript bundle got out of sync with the source code. For example, in
30a0c7e040 only the compiled bundle was
modified. This meant that anyone who ran `yarn build` in the actioncable
directory would then see a dirty git status indicating changes to the
compiled bundle, despite not having made any changes to the actioncable
javascript source code. We fixed that particular inconsistency in
a4c27588d5. However, the same problem
could reoccur.
To address this, I've added a new test to enforce that actioncable's
compiled javascript bundle is in sync with the source code. When the
compiled bundle is in sync with the source code, the test will pass:
$ bundle exec ruby -Itest test/javascript_package_test.rb
Run options: --seed 19308
# Running:
yarn run v1.12.3
$ yarn lint && bundle exec rake assets:codegen
$ eslint app/javascript
$ rollup --config rollup.config.js
app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
created app/assets/javascripts/action_cable.js in 762ms
✨ Done in 6.35s.
.
Finished in 7.130345s, 0.1402 runs/s, 0.1402 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
However, if the two are not in sync, the test will fail. For example, if
you were to apply the following patch (which only updates the source
code):
```
diff --git a/actioncable/app/javascript/action_cable/adapters.js b/actioncable/app/javascript/action_cable/adapters.js
index 4de8131438..d38d9a6a0b 100644
--- a/actioncable/app/javascript/action_cable/adapters.js
+++ b/actioncable/app/javascript/action_cable/adapters.js
@@ -1,4 +1,5 @@
export default {
+ foo: self.foo,
logger: self.console,
WebSocket: self.WebSocket
}
```
the test would then fail like this:
$ bundle exec ruby -Itest test/javascript_package_test.rb
Run options: --seed 26377
# Running:
yarn run v1.12.3
$ yarn lint && bundle exec rake assets:codegen
$ eslint app/javascript
$ rollup --config rollup.config.js
app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
created app/assets/javascripts/action_cable.js in 776ms
✨ Done in 5.55s.
F
Failure:
JavascriptPackageTest#test_compiled_code_is_in_sync_with_source_code [test/javascript_package_test.rb:16]:
--- expected
+++ actual
@@ -3,6 +3,7 @@
})(this, function(exports) {
\"use strict\";
var adapters = {
+ foo: self.foo,
logger: self.console,
WebSocket: self.WebSocket
};
rails test test/javascript_package_test.rb:9
Finished in 5.837403s, 0.1713 runs/s, 0.1713 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Thus, the actioncable test suite will now prevent "the compiled bundle
is out of sync" issues going forward.