Skip to content

Commit 2d284ba

Browse files
committed
Fix app-breaking javascript re: stimulus-loading
1 parent c468653 commit 2d284ba

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// app/assets/config/better_together_manifest.js
22

33
//= link_tree ../../javascript/better_together .js
4+
// link_tree ../../../vendor/javascript .js
45
//= link_tree ../stylesheets/better_together .css
56
//= link_tree ../images/better_together
67

78
//= link bootstrap.min.js
89
//= link popper.js
910

11+
//= link stimulus.min.js
12+
//= link stimulus-loading.js
13+
//= link turbo.min.js

app/javascript/better_together/application.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616
//= require better_together/tooltips
1717
// require_tree .
1818

19-
import '@hotwired/turbo-rails'
20-
import '@hotwired/stimulus'
21-
import '@hotwired/stimulus-loading'
19+
import { Turbo } from '@hotwired/turbo-rails'
20+
// import { Application } from '@hotwired/stimulus'
2221
// import 'trix'
23-
import '@rails/actiontext'
22+
// import { start as startActionText } from '@rails/actiontext'
2423

25-
import 'better_together/controllers'
24+
import { application } from 'better_together/controllers'
2625
// import 'better_together/trix-extensions/richtext'
2726

2827
// import 'bootstrap'
2928

3029
// Turbo.session.drive = false
3130

32-
console.log('initializing engine')
31+
// const application = Application.start()
32+
33+
console.log('initializing engine')
34+
35+
// window.Stimulus = application
36+
37+
export { application }

app/javascript/better_together/controllers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { application } from "better_together/controllers/application"
77
// eagerLoadControllersFrom("controllers", application)
88

99
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
10-
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
10+
import { lazyLoadControllersFrom } from 'stimulus-loading' // Adjust the path if necessary
1111
lazyLoadControllersFrom("controllers", application)
1212

1313
console.log('initializing engine controllers')
1414

15-
export { }
15+
export { application }

config/importmap.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# frozen_string_literal: true
22

33
# config/importmap.rb
4-
# pin_all_from File.expand_path("../app/assets/javascript", __dir__)
4+
55
pin_all_from File.expand_path('../app/javascript', __dir__)
6+
# pin_all_from File.expand_path('../vendor/javascript', __dir__)
67
pin_all_from 'app/javascript/better_together/controllers', under: 'controllers', to: 'controllers'
78
pin_all_from 'app/javascript/better_together/trix-extensions', under: 'trix-extensions', to: 'trix-extensions'
9+
810
pin '@hotwired/turbo-rails', to: 'turbo.min.js'
911
pin '@hotwired/stimulus', to: 'stimulus.min.js'
10-
pin '@hotwired/stimulus-loading', to: 'stimulus-loading'
11-
# TODO: Check if this is compiled for prod: https://github.com/hotwired/stimulus-rails/issues/108
12+
pin 'stimulus-loading', to: 'stimulus-loading.js', preload: true # Ensure correct path and file extension
1213

1314
pin 'bootstrap', to: 'bootstrap.min.js', preload: true
1415
pin '@popperjs/core', to: 'popper.js', preload: true

lib/better_together/engine.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class Engine < ::Rails::Engine
4747
initializer 'better_together.importmap', before: 'importmap' do |app|
4848
app.config.importmap.paths << Engine.root.join('config/importmap.rb')
4949

50-
# NOTE: something about cache; I did not look into it.
51-
# https://github.com/rails/importmap-rails#sweeping-the-cache-in-development-and-test
50+
# Ensure the cache is swept in development and test environments
5251
app.config.importmap.cache_sweepers << root.join('app/assets/javascripts')
52+
app.config.importmap.cache_sweepers << root.join('app/javascript')
5353
end
5454

55-
# NOTE: add engine manifest to precompile assets in production
55+
# Add engine manifest to precompile assets in production
5656
initializer 'better_together.assets' do |app|
57-
app.config.assets.precompile += %w[better_together_manifest]
57+
app.config.assets.precompile += %w[better_together_manifest.js]
5858
app.config.assets.paths << root.join('app', 'assets', 'images')
5959
app.config.assets.paths << root.join('app', 'javascript')
6060
end
@@ -63,6 +63,11 @@ class Engine < ::Rails::Engine
6363
app.config.action_view.form_with_generates_remote_forms = true
6464
end
6565

66+
# Add custom logging
67+
initializer 'better_together.logging', before: :initialize_logger do |app|
68+
app.config.log_tags = [:request_id, :remote_ip]
69+
end
70+
6671
rake_tasks do
6772
load 'tasks/better_together_tasks.rake'
6873

0 commit comments

Comments
 (0)