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

Connect running multiple times #44

Closed
noctivityinc opened this issue Feb 3, 2021 · 1 comment
Closed

Connect running multiple times #44

noctivityinc opened this issue Feb 3, 2021 · 1 comment

Comments

@noctivityinc
Copy link

Simple install on new Rails 6.1 app. As can be seen on page load, connect occurs twice every time. Running Ruby 3.0.0 and Rails 6.1.1 and latest stimulus-rails gem.

Screen Shot 2021-02-03 at 9 51 11 AM

Application.js

import "../stylesheets/application";
import $ from 'jquery';
global.$ = jQuery;

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
import "controllers"

import { stripeElements } from "./subscriptions";
global.stripeElements = stripeElements;

global.toastr = require("toastr")

Rails.start()
Turbolinks.start()
ActiveStorage.start()

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function(tooltipTriggerEl) {
    return new bootstrap.Tooltip(tooltipTriggerEl)
})

var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
    return new bootstrap.Popover(popoverTriggerEl)

Index.html.haml

.container
  %h1 Home#index
  %p Find me in app/views/home/index.html.haml

  %div{"data-controller" => "home"}
    %input{"data-hello-target" => "name", :type => "text"}/
    %button{"data-action" => "click->hello#greet"}
      Greet
    %span{"data-hello-target" => "output"}

Package.js

{
  "name": "subscription",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "5.2.1",
    "jquery": "^3.5.1",
    "moment": "^2.29.1",
    "stimulus": "^2.0.0",
    "toastr": "^2.1.4",
    "tooltip": "^1.6.1",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "rails-erb-loader": "^5.5.2",
    "webpack-dev-server": "^3.11.2"
  }
}

Environment.js

const { environment } = require('@rails/webpacker')
const erb = require('./loaders/erb')

const webpack = require('webpack');
environment.plugins.append("Provide",
    new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        Rails: ['@rails/ujs']
    }))

environment.loaders.prepend('erb', erb)
module.exports = environment
@joaku
Copy link

joaku commented Jul 25, 2021

Why are you adding the:

Rails: ['@rails/ujs']

To webpacker Enviroment.js?

@dhh dhh closed this as completed Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants