hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.67k stars 421 forks source link

Conflicting Fetch between stimulus and Hotwire #769

Closed jdpy19 closed 4 months ago

jdpy19 commented 4 months ago

Hey! I have spun up a new project this morning and I am running into an issue that is due to window.fetch being overridden with the fetch in set operations. https://github.com/hotwired/stimulus/blob/e6f1887c9ac91f3d83d8cde0b80c216d0dc3de6e/src/multimap/set_operations.ts#L10

Hotwire is using window.fetch which should be the native https://github.com/hotwired/turbo/blob/89be8e4c206ea877183b7ac4a89f898363a14f0f/src/http/fetch.js#L6

Error

Screenshot 2024-05-24 at 12 27 12 PM

Package.json

{
  "name": "app",
  "private": true,
  "dependencies": {
    "@hotwired/stimulus": "^3.2.2",
    "@hotwired/turbo-rails": "^8.0.4",
    "esbuild": "^0.21.3",
    "sass": "^1.77.2"
  },
  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
    "build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }
}

Gemfile

source "https://rubygems.org"

ruby "3.3.0"

gem "bcrypt", "~> 3.1.7"
gem "bootsnap", require: false
gem "cssbundling-rails"
gem "devise", "~> 4.9"
gem "image_processing", "~> 1.12"
gem "jbuilder"
gem "jsbundling-rails"
gem "pg", "~> 1.1"
gem "puma", ">= 5.0"
gem "rails", "~> 7.1.3"
gem "redis", ">= 4.0.1"
gem "simple_form", "~> 5.3"
gem "sprockets-rails"
gem "stimulus-rails"
gem "turbo-rails", '~> 1.0'

group :development, :test do
  gem "debug"
end

group :development do
  gem "htmlbeautifier"
  gem "web-console"
end

group :test do
  gem "capybara"
  gem "selenium-webdriver"
end
jdpy19 commented 4 months ago

I'll be digging into this later, but wanted to throw the issue up.

seanpdoyle commented 4 months ago

This might be related to https://github.com/hotwired/turbo/issues/1265. Similar to https://github.com/hotwired/turbo/issues/1265#issuecomment-2130326864, could you share more information about how the turbo and stimulus dependencies are being loaded by the browser?

seanpdoyle commented 4 months ago

Since https://github.com/hotwired/turbo/issues/1265 has been closed, could this also be closed?

marcoroth commented 4 months ago

The function in set_operations.ts shouldn't be leaking into the global window namespace. Looking at https://github.com/hotwired/turbo/issues/1265 this seems to be the case. Going to close this for now. Please feel to re-open if you see anything else unexpected.