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

Support jsbundling #12

Closed
adrienpoly opened this issue Dec 18, 2024 · 16 comments · Fixed by #44
Closed

Support jsbundling #12

adrienpoly opened this issue Dec 18, 2024 · 16 comments · Fixed by #44
Labels
enhancement New feature or request

Comments

@adrienpoly
Copy link
Member

I gave it a spin a our app using css_bundling and js_bundling

updating the html works but I am getting this error in the console.

I suppose it is because I don't have importmaps in my app

CleanShot 2024-12-18 at 17 52 21@2x

Given that it seems to work I think it would be best to silence this error

@jorgemanrubia
Copy link
Member

Yes @adrienpoly. We only support importmaps for now. jssbundling on our radar, but we need to see build dedicated support for it.

In any case I'll leave this open as we should handle that more gracefully.

@jorgemanrubia jorgemanrubia changed the title Error on reload_html TypeError jssbundling support Dec 18, 2024
@TeriyakiBomb
Copy link
Contributor

I think it'd be good if that was explicit in the readme, it'll save a lot of unnecessary issues being opened 😅
Happy to add if you like

@jankeesvw
Copy link

This was also my first question :-)

@jorgemanrubia jorgemanrubia added the enhancement New feature or request label Dec 20, 2024
@jorgemanrubia jorgemanrubia changed the title jssbundling support Support jssbundling Dec 20, 2024
@jorgemanrubia
Copy link
Member

I think a path here would be to add a new endpoint to return the source given a stimulus controller path. That would let us use a unified reloader that works with both jssbundling and importmaps. It would also simplify not having to parse the import maps or reload the HTML document before that.

I'll take a stab at this this week.

@jorgemanrubia
Copy link
Member

I think this change will make Hotwire Spark compatible with jsbundling and other alternatives. Tomorrow I'll test and confirm. I'd appreciate it if anyone gives that branch a try to confirm too.

@TeriyakiBomb
Copy link
Contributor

TeriyakiBomb commented Dec 24, 2024

I had a go with the default hello controller - adding the controller to a view updates the html as expected. Modifying the textContents string reloads but returns:

CleanShot 2024-12-24 at 13 45 50@2x

This includes re running the server post install and double checking my gemfile.lock:

remote: https://github.com/hotwired/spark.git revision: e9c255688bd0cdcc581cf0e393ea0597bb2c091c

On a fresh rails install @8.0.1 with jsbundling

@adrienpoly
Copy link
Member Author

I think this change will make Hotwire Spark compatible with jsbundling and other alternatives. Tomorrow I'll test and confirm. I'd appreciate it if anyone gives that branch a try to confirm too.

I gave it a try on our App, Rails 8 /JS bundling / CSS Bundling

The error is gone.

As far as I could tell the changes in the HTML, JS, and CSS are captured and the page is refreshed.
but it seems that I get an extra Turbo visit for every refresh as I see the Turbo blue progress bar popping.
Also probably a consequence of this Turbo visit I loose the scroll position.
At first the page is updated and scroll preserved (using morph I believe) and then the Turbo visit refresh the entire page and reset the scroll position.

Might be something with our app???

@jorgemanrubia
Copy link
Member

This is not working to provide hot-reloading for stimulus controllers under jsbundling. Check my reply to @kobaltz here.

I'll play a bit more with the approach, but I'm afraid a saner way for jsbundling will be to get this merged and use replaces instead of morphing for the jsbundling path.

@jorgemanrubia
Copy link
Member

Hey @adrienpoly did you try this branch by any chance? That's the only branch that should be triggering a new turbo visit here 🤔

@jorgemanrubia
Copy link
Member

I went with a different approach here. It will now detect jsbundling and configure some dedicated options: instead of trying to hot-reload stimulus controllers, it will reload the current page with Turbo (new option introduced by #40).

The problem with hot reloading with jsbundling are dependencies: the browser can't resolve those outside of the bundling environment, so enabling hot-reloading is a much more complex endeavour than when using importmaps.

@adrienpoly
Copy link
Member Author

Hey @adrienpoly did you try this branch by any chance? That's the only branch that should be triggering a new turbo visit here 🤔

I did some more investigating and it is an issue on my side with some legacy esbuild reload that I put in place. Will do some more testing but it is looking good as fare as I could tell

@jorgemanrubia
Copy link
Member

I'm closing this as jsbundling will work fine now. I'll be happy to consider hot-reloading for stimulus controllers within this path too if something comes with a good idea that isn't terribly complex.

@jorgemanrubia jorgemanrubia changed the title Support jssbundling Support jsbundling Dec 25, 2024
@adrienpoly
Copy link
Member Author

adrienpoly commented Dec 25, 2024

I'm closing this as jsbundling will work fine now. I'll be happy to consider hot-reloading for stimulus controllers within this path too if something comes with a good idea that isn't terribly complex.

I am going to try hotwire-spark with Ruby Vite. The HMR of RubyVite is amazing. I think there is a sweet spot between Spark html morph updates and RubyVite HMR for JS/CSS. This could be an advanced path to get HMR without importmaps without making Spark too complex neither

@SyedMSawaid
Copy link

Screenshot 2025-01-02 at 2 57 33 AM

I am still facing issue with hot-reloading when I change my stimulus controller. Is that not supported yet with js-bundling?

@jorgemanrubia
Copy link
Member

@SyedMSawaid have you updated to latest? Also, it could be a caching issue (304 response and, thus, not updating the JS library file). Try disabling the cache to see if that fixes it.

@SyedMSawaid
Copy link

The response seems to be 200 for the js files. I have pulled the latest commit directly from GitHub.
Screenshot 2025-01-07 at 7 09 29 PM

This is how my Gemfile, Gemfile.lock and manifest.js looks like.
Screenshot 2025-01-07 at 7 12 16 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

5 participants