Skip to content

Filter form missing id triggers LiveView missing_form_id warning (no form recovery) #189

Description

@mbaertschi

Summary

The filter/search <form> rendered by Cinder.FilterManager has no id attribute. On phoenix_live_view 1.1+ this triggers the new missing_form_id diagnostic, and more importantly it means LiveView cannot perform form recovery for the filter form after a disconnect or crash.

Versions

  • cinder 0.15.0 (latest)
  • phoenix_live_view 1.2.1

Warning

Running any test that mounts a LiveView containing a <Cinder.collection> prints:

warning: Detected a form with phx-change but missing id:

    <form phx-change="filter_change" phx-submit="filter_change" phx-target="1"></form>

Without an id, LiveView will not be able to perform form recovery,
for more information see:
https://hexdocs.pm/phoenix_live_view/form-bindings.html#recovery-following-crashes-or-disconnects

Cause

lib/cinder/filter_manager.ex renders the filter form without an id in both branches:

  • render_filter_controls_with_slot/2 — line 75
  • render_filter_controls_default/1 — line 110
<form phx-change="filter_change" phx-submit="filter_change" phx-target={@target}>

Suggested fix

@table_id is already in scope in this module (e.g. it's used at line 109 for id={"#{@table_id}-filter-body"}), so the form can derive a stable, unique id from it:

<form id={"#{@table_id}-filter-form"} phx-change="filter_change" phx-submit="filter_change" phx-target={@target}>

Only one of the two branches renders per table, so a single "#{@table_id}-filter-form" scheme stays unique.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions