Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TurboReflex::Runner failed to append the meta tag to the response! undefined method `invoke' #43

Closed
drnic opened this issue Dec 9, 2022 · 13 comments

Comments

@drnic
Copy link
Contributor

drnic commented Dec 9, 2022

I followed installation instructions:

diff --git Gemfile Gemfile
index ca6f079..cd3ad7e 100644
--- Gemfile
+++ Gemfile
@@ -130,3 +130,5 @@ end
 
 # We recommend using strong migrations when your app is in production
 # gem "strong_migrations", "~> 0.7.6"
+
+gem "turbo_reflex", "~> 0.0.28"
diff --git Gemfile.lock Gemfile.lock
index f118ce5..c85fd35 100644
--- Gemfile.lock
+++ Gemfile.lock
@@ -479,6 +479,13 @@ GEM
       actionpack (>= 6.0.0)
       activejob (>= 6.0.0)
       railties (>= 6.0.0)
+    turbo_ready (0.1.2)
+      rails (>= 6.1)
+      turbo-rails (>= 1.1)
+    turbo_reflex (0.0.28)
+      rails (>= 6.1)
+      turbo-rails (>= 1.1)
+      turbo_ready (>= 0.1)
     tzinfo (2.0.5)
       concurrent-ruby (~> 1.0)
     tzinfo-data (1.2022.7)
@@ -584,6 +591,7 @@ DEPENDENCIES
   standard
   stimulus-rails (~> 1.0, >= 1.0.2)
   turbo-rails (~> 1.0, >= 1.0.1)
+  turbo_reflex (~> 0.0.28)
   tzinfo-data
   vcr (~> 6.1)
   view_component (~> 2.78)
diff --git app/javascript/application.js app/javascript/application.js
index 2aec40b..940c8b8 100644
--- app/javascript/application.js
+++ app/javascript/application.js
@@ -3,6 +3,7 @@
 // Rails functionality
 import Rails from "@rails/ujs"
 import { Turbo } from "@hotwired/turbo-rails"
+import "turbo_reflex"
 
 // Make accessible for Electron and Mobile adapters
 window.Rails = Rails
diff --git app/views/layouts/application.html.erb app/views/layouts/application.html.erb
index 6140daf..3b80eba 100644
--- app/views/layouts/application.html.erb
+++ app/views/layouts/application.html.erb
@@ -11,6 +11,7 @@
     <%= csrf_meta_tags %>
     <%= csp_meta_tag %>
     <%= viewport_meta_tag %>
+    <%= turbo_reflex.meta_tag %>
 
     <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
     <%= stylesheet_link_tag "application", media: "all", "data-turbo-track": "reload" %>
diff --git package.json package.json
index a6b6373..b56055e 100644
--- package.json
+++ package.json
@@ -34,7 +34,8 @@
     "tailwindcss-stimulus-components": "^3.0.4",
     "tippy.js": "^6.3.5",
     "tributejs": "^5.1.3",
-    "trix": "^2.0.0"
+    "trix": "^2.0.0",
+    "turbo_reflex": "^0.0.28"
   },
   "scripts": {
     "build:css": "tailwindcss --postcss --minify -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css",
diff --git yarn.lock yarn.lock
index e24f130..eade1fc 100644
--- yarn.lock
+++ yarn.lock
@@ -997,6 +997,11 @@ tslib@^2.0.1:
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
   integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
 
+turbo_reflex@^0.0.28:
+  version "0.0.28"
+  resolved "https://registry.yarnpkg.com/turbo_reflex/-/turbo_reflex-0.0.28.tgz#2e01bf26193a64094b83213a0c03044f7564c138"
+  integrity sha512-hynGvxk1YdA/ubn3eBNaVY7iv9z2TFy/d4vsIYJdPmyFkF1KuG/5SYhxq137I4eDtpLO+JuzU8/wJmc24OOJuQ==
+
 update-browserslist-db@^1.0.9:
   version "1.0.10"
   resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz#0f54b876545726f17d00cd9a2561e6dade943ff3"

But whilst my pages load ok, in my logs I see:

web    | TurboReflex::Runner failed to append the meta tag to the response! undefined method `invoke' for #<Turbo::Streams::TagBuilder:0x000000010cfcddb8 @view_context=#<ActionView::Base:0x00000000043b48>>
web    |
web    |     append_to_response_body turbo_stream.invoke("morph", args: [meta_tag], selector: "#turbo-reflex")

Something extra I need to install or configure?

In my Gemfile.lock I have rails :

    turbo-rails (1.3.2)
      actionpack (>= 6.0.0)
      activejob (>= 6.0.0)
      railties (>= 6.0.0)
    turbo_ready (0.1.2)
      rails (>= 6.1)
      turbo-rails (>= 1.1)
    turbo_reflex (0.0.28)
      rails (>= 6.1)
      turbo-rails (>= 1.1)
      turbo_ready (>= 0.1)

And yarn.lock:

"@hotwired/stimulus@>=3.0.0", "@hotwired/stimulus@^3.0.0", "@hotwired/stimulus@^3.0.1":
  version "3.2.1"
  resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.1.tgz#e3de23623b0c52c247aba4cd5d530d257008676b"
  integrity sha512-HGlzDcf9vv/EQrMJ5ZG6VWNs8Z/xMN+1o2OhV1gKiSG6CqZt5MCBB1gRg5ILiN3U0jEAxuDTNPRfBcnZBDmupQ==

"@hotwired/turbo-rails@^7.2.0":
  version "7.2.4"
  resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.2.4.tgz#d155533e79c4ebdac23e8fe12697d821d5c06307"
  integrity sha512-givDUQqaccd19BvErz1Cf2j6MXF74m0G6I75oqFJGeXAa7vwkz9nDplefVNrALCR9Xi9j9gy32xmSI6wD0tZyA==
  dependencies:
    "@hotwired/turbo" "^7.2.4"
    "@rails/actioncable" "^7.0"

"@hotwired/turbo@^7.2.4":
  version "7.2.4"
  resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.2.4.tgz#0d35541be32cfae3b4f78c6ab9138f5b21f28a21"
  integrity sha512-c3xlOroHp/cCZHDOuLp6uzQYEbvXBUVaal0puXoGJ9M8L/KHwZ3hQozD4dVeSN9msHWLxxtmPT1TlCN7gFhj4w==

Update: I've also tried explicitly installing turbo_ready but afaict the only additional instructions were javascript related - yarn add and import TurboReady etc.

Any protips to get my rails 7/jumpstart pro app to pickup turbo_ready's invoke helper?

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

This happens because TurboReady doesn't auto initialize the client code. I have releases for each lib that should ship today that will address this problem. Here's the first related PR. hopsoft/turbo_boost-streams#26

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

This issue should get resolved with #44

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

This should now be resolved with v0.0.29. Will you give it another shot at let me know if these instructions now work for you? https://github.com/hopsoft/turbo_reflex#setup

@drnic
Copy link
Contributor Author

drnic commented Dec 9, 2022

Hmm, still getting same error.

My app/javascript/application.js is:

/* eslint no-console:0 */

// Rails functionality
import Rails from "@rails/ujs"
import { Turbo } from "@hotwired/turbo-rails"
import "turbo_reflex"

// Make accessible for Electron and Mobile adapters
window.Rails = Rails
window.Turbo = Turbo

require("@rails/activestorage").start()
import "@rails/actiontext"

// ActionCable Channels
import "./channels"

// Stimulus controllers
import "./controllers"

// Jumpstart Pro & other Functionality
import "./src/**/*"
require("local-time").start()

// Start Rails UJS
Rails.start()

I upgraded both gems + npm:

diff --git Gemfile Gemfile
index ea339f5..1b2b414 100644
--- Gemfile
+++ Gemfile
@@ -131,6 +131,4 @@ end
 # We recommend using strong migrations when your app is in production
 # gem "strong_migrations", "~> 0.7.6"
 
-gem "turbo_reflex", "~> 0.0.28"
+gem "turbo_reflex", "~> 0.0.29"
...
diff --git app/javascript/application.js app/javascript/application.js
index 392f2f1..eb3e59e 100644
--- app/javascript/application.js
+++ app/javascript/application.js
@@ -3,7 +3,8 @@
 // Rails functionality
 import Rails from "@rails/ujs"
 import { Turbo } from "@hotwired/turbo-rails"
+import "turbo_reflex"
 
 // Make accessible for Electron and Mobile adapters
 window.Rails = Rails
diff --git package.json package.json
index ed1f33c..9fbcf64 100644
--- package.json
+++ package.json
@@ -26,7 +26,6 @@
     "local-time": "^2.1.0",
     "postcss": "^8.4.8",
     "postcss-import": "^15.0.0",
-    "reflex_behaviors": "^0.0.6",
     "slim-select": "^2.0.0",
     "stimulus-flatpickr": "^3.0.0-0",
     "stimulus-hotkeys": "^2.2.0",
@@ -36,8 +35,8 @@
     "tippy.js": "^6.3.5",
     "tributejs": "^5.1.3",
     "trix": "^2.0.0",
-    "turbo_ready": "^0.1.2",
-    "turbo_reflex": "^0.0.28"
+    "turbo_ready": "^0.1.3",
+    "turbo_reflex": "^0.0.29"
   },
   "scripts": {
     "build:css": "tailwindcss --postcss --minify -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css",
diff --git yarn.lock yarn.lock
index c530c24..2fee0d6 100644
--- yarn.lock
+++ yarn.lock
@@ -44,10 +44,10 @@
   resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.2.4.tgz#0d35541be32cfae3b4f78c6ab9138f5b21f28a21"
   integrity sha512-c3xlOroHp/cCZHDOuLp6uzQYEbvXBUVaal0puXoGJ9M8L/KHwZ3hQozD4dVeSN9msHWLxxtmPT1TlCN7gFhj4w==

 resolve@^1.1.7, resolve@^1.22.1:
   version "1.22.1"
   resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177"
@@ -918,9 +910,9 @@ select@^1.1.2:
   integrity sha512-OwpTSOfy6xSs1+pwcNrv0RBMOzI39Lp3qQKUTPVVPRjCdNa5JH/oPRiqsesIskK8TVgmRiHwO4KXlV2Li9dANA==
  
 source-map-js@^1.0.2:
   version "1.0.2"
@@ -1029,18 +1021,20 @@ tslib@^2.0.1:
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
   integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
 
-"turbo_ready@>= 0.1.2", turbo_ready@^0.1.2:
-  version "0.1.2"
-  resolved "https://registry.yarnpkg.com/turbo_ready/-/turbo_ready-0.1.2.tgz#0aa812c0661073106e6efea2f1af41d7b6786e44"
-  integrity sha512-CwJJ2sz72cuNBQuECH2K3H8R9Zb8d3jppK61+i+PwMxPXM8dyL3Rj4K23JPR5RnUBQGIPwxmAVdmPXQxQJoYCA==
+"turbo_ready@>= 0.1.3", turbo_ready@^0.1.3:
+  version "0.1.3"
+  resolved "https://registry.yarnpkg.com/turbo_ready/-/turbo_ready-0.1.3.tgz#e54cd1539a0808307d8e68dbfe5c507af48baf72"
+  integrity sha512-fglj2qohy7llj9Jxj/g9S//uZefE2NdORrRaxu3ZHwLLb7Rge+brgSzDfc6/doa+BReIXwiwd8Yql1k2bGsopg==
   dependencies:
     "@alpinejs/morph" ">=3.10.4"
     alpinejs ">=3.10.4"
 
-"turbo_reflex@>= 0.0.28", turbo_reflex@^0.0.28:
-  version "0.0.28"
-  resolved "https://registry.yarnpkg.com/turbo_reflex/-/turbo_reflex-0.0.28.tgz#2e01bf26193a64094b83213a0c03044f7564c138"
-  integrity sha512-hynGvxk1YdA/ubn3eBNaVY7iv9z2TFy/d4vsIYJdPmyFkF1KuG/5SYhxq137I4eDtpLO+JuzU8/wJmc24OOJuQ==
+turbo_reflex@^0.0.29:
+  version "0.0.29"
+  resolved "https://registry.yarnpkg.com/turbo_reflex/-/turbo_reflex-0.0.29.tgz#c2341e6ea7b880d1a9051d7d2b4792a84079ffe9"
+  integrity sha512-dl/iEAll86laCR5bFpJIL2/ldWbr0LwdFjZ+6neFTTtroHH51bSgObHVFWqbxM0KP17YxpVGRgSj+s7EEKvKyQ==
+  dependencies:
+    turbo_ready ">= 0.1.3"
 
 update-browserslist-db@^1.0.9:
   version "1.0.10"

My javascript console logs look happy:

TurboReady has initialized and has registered new stream actions with Turbo.

My <head> section looks right:

<meta id="turbo-reflex" name="turbo-reflex" content="BAhJIhVlalpyT2UyLUZ6T2tmYTVJBjoGRUY=--bfc7a59241fd8ef22489b257f7a8aefd3af81213ff0872dad8ffae8a99378831" data-busy="false" data-state="e30">

But bin/dev logs still contain:

web    |   Rendered layout layouts/application.html.erb (Duration: 14.9ms | Allocations: 13292)
web    | TurboReflex::Runner failed to append the meta tag to the response! undefined method `invoke' for #<Turbo::Streams::TagBuilder:0x000000010c1bbab8 @view_context=#<ActionView::Base:0x00000000044688>>
web    |
web    |     append_to_response_body turbo_stream.invoke("morph", args: [meta_tag], selector: "#turbo-reflex")
web    |                                         ^^^^^^^
web    | Completed 200 OK in 31ms (Views: 14.3ms | ActiveRecord: 4.0ms | Allocations: 24781)

I also tried following install instructions in to fresh jumpstart_pro app and get same result. /cc @excid3 perhaps could @hopsoft have access to JSP if it helps him debug the startup sequence of turbo_reflex?

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

I wonder if it's related to how you're importing Turbo. The latest turbo libs implicitly expose the global Turbo on window.

So this code.

import { Turbo } from "@hotwired/turbo-rails"
window.Turbo = Turbo

Could be changed to.

import "@hotwired/turbo-rails"
// Both window.Turbo and Turbo will implicitly be setup for you

I wonder if I should expose an option to explicitly register/initialize TurboReady's stream actions where you pass in either Turbo or Turbo.StreamActions.

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

After initialization you should see that Turbo.StreamActions.invoke is a function.

@excid3
Copy link

excid3 commented Dec 9, 2022

The error is from Ruby, so what's the Javascript piece have to do with it?

@hopsoft
Copy link
Owner

hopsoft commented Dec 9, 2022

Ah yeah. Been chasing a different but similar problem on the client. This looks like you may just be missing the turbo_ready GEM.

@drnic
Copy link
Contributor Author

drnic commented Dec 9, 2022

I'll be back in couple hours to try/relook

@drnic
Copy link
Contributor Author

drnic commented Dec 10, 2022

Ok I manually bundle add turbo_ready and it's now working. But turbo_ready is a gem dependency of turbo_reflex so i'm unsure why it didn't get added to my Gemfile.lock.

diff --git Gemfile Gemfile
index 1b2b414..6038062 100644
--- Gemfile
+++ Gemfile
@@ -132,3 +132,5 @@ end
 # gem "strong_migrations", "~> 0.7.6"

 gem "turbo_reflex", "~> 0.0.29"
+
+gem "turbo_ready", "~> 0.1.3"
diff --git Gemfile.lock Gemfile.lock
index c53acc6..4644a7b 100644
--- Gemfile.lock
+++ Gemfile.lock
@@ -593,6 +593,7 @@ DEPENDENCIES
   standard
   stimulus-rails (~> 1.0, >= 1.0.2)
   turbo-rails (~> 1.0, >= 1.0.1)
+  turbo_ready (~> 0.1.3)
   turbo_reflex (~> 0.0.29)
   tzinfo-data
   vcr (~> 6.1)

@drnic
Copy link
Contributor Author

drnic commented Dec 10, 2022

I guess bundler will autoload turbo_ready if its in the Gemfile, but not if its just a dependency of another gem?

drnic added a commit to drnic/turbo_reflex that referenced this issue Dec 10, 2022
@hopsoft
Copy link
Owner

hopsoft commented Dec 10, 2022

Good news. #48 requires the TurboReady dependency for you implicitly which will resolve this problem.

@hopsoft
Copy link
Owner

hopsoft commented Dec 10, 2022

Just realized you did the same with #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants