@hotwired/turbo-rails 8.0.1 → 8.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -146,11 +146,11 @@ Turbo can coexist with Rails UJS, but you need to take a series of upgrade steps
146
146
 
147
147
  ## Testing
148
148
 
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.
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 [`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.
150
150
 
151
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).
152
152
 
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. 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).
154
154
 
155
155
  ## Development
156
156
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Turbo 8.0.1
2
+ Turbo 8.0.3
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) {
@@ -3816,7 +3818,6 @@ class MorphRenderer extends PageRenderer {
3816
3818
  #morphElements(currentElement, newElement, morphStyle = "outerHTML") {
3817
3819
  this.isMorphingTurboFrame = this.#isFrameReloadedWithMorph(currentElement);
3818
3820
  Idiomorph.morph(currentElement, newElement, {
3819
- ignoreActiveValue: true,
3820
3821
  morphStyle: morphStyle,
3821
3822
  callbacks: {
3822
3823
  beforeNodeAdded: this.#shouldAddElement,
@@ -4145,9 +4146,9 @@ class Session {
4145
4146
  refresh(url, requestId) {
4146
4147
  const isRecentRequest = requestId && this.recentRequests.has(requestId);
4147
4148
  if (!isRecentRequest) {
4148
- this.cache.exemptPageFromPreview();
4149
4149
  this.visit(url, {
4150
- action: "replace"
4150
+ action: "replace",
4151
+ shouldCacheSnapshot: false
4151
4152
  });
4152
4153
  }
4153
4154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotwired/turbo-rails",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
4
4
  "description": "The speed of a single-page web application without having to write any JavaScript",
5
5
  "module": "app/javascript/turbo/index.js",
6
6
  "main": "app/assets/javascripts/turbo.js",
@@ -13,7 +13,7 @@
13
13
  "release": "npm publish && git commit -am \"$npm_package_name v$npm_package_version\" && git push"
14
14
  },
15
15
  "dependencies": {
16
- "@hotwired/turbo": "^8.0.1",
16
+ "@hotwired/turbo": "^8.0.3",
17
17
  "@rails/actioncable": "^7.0"
18
18
  },
19
19
  "devDependencies": {