Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.3k
Tutorial: How to integrate Hotwire / Turbo / Stimulus in AAv4#8694
-
If you use this, please comment here. Feel free to post any questions and comments. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 10 replies
-
Hello, is this a replacement of#8573? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think it would! I noticed that, by following my instructions above to separate admin and application importmaps, the Output<scripttype="importmap"data-turbo-track="reload">{"imports":{"flowbite":"https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.turbo.min.js","@rails/ujs":"/assets/@rails--ujs-7bfe798b.js","active_admin":"/assets/active_admin-1f4b319c.js","controllers/hw_combobox_controller":"/assets/hotwire_combobox.esm-51aa78e9.js","application":"/assets/application-c8a17222.js","admin":"/assets/admin-f3a1e1e0.js","@hotwired/turbo-rails":"/assets/turbo.min-1262d735.js","@hotwired/stimulus":"/assets/@hotwired--stimulus-132cbc23.js","@hotwired/stimulus-loading":"/assets/stimulus-loading-1fc53fe7.js","@stimulus-components/auto-submit":"/assets/@stimulus-components--auto-submit-6fcf2e50.js","@activeadmin/activeadmin":"/assets/@activeadmin--activeadmin-bed5bb29.js","stimulus-datepicker":"/assets/stimulus-datepicker-bb618857.js","flowbite-datepicker":"/assets/flowbite-datepicker-cf5b6ca8.js","active_admin/features/batch_actions":"/assets/active_admin/features/batch_actions-1d7f386b.js","active_admin/features/dark_mode_toggle":"/assets/active_admin/features/dark_mode_toggle-184c54d4.js","active_admin/features/filters":"/assets/active_admin/features/filters-6c101f9e.js","active_admin/features/has_many":"/assets/active_admin/features/has_many-2ade3ece.js","active_admin/features/main_menu":"/assets/active_admin/features/main_menu-f6d05848.js","active_admin/features/per_page":"/assets/active_admin/features/per_page-375aaac7.js","active_admin/utils/dom":"/assets/active_admin/utils/dom-fd0d5978.js","controllers/application":"/assets/controllers/application-3f3d5175.js","controllers":"/assets/controllers/index-5a48c1ca.js","controllers/map_controller":"/assets/controllers/map_controller-473b4762.js"}}</script><linkrel="modulepreload"href="https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.turbo.min.js"><linkrel="modulepreload"href="/assets/@rails--ujs-7bfe798b.js"><linkrel="modulepreload"href="/assets/active_admin-1f4b319c.js"><linkrel="modulepreload"href="/assets/hotwire_combobox.esm-51aa78e9.js"><linkrel="modulepreload"href="/assets/application-c8a17222.js"><linkrel="modulepreload"href="/assets/admin-f3a1e1e0.js"><linkrel="modulepreload"href="/assets/turbo.min-1262d735.js"><linkrel="modulepreload"href="/assets/@hotwired--stimulus-132cbc23.js"><linkrel="modulepreload"href="/assets/stimulus-loading-1fc53fe7.js"><linkrel="modulepreload"href="/assets/@stimulus-components--auto-submit-6fcf2e50.js"><linkrel="modulepreload"href="/assets/@activeadmin--activeadmin-bed5bb29.js"><linkrel="modulepreload"href="/assets/stimulus-datepicker-bb618857.js"><linkrel="modulepreload"href="/assets/flowbite-datepicker-cf5b6ca8.js"><linkrel="modulepreload"href="/assets/active_admin/features/batch_actions-1d7f386b.js"><linkrel="modulepreload"href="/assets/active_admin/features/dark_mode_toggle-184c54d4.js"><linkrel="modulepreload"href="/assets/active_admin/features/filters-6c101f9e.js"><linkrel="modulepreload"href="/assets/active_admin/features/has_many-2ade3ece.js"><linkrel="modulepreload"href="/assets/active_admin/features/main_menu-f6d05848.js"><linkrel="modulepreload"href="/assets/active_admin/features/per_page-375aaac7.js"><linkrel="modulepreload"href="/assets/active_admin/utils/dom-fd0d5978.js"><linkrel="modulepreload"href="/assets/controllers/application-3f3d5175.js"><linkrel="modulepreload"href="/assets/controllers/index-5a48c1ca.js"><linkrel="modulepreload"href="/assets/controllers/map_controller-473b4762.js"><scripttype="module">import"admin"</script> The only thing that changes is that last line: -<script type="module">import "admin"</script>+<script type="module">import "application"</script> It's leaking the list of JS files/libraries that are being used in the admin to the frontend. What's worse, it also instructs the browser to preload all of these files and so browsers download them even if they don't need/use it. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@thisismydesign do you have any examples of what exactly breaks when you connect ActiveAdmin and Turbo? I haven't had any issues so far. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@vfonic It's the issue you opened:#8573 it's an interaction between flwobite and turbo, so it might be flowbite, but IMO it should work out of the box. And there's this:#8603 (might be fixed already, didn't test yet) |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Reference for flowbite:themesberg/flowbite#796 Semi-OTI'm currently attempting to use flowbite on the front-end of an application, but I've noticed that there is a lot of improvement in the JavaScript part of that library (I'm not a JavaScript developer). I noticed that it is exposing object to I also have issues with tree-shaking, it looks like it's all or nothing because of the This is my implementation to remove some of the features I don't need from the output build, but I'm thinking to move the javascript part to stimulus controllers For this reason too, I would advise not to mix active admin assets with application assets (especially the opposite) importDismissfrom'flowbite/lib/esm/components/dismiss'importDropdownfrom'flowbite/lib/esm/components/dropdown'importModalfrom'flowbite/lib/esm/components/modal'importTooltipfrom'flowbite/lib/esm/components/tooltip'// Turbo patch, vendored from flowbite/lib/esm/index.js// Ref: themesberg/flowbite#796importEventsfrom'flowbite/lib/esm/dom/events'constafterRenderEvent=newEvent('turbo:after-stream-render')constinitFlowbite=function(){window.initDismisses()window.initDropdowns()window.initModals()window.initTooltips()}window.addEventListener('turbo:before-stream-render',function(event){constoriginalRender=event.detail.renderevent.detail.render=function(streamElement){originalRender(streamElement)window.dispatchEvent(afterRenderEvent)}})constturboLoadEvents=newEvents('turbo:load',[initFlowbite])turboLoadEvents.init()constturboFrameLoadEvents=newEvents('turbo:frame-load',[initFlowbite])turboFrameLoadEvents.init()constturboStreamLoadEvents=newEvents('turbo:after-stream-render',[initFlowbite,])turboStreamLoadEvents.init()export{Dismiss,Dropdown,Modal,Tooltip} |
BetaWas this translation helpful?Give feedback.
All reactions
-
The issue I had is fixed by using "Turbo" version of Flowbite JS (as per their documentation): pin"flowbite",to:"https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.turbo.min.js"# @2.5.2 And, I just checked the validation issue |
BetaWas this translation helpful?Give feedback.
