Skip to content

Commit 1ca27cc

Browse files
committed
Documented a breaking change regarding imports in @rails/ujs 7.1.0
1 parent 344e59e commit 1ca27cc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

guides/source/upgrading_ruby_on_rails.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ See the [Testing Rails Applications](https://guides.rubyonrails.org/testing.html
257257

258258
If you run a single file's tests (`bin/rails test test/models/user_test.rb`), `test:prepare` will not run before it.
259259

260+
### Import syntax from `@rails/ujs` is modified
261+
262+
Starting from Rails 7.1, the syntax for importing modules from `@rails/ujs` is modified. Rails no longer supports the
263+
direct import of a module from `@rails/ujs`. If users create and build a JavaScript file with the line `import
264+
{ fileInputSelector } from "@rails/ujs"`, they will encounter the error `export 'fileInputSelector'
265+
(imported as 'fileInputSelector') was not found in '@rails/ujs' (possible exports: default)`.
266+
267+
In Rails 7.1, users should first import the Rails object directly from `@rails/ujs`.
268+
Users can then import specific modules from the Rails object.
269+
270+
An example of imports in Rails 7.1 is shown below:
271+
272+
```javascript
273+
import Rails from "@rails/ujs"
274+
// Alias the method
275+
const fileInputSelector = Rails.fileInputSelector
276+
// Alternatively, reference it from the Rails object where it is used
277+
Rails.fileInputSelector(...)
278+
```
279+
260280
### `ActionView::TestCase#rendered` no longer returns a `String`
261281

262282
Starting from Rails 7.1, `ActionView::TestCase#rendered` returns an object that

0 commit comments

Comments
 (0)