-
Notifications
You must be signed in to change notification settings - Fork 91
Make autoloading changes visible to the DOM #57
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import { Controller } from "stimulus" | ||
|
|
||
| export default class extends Controller { | ||
| connect() { | ||
| this.element.textContent = "Hello World!" | ||
| static get targets() { return [ "input", "output" ] } | ||
|
|
||
| greet() { | ||
| this.outputTarget.innerHTML = `Hello, ${this.inputTarget.value}` | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,16 @@ class AutoloadTest < ApplicationSystemTestCase | |
| end | ||
| end | ||
|
|
||
| test "waits for autoloading to complete" do | ||
| visit root_path | ||
|
|
||
| within "#eager-loaded" do | ||
| click_button "Say Hello" | ||
|
|
||
| assert_text "Hello, Waiting for Eager Load" | ||
| end | ||
| end | ||
|
|
||
| test "autoloads Controller modules on the page lazily" do | ||
| visit root_path(message: "Hello World!") | ||
|
|
||
|
|
@@ -45,4 +55,14 @@ class AutoloadTest < ApplicationSystemTestCase | |
| assert_text "Namespace: Hello, from Turbo page" | ||
| end | ||
| end | ||
|
|
||
| def click_button(*) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In its current state, this draft PR only extends the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a super interesting way to address this problem! One thing that I'm wrestling with is that I can't help but feel like this behavior codifies the possible experience for a user where:
Granted, in most cases, the delay here should be negligible and shouldn't be a problem, but I do think there are situations where this will come up outside of an automated test scenario. Just an idea here, but I wonder if it'd be possible to specify strategies for how to deal with this in the library that would help avoid the need to override this behavior in capybara, e.g. |
||
| begin | ||
| assert_css "[data-stimulus-autoloading]" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion is intended to wait for the autoloading to start.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be best to wrap this in a using_wait_time block of 0-ish to cut down on time spent waiting. |
||
| rescue | ||
| # does not eagerly load any Stimulus | ||
| end | ||
| assert_no_css "[data-stimulus-autoloading]" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion is intended to wait for the autoloading to complete. If we think using |
||
| super | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe storing the currently autoloader identifiers on the
html,body, or a<meta>element would suffice, instead of on each individual element.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts around placing it on
html,bodyormeta? I was thinking that with adata-stimulus-autoloadingattribute on the element directly you could at least target that with a css class and have a path to display a loading indicator that way (or block interaction).