Skip to content

Commit 2928cdc

Browse files
committed
Fix turbo-action queuing and add a console error if a frame error occurs
1 parent 9fcb191 commit 2928cdc

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
katalyst-kpop (3.1.0)
4+
katalyst-kpop (3.1.1)
55
katalyst-html-attributes
66
turbo-rails
77
view_component

app/javascript/kpop/controllers/frame_controller.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class Kpop__FrameController extends Controller {
3232
}
3333

3434
disconnect() {
35-
this.debug("disconnect");
35+
this.debug("disconnect", this.element.src);
3636

3737
delete this.element.kpop;
3838
delete this.modal;
@@ -134,11 +134,12 @@ export default class Kpop__FrameController extends Controller {
134134
// Defer rendering until dismiss is complete.
135135
// Dismiss may change history so we need to wait for it to complete to avoid
136136
// losing DOM changes on restoration visits.
137-
event.detail.render = (stream) => {
138-
(this.dismissing || Promise.resolve()).then(() => {
139-
this.debug("stream-render", stream);
140-
resume(stream);
141-
});
137+
event.detail.render = async (stream) => {
138+
await this.dismissing;
139+
140+
this.debug("stream-render", stream);
141+
142+
await resume(stream);
142143
};
143144
}
144145

@@ -190,6 +191,11 @@ export default class Kpop__FrameController extends Controller {
190191
delete this.opening;
191192

192193
this.debug("open-end");
194+
195+
// Detect https://github.com/hotwired/turbo-rails/issues/580
196+
if (Turbo.session.view.forceReloaded) {
197+
console.error("Turbo-Frame response is incompatible with current page");
198+
}
193199
}
194200

195201
async #dismiss({ animate = true, reason = "" } = {}) {
@@ -255,6 +261,7 @@ function installNavigationInterception(controller) {
255261
}
256262

257263
if (frame.kpop) {
264+
frame.kpop.debug("navigate-frame %s => %s", frame.src, location);
258265
FrameModal.visit(location, frame.kpop, frame, () => {
259266
TurboFrameController._linkClickIntercepted.call(
260267
this,

katalyst-kpop.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "katalyst-kpop"
5-
spec.version = "3.1.0"
5+
spec.version = "3.1.1"
66
spec.authors = ["Katalyst Interactive"]
77
spec.email = ["[email protected]"]
88

spec/system/frame_modal_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,30 @@
250250
expect(page).to have_no_css(".kpop-title")
251251
end
252252

253+
it "supports closing a modal with kpop.dismiss" do
254+
# Fill in the form
255+
within(".kpop-modal") do |_kpop|
256+
select "content", from: "Next"
257+
click_on "Save"
258+
end
259+
260+
expect(page).to have_current_path(new_parent_child_path)
261+
expect(page).to have_css(".kpop-title", text: "New child")
262+
263+
# Create a child
264+
within(".kpop-modal") do |_kpop|
265+
fill_in "Name", with: "TEST"
266+
click_on "Create"
267+
end
268+
269+
sleep 0.1
270+
271+
# Check that the child was created
272+
expect(page).to have_current_path(parent_path)
273+
expect(page).to have_no_css(".kpop-title")
274+
expect(page).to have_css("li", text: "TEST")
275+
end
276+
253277
it "debounces double open requests" do
254278
page.go_back
255279

0 commit comments

Comments
 (0)