Skip to content

Regression in 1.1.1 when using render_submit/2 with a custom submitter on forms without IDs #3927

@frerich

Description

@frerich

Environment

  • Elixir version (elixir -v): 1.18.3
  • Phoenix version (mix deps): 1.8.0-rc.4
  • Phoenix LiveView version (mix deps): 1.1.1
  • Operating system: macOS 15.5
  • Browsers you attempted to reproduce this bug on (the more the merrier): -
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: -

Actual behavior

Calling Phoenix.LiveViewTest.render_submit/1 raises an error when using a custom submitter if the form has no ID.

To reproduce, add this test to e.g. test/phoenix_live_view/integrations/elements_test.exs:

    test "put_submitter/2 works on forms without IDs", %{live: view} do
      view
      |> element("form[data-name='form-without-id']")
      |> put_submitter("[name=button]")
      |> render_submit()
    end

Also, extend phoenix_live_view/test/support/live_views/elements.ex with a form which has no ID by adding:

    <form data-name="form-without-id" phx-submit="form-submit">
      <button name="button" type="submit">button</button>
    </form>

Running this test via mix test test/phoenix_live_view/integrations/elements_test.exs yields:

  1) test render_submit put_submitter/2 works on forms without IDs (Phoenix.LiveView.ElementsTest)
     test/phoenix_live_view/integrations/elements_test.exs:577
     ** (EXIT from #PID<0.366.0>) an exception was raised:

          ** (FunctionClauseError) no function clause matching in LazyHTML.from_tree/1

          The following arguments were given to LazyHTML.from_tree/1:

              # 1
              {"form", [{"data-name", "form-without-id"}, {"phx-submit", "form-submit"}], ["\n  ", {"button", [{"name", "button"}, {"type", "submit"}], ["button"]}, "\n"]}

          Attempted function clauses (showing 1 out of 1):

              def from_tree(tree) when is_list(tree)

          stacktrace:
            (lazy_html 0.1.3) lib/lazy_html.ex:188: LazyHTML.from_tree/1
            (phoenix_live_view 1.2.0-dev) lib/phoenix_live_view/test/client_proxy.ex:1319: Phoenix.LiveViewTest.ClientProxy.maybe_submitter/4
            (phoenix_live_view 1.2.0-dev) lib/phoenix_live_view/test/client_proxy.ex:1281: Phoenix.LiveViewTest.ClientProxy.maybe_values/4
            (phoenix_live_view 1.2.0-dev) lib/phoenix_live_view/test/client_proxy.ex:369: Phoenix.LiveViewTest.ClientProxy.handle_info/2
            (stdlib 6.2.2) gen_server.erl:2345: :gen_server.try_handle_info/3
            (stdlib 6.2.2) gen_server.erl:2433: :gen_server.handle_msg/6
            (stdlib 6.2.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

Expected behavior

The test should succeed, no error should be printed.

Further observations

  • This appears to be a regression since Phoenix LiveView 1.0.17.
  • Omitting the Phoenix.LiveViewTest.put_submitter/2 call or adding a dummy ID (e.g. id="x") to the <form> element avoids the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions