diff --git a/Gemfile.lock b/Gemfile.lock index 58554a4..14f5ab9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - katalyst-kpop (3.1.0) + katalyst-kpop (3.1.1) katalyst-html-attributes turbo-rails view_component diff --git a/app/javascript/kpop/controllers/frame_controller.js b/app/javascript/kpop/controllers/frame_controller.js index bd1c0b6..898f10f 100644 --- a/app/javascript/kpop/controllers/frame_controller.js +++ b/app/javascript/kpop/controllers/frame_controller.js @@ -32,7 +32,7 @@ export default class Kpop__FrameController extends Controller { } disconnect() { - this.debug("disconnect"); + this.debug("disconnect", this.element.src); delete this.element.kpop; delete this.modal; @@ -134,11 +134,12 @@ export default class Kpop__FrameController extends Controller { // Defer rendering until dismiss is complete. // Dismiss may change history so we need to wait for it to complete to avoid // losing DOM changes on restoration visits. - event.detail.render = (stream) => { - (this.dismissing || Promise.resolve()).then(() => { - this.debug("stream-render", stream); - resume(stream); - }); + event.detail.render = async (stream) => { + await this.dismissing; + + this.debug("stream-render", stream); + + await resume(stream); }; } @@ -190,6 +191,11 @@ export default class Kpop__FrameController extends Controller { delete this.opening; this.debug("open-end"); + + // Detect https://github.com/hotwired/turbo-rails/issues/580 + if (Turbo.session.view.forceReloaded) { + console.error("Turbo-Frame response is incompatible with current page"); + } } async #dismiss({ animate = true, reason = "" } = {}) { @@ -255,6 +261,7 @@ function installNavigationInterception(controller) { } if (frame.kpop) { + frame.kpop.debug("navigate-frame %s => %s", frame.src, location); FrameModal.visit(location, frame.kpop, frame, () => { TurboFrameController._linkClickIntercepted.call( this, diff --git a/katalyst-kpop.gemspec b/katalyst-kpop.gemspec index 6d57bc8..f90085d 100644 --- a/katalyst-kpop.gemspec +++ b/katalyst-kpop.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "katalyst-kpop" - spec.version = "3.1.0" + spec.version = "3.1.1" spec.authors = ["Katalyst Interactive"] spec.email = ["developers@katalyst.com.au"] diff --git a/spec/system/frame_modal_spec.rb b/spec/system/frame_modal_spec.rb index 18abb41..27f242c 100644 --- a/spec/system/frame_modal_spec.rb +++ b/spec/system/frame_modal_spec.rb @@ -250,6 +250,30 @@ expect(page).to have_no_css(".kpop-title") end + it "supports closing a modal with kpop.dismiss" do + # Fill in the form + within(".kpop-modal") do |_kpop| + select "content", from: "Next" + click_on "Save" + end + + expect(page).to have_current_path(new_parent_child_path) + expect(page).to have_css(".kpop-title", text: "New child") + + # Create a child + within(".kpop-modal") do |_kpop| + fill_in "Name", with: "TEST" + click_on "Create" + end + + sleep 0.1 + + # Check that the child was created + expect(page).to have_current_path(parent_path) + expect(page).to have_no_css(".kpop-title") + expect(page).to have_css("li", text: "TEST") + end + it "debounces double open requests" do page.go_back