GithubHelp home page GithubHelp logo

Comments (9)

jasonfb avatar jasonfb commented on June 26, 2024

as this point, the only way I can get stimulus working on new Rails 7 apps is to use neither --css=bootstrap nor --javascript=webpack

when I use either of these, I get some kind of a "registry" file at app/javascript/controllers/applicationl.js (see below)

please note that this file is inconsistent with what is generated by the default rails new, which uses a dynamic loader that makes the registering of each Stimulus class name (and thus rebuilding of this file) unnecessary.

However, when I copy the dynamic loader content into an app generated in this registry-style pattern, it doesn't seem to work. (That is, I can't seem to swap out the dynamic loader content for the registry content.)

TO be clear, under these circumstances, I can't get get any Stimulus controllers to load at all, with or without the dynamic loader. It is only with the default rails new that I can get the stimulus controllers to load.

here is the registry loader that comes with --css=bootstrap or --javascript=webpack

// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { application } from "./application"

import HelloController from "./hello_controller"
application.register("hello", HelloController)

from jsbundling-rails.

dhh avatar dhh commented on June 26, 2024

I can't replicate this on Rails 7.0.1. When you start with --javascript=webpack you get the static index loader by design. The dynamic loader is only intended to be used with import maps.

Steps to get things working:

  1. rails new testapp --javascript=webpack
  2. rails generate scaffold post title:string
  3. Add <div data-controller="hello"></div> to app/views/posts/index.html.erb
  4. See "Hello World" from Stimulus on localhost:3000/posts

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

hmm... this is most odd. I am doing these exact steps but I am not getting this. I am still seeing my own original error (no stimulus controllers connected). I am using the latest version of Chrome and have been over it several times...

let me re-create here:

rails new testapp --javascript=webpack

Rails new initial commit:
https://github.com/jasonfb/js-bundling-issue74/commit/fcf75494d4152ad0ebb44ee3f69537465b2c2219

rails generate scaffold post title:string

this generates:

https://github.com/jasonfb/js-bundling-issue74/commit/de9d15df449732a6052ccb260142b7b169f87b8e

Add

to app/views/posts/index.html.erb

testapp – index html erb 2022-01-26 10-58-32

https://github.com/jasonfb/js-bundling-issue74/commit/92144f0c26a6ce8efe3bd0b48d238b8d24270759

Then I migrate the database rails db:migrate

But still the Stiummy controller won't connect at all. --- no "Hello world" or nothing
I added a console output too:

DevTools - 127 0 0 1:3000:posts 2022-01-26 11-02-46

https://github.com/jasonfb/js-bundling-issue74/

@dhh -- this is very odd, it must be something else that we haven't thought of. is it possible you have cached gem dependencies on your machine that have been yanked from Rubygems?

Could please do either of the following:

  1. ask someone else to replicate the same steps as above to see what they get

  2. pull my repo above (https://github.com/jasonfb/js-bundling-issue74/) and let me know when you pull my repo if you see the Stimulus controller connect

  3. Re-create the steps on your machine, commit & and then push the example code so that I might pull it and see if it works on my machine.

In the event that you or I have cached yanked gems, we could be building Rails against different default causing this issue. we would then be able to compare the Gemfile.lock

I'm certain there is a very reasonable explanation (but of course, I feel like a crazy person because it seems like it should be obvious).

the only explanation I can think of is this is similar to the yanked turbo-rails versions at the 7.x version range which were causing those versions to be installed above the lower-numbered ones..

I suppose I could implode my ruby and re-install all the gems but still if I had your lockfile that would be helpful as I could compare gem by gem to see what the difference is.

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

I tested this against Ruby 2.7. I will check it against Ruby 3.0 now and report back here.

here's it recreated against Ruby 3.1.0:

https://github.com/jasonfb/-js-bundling-issue74-ruby310

I've recreated it multiple times and there is no inconsistency-- any new app created with these steps do not have Stimulus enabled and I can't even figure out why not. (They also do not have Turbo enabled for me).

Only apps that I create without --css or --javascript can I get Turbo or Stimulus working. As well, I didn't have Ruby 3.1 before this so it must have installed all the gems fresh.

I suspect the only explanation for this that I can surmise is that DHH has some yanked cached gems on his machine causing his apps to come out in an OK state.

Can someone else please test and push your result publicly so that we might compare the Gemfile.lock versions? Thank you.

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

ok @dhh -- I have now recreated this issue using a 2nd laptop that did not previously have Rails 7.0.1 on it. same result. Would you please consider that your machine may have yanked cached gems causing your new rails build to work for only you but not for everyone else?

Please re-open the issue or supply the rails build for us to examine the Gemfile.lock. this does not make sense.

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

here is the Gemfile.lock that I am getting. I can't see anything wrong with it by examination, but if possibly your machine has yanked cached gems you will be building against gems that make your apps work.

https://gist.github.com/jasonfb/fa99be3bed6eec5a394b0205a53c9f56

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

@dhh -- nevermind!

the problem here is that this is what happens when you don't actually install webpack as a node module using npx webpack

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

RESOLITION & NOTICE:

The problem here is that I was running my Rails server with rails s, which won't install webpack as a node module.

You are now encouraged to use the new development command, which takes care of both (although requires a reload of the web browser to kick in webpack:

bin/dev rails

If using rails server (rails s), you must run npx webpack first or else your webpack won't be installed.

Remember, this affects only apps built using the new --css and --javascript flags.

there are likely no yanked cached gems on DHH's machine I just didn't know what else to think of next!

from jsbundling-rails.

jasonfb avatar jasonfb commented on June 26, 2024

https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-7-new-app-with-js-bundling-css-bundling/

from jsbundling-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.