question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of Values is not working for stimulus 2.0.0

See original GitHub issue

Hello, I am using stimulus with rails and webpacker.

package.json:

"stimulus": "^2.0.0",

yarn.lock:

"@stimulus/core@^2.0.0":
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/@stimulus/core/-/core-2.0.0.tgz#140c85318d6a8a8210c0faf182223b8459348877"
  integrity sha512-ff70GafKtzc8zQ1/cG+UvL06GcifPWovf2wBEdjLMh9xO2GOYURO3y2RYgzIGYUIBefQwyfX2CLfJdZFJrEPTw==
  dependencies:
    "@stimulus/mutation-observers" "^2.0.0"

"@stimulus/multimap@^2.0.0":
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/@stimulus/multimap/-/multimap-2.0.0.tgz#420cfa096ed6538df4a91dbd2b2842c1779952b2"
  integrity sha512-pMBCewkZCFVB3e5mEMoyO9+9aKzHDITmf3OnPun51YWxlcPdHcwbjqm1ylK63fsoduIE+RowBpFwFqd3poEz4w==

"@stimulus/mutation-observers@^2.0.0":
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/@stimulus/mutation-observers/-/mutation-observers-2.0.0.tgz#3dbe37453bda47a6c795a90204ee8d77a799fb87"
  integrity sha512-kx4VAJdPhIGBQKGIoUDC2tupEKorG3A+ckc2b1UiwInKTMAC1axOHU8ebcwhaJIxRqIrs8//4SJo9YAAOx6FEg==
  dependencies:
    "@stimulus/multimap" "^2.0.0"

"@stimulus/webpack-helpers@^2.0.0":
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/@stimulus/webpack-helpers/-/webpack-helpers-2.0.0.tgz#54296d2a2dffd4f962d2e802d99a3fdd84b8845f"
  integrity sha512-D6tJWsAC024MwGEIKlUVYU8Ln87mlrmiwHvYAjipg+s8H4eLxUMQ3PZkWyPevfipH+oR3leuHsjYsK1gN5ViQA==

application.js:

import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("../controllers", true, /\.js$/)
application.load(definitionsFromContext(context))

html:

<div data-controller="loader"
     data-loader-url-value="/messages">
</div>

app/javascript/controllers/loader_controller.js:

import { Controller } from "stimulus";

export default class extends Controller {
  static values = { url: String };
  connect() {
    this.urlValue;
    debugger;
    fetch(this.urlValue).then(/* … */);
  }
}

And this.urlValue is undefined on the breakpoint. Am i missing something obvious here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hidr0commented, Mar 23, 2021

Ok, I got it. Rails did not auto reload the compiled web pack JS.

So I had to delete my node_modules and manifest.json, stop the server and yarn install. It now works with 2.0.0

The issue was that the lib was not properly updated.

I am closing this issue, sorry for the time.

@javan Thank you for the reply.

Best wishes, Michael.

0reactions
hidr0commented, Mar 23, 2021

Yes, it was 1.1.1. And I changed my package.json to 2.0.0. yarn install

Checked the yarn.lock and there it said 2.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stimulus 2.0 Value change callbacks. What are they good for?
Just try running the fiddle, put a ”price“ in the input and watch the converted prices recalculate automatically after 5s. The trick here...
Read more >
How to use Stimulus JS 2.0's new Values and CSS Classes APIs
Notes. Stimulus JS 2.0 is finally out and it includes the brand new Values and CSS Classes APsI. These APIs have been in...
Read more >
How to Use Stimulus JS 2.0: Values and CSS Classes API
Check out https://gorails.com for Pro episodes and more!▻ SaaS business template for Ruby on Rails with built-in features like Payments, ...
Read more >
Updating to Stimulus.js 2.0 - Blogging On Rails
Here are some things to consider if you decide to update to 2.0. It adds a Values api, CSS classes, and a change...
Read more >
Values ​stimulus js don't working a single escope of a controller
I believe by design is must be in the same element as the controller definition. Looking at the values documentation, It is purposefully...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found