turbo-rails 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5280b7de6628b91f4fc033cdc620a7e2e1bf208f982092b3468a9b964c1c911f
4
- data.tar.gz: a42195f38b5747b2d7a68709ec631d4cbe2722d7b425574f7d09df0cb9bcbadf
3
+ metadata.gz: a6b62b2ebe62c102e59d47bd27106b8e4eb7d13981dcff4f320337c8386a21e6
4
+ data.tar.gz: f5966219c9772a134548f1d21d00b68c52dcaf3a790ea8ed98c5b691fcbf22aa
5
5
  SHA512:
6
- metadata.gz: 4c72a850a046b9effd1e7ed59c5255b74765dcc127071cbbd8143b5bf8e799d0b79878ab7511ce4ed922d6d6cc757663a2d312439ab4b2ea90ddfd949900c7f7
7
- data.tar.gz: 96973ebd86a1e03eb32d8c1bae50f50df35951beb9ed234529f29ef70f0cbf0fd0480f1d690f66f86c329902c6c48ac574f8e381fb24a52fd70bb27967534bc9
6
+ metadata.gz: 1e7c17ae5bf6cdd69f127862e7493bfe7957609b6efffd9632df71904a2453ec91db23336de207d07ada6befeb427a0fec7c65e63661286700a7d7edcbc1124a
7
+ data.tar.gz: 28ea056509d04849be4758049cd558b6b3bc80affd4edf2b4eb66080360e2470ab0faaf8ce7862f5689de37b807bb5c388573a6b4df8d7f55c9c4d16d8d6fc90
data/README.md CHANGED
@@ -6,7 +6,6 @@ On top of accelerating web applications, Turbo was built from the ground-up to f
6
6
 
7
7
  Turbo is a language-agnostic framework written in JavaScript, but this gem builds on top of those basics to make the integration with Rails as smooth as possible. You can deliver turbo updates via model callbacks over Action Cable, respond to controller actions with native navigation or standard redirects, and render turbo frames with helpers and layout-free responses.
8
8
 
9
-
10
9
  ## Navigate with Turbo Drive
11
10
 
12
11
  Turbo is a continuation of the ideas from the previous [Turbolinks](https://github.com/turbolinks/turbolinks) framework, and the heart of that past approach lives on as Turbo Drive. When installed, Turbo automatically intercepts all clicks on `<a href>` links to the same domain. When you click an eligible link, Turbo prevents the browser from following it. Instead, Turbo changes the browser’s URL using the History API, requests the new page using `fetch`, and then renders the HTML response.
@@ -122,7 +121,6 @@ The `Turbo` instance is automatically assigned to `window.Turbo` upon import:
122
121
  import "@hotwired/turbo-rails"
123
122
  ```
124
123
 
125
-
126
124
  ## Usage
127
125
 
128
126
  You can watch [the video introduction to Hotwire](https://hotwired.dev/#screencast), which focuses extensively on demonstrating Turbo in a Rails demo. Then you should familiarize yourself with [Turbo handbook](https://turbo.hotwired.dev/handbook/introduction) to understand Drive, Frames, and Streams in-depth. Finally, dive into the code documentation by starting with [`Turbo::FramesHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/frames_helper.rb), [`Turbo::StreamsHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/streams_helper.rb), [`Turbo::Streams::TagBuilder`](https://github.com/hotwired/turbo-rails/blob/main/app/models/turbo/streams/tag_builder.rb), and [`Turbo::Broadcastable`](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb).
@@ -130,6 +128,17 @@ You can watch [the video introduction to Hotwire](https://hotwired.dev/#screenca
130
128
  ### RubyDoc Documentation
131
129
 
132
130
  For the API documentation covering this gem's classes and packages, [visit the RubyDoc page](https://rubydoc.info/github/hotwired/turbo-rails/main).
131
+ Note that this documentation is updated automatically from the main branch, so it may contain features that are not released yet.
132
+
133
+ - [Turbo Drive Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/DriveHelper)
134
+ - [Turbo Frames Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/FramesHelper)
135
+ - [Turbo Streams View Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/StreamsHelper)
136
+ - [Turbo Streams Broadcast Methods](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable)
137
+ - [Turbo Streams Channel](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/StreamsChannel)
138
+ - [Turbo Native Navigation](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Native/Navigation)
139
+ - [Turbo Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions)
140
+ - [Turbo Integration Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions/IntegrationTestAssertions)
141
+ - [Turbo Broadcastable Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable/TestHelper)
133
142
 
134
143
  ## Compatibility with Rails UJS
135
144
 
@@ -137,18 +146,16 @@ Turbo can coexist with Rails UJS, but you need to take a series of upgrade steps
137
146
 
138
147
  ## Testing
139
148
 
140
-
141
- The [`Turbo::TestAssertions`](./lib/turbo/test_assertions.rb) concern provides Turbo Stream test helpers that assert the presence or absence of `<turbo-stream>` elements in a rendered fragment of HTML. `Turbo::TestAssertions` are automatically included in [`ActiveSupport::TestCase`](https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html) and depend on the presence of [`rails-dom-testing`](https://github.com/rails/rails-dom-testing/) assertions.
149
+ The [`Turbo::TestAssertions`](./lib/turbo/test_assertions.rb) concern provides Turbo Stream test helpers that assert the presence or absence ofs s `<turbo-stream>` elements in a rendered fragment of HTML. `Turbo::TestAssertions` are automatically included in [`ActiveSaupport::TestCase`](https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html) and depend on the presence of [`rails-dom-testing`](https://github.com/rails/rails-dom-testing/) assertions.
142
150
 
143
151
  The [`Turbo::TestAssertions::IntegrationTestAssertions`](./lib/turbo/test_assertions/integration_test_assertions.rb) are built on top of `Turbo::TestAssertions`, and add support for passing a `status:` keyword. They are automatically included in [`ActionDispatch::IntegrationTest`](https://edgeguides.rubyonrails.org/testing.html#integration-testing).
144
152
 
145
- The [`Turbo::Broadcastable::TestHelper`](./lib/turbo/broadcastable/test_helper.rb) concern provides Action Cable-aware test helpers that assert that `<turbo-stream>` elements were or were not broadcast over Action Cable. They are not automatically included. To use them in your tests, make sure to `include Turbo::Broadcastable::TestHelper`.
153
+ The [`Turbo::Broadcastable::TestHelper`](./lib/turbo/broadcastable/test_helper.rb) concern provides Action Cable-aware test helpers that assert that `<turbo-stream>` elements were or were not broadcast over Action Cable. `Turbo::Broadcastable::TestHelper` is automatically included in [`ActiveSupport::TestCase`](https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html).
146
154
 
147
155
  ## Development
148
156
 
149
157
  Run the tests with `./bin/test`.
150
158
 
151
-
152
159
  ## License
153
160
 
154
161
  Turbo is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Turbo 8.0.1
2
+ Turbo 8.0.2
3
3
  Copyright © 2024 37signals LLC
4
4
  */
5
5
  (function(prototype) {
@@ -2647,9 +2647,6 @@ class LinkPrefetchObserver {
2647
2647
  if (turboFrameTarget && turboFrameTarget !== "_top") {
2648
2648
  request.headers["Turbo-Frame"] = turboFrameTarget;
2649
2649
  }
2650
- if (link.hasAttribute("data-turbo-stream")) {
2651
- request.acceptResponseType(StreamMessage.contentType);
2652
- }
2653
2650
  }
2654
2651
  requestSucceededWithResponse() {}
2655
2652
  requestStarted(fetchRequest) {}
@@ -2662,41 +2659,46 @@ class LinkPrefetchObserver {
2662
2659
  }
2663
2660
  #isPrefetchable(link) {
2664
2661
  const href = link.getAttribute("href");
2665
- if (!href || href.startsWith("#") || link.getAttribute("data-turbo") === "false" || link.getAttribute("data-turbo-prefetch") === "false") {
2666
- return false;
2667
- }
2668
- const event = dispatch("turbo:before-prefetch", {
2669
- target: link,
2670
- cancelable: true
2671
- });
2672
- if (event.defaultPrevented) {
2673
- return false;
2674
- }
2675
- if (link.origin !== document.location.origin) {
2676
- return false;
2677
- }
2678
- if (![ "http:", "https:" ].includes(link.protocol)) {
2679
- return false;
2680
- }
2681
- if (link.pathname + link.search === document.location.pathname + document.location.search) {
2682
- return false;
2683
- }
2684
- const turboMethod = link.getAttribute("data-turbo-method");
2685
- if (turboMethod && turboMethod !== "get") {
2686
- return false;
2687
- }
2688
- if (targetsIframe(link)) {
2689
- return false;
2690
- }
2691
- const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
2692
- if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
2693
- return false;
2694
- }
2662
+ if (!href) return false;
2663
+ if (unfetchableLink(link)) return false;
2664
+ if (linkToTheSamePage(link)) return false;
2665
+ if (linkOptsOut(link)) return false;
2666
+ if (nonSafeLink(link)) return false;
2667
+ if (eventPrevented(link)) return false;
2695
2668
  return true;
2696
2669
  }
2697
2670
  }
2698
2671
 
2699
- const targetsIframe = link => !doesNotTargetIFrame(link);
2672
+ const unfetchableLink = link => link.origin !== document.location.origin || ![ "http:", "https:" ].includes(link.protocol) || link.hasAttribute("target");
2673
+
2674
+ const linkToTheSamePage = link => link.pathname + link.search === document.location.pathname + document.location.search || link.href.startsWith("#");
2675
+
2676
+ const linkOptsOut = link => {
2677
+ if (link.getAttribute("data-turbo-prefetch") === "false") return true;
2678
+ if (link.getAttribute("data-turbo") === "false") return true;
2679
+ const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
2680
+ if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true;
2681
+ return false;
2682
+ };
2683
+
2684
+ const nonSafeLink = link => {
2685
+ const turboMethod = link.getAttribute("data-turbo-method");
2686
+ if (turboMethod && turboMethod.toLowerCase() !== "get") return true;
2687
+ if (isUJS(link)) return true;
2688
+ if (link.hasAttribute("data-turbo-confirm")) return true;
2689
+ if (link.hasAttribute("data-turbo-stream")) return true;
2690
+ return false;
2691
+ };
2692
+
2693
+ const isUJS = link => link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method");
2694
+
2695
+ const eventPrevented = link => {
2696
+ const event = dispatch("turbo:before-prefetch", {
2697
+ target: link,
2698
+ cancelable: true
2699
+ });
2700
+ return event.defaultPrevented;
2701
+ };
2700
2702
 
2701
2703
  class Navigator {
2702
2704
  constructor(delegate) {