Skip to content

Commit

Permalink
Fix turbo-action queuing and add a console error if a frame error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfnelson committed Feb 21, 2024
1 parent 9fcb191 commit 2928cdc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
katalyst-kpop (3.1.0)
katalyst-kpop (3.1.1)
katalyst-html-attributes
turbo-rails
view_component
Expand Down
19 changes: 13 additions & 6 deletions app/javascript/kpop/controllers/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
}

Expand Down Expand Up @@ -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 = "" } = {}) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion katalyst-kpop.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]

Expand Down
24 changes: 24 additions & 0 deletions spec/system/frame_modal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2928cdc

Please sign in to comment.