Skip to content

Commit 0b3cafe

Browse files
authored
Merge pull request rails#49857 from mguan2020/ujsfix
Documented a breaking change regarding imports in @rails/ujs 7.1.0 [ci skip]
2 parents 2416cc1 + ed04556 commit 0b3cafe

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

guides/source/upgrading_ruby_on_rails.md

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

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

261+
### Import syntax from `@rails/ujs` is modified
262+
263+
Starting from Rails 7.1, the syntax for importing modules from `@rails/ujs` is modified. Rails no longer supports the
264+
direct import of a module from `@rails/ujs`.
265+
266+
For example, attempting to import a function from the library will fail:
267+
268+
\```
269+
import { fileInputSelector } from "@rails/ujs"
270+
#=> export 'fileInputSelector' (imported as 'fileInputSelector') was not found in '@rails/ujs' (possible exports: default)
271+
\```
272+
273+
In Rails 7.1, users should first import the Rails object directly from `@rails/ujs`.
274+
Users can then import specific modules from the Rails object.
275+
276+
An example of imports in Rails 7.1 is shown below:
277+
278+
```javascript
279+
import Rails from "@rails/ujs"
280+
// Alias the method
281+
const fileInputSelector = Rails.fileInputSelector
282+
// Alternatively, reference it from the Rails object where it is used
283+
Rails.fileInputSelector(...)
284+
```
285+
261286
### `ActionView::TestCase#rendered` no longer returns a `String`
262287

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

0 commit comments

Comments
 (0)