Skip to content

False positive ArgumentError for ColocatedHook macro component in .heex templates #1256

@druvv

Description

@druvv

Environment

  • ElixirLS: 0.30.0
  • Elixir: 1.19.5
  • Erlang/OTP: 28
  • Phoenix LiveView: 1.1.25
  • Editor: Zed

Description

ElixirLS reports an ArgumentError diagnostic in .html.heex template files that use <script :type={Phoenix.LiveView.ColocatedHook}> (macro components introduced in LiveView 1.1 via PR #3810).

The error appears at line 1 of the template:

** (ArgumentError) macro components are only supported in modules that `use Phoenix.Component`
(phoenix_live_view 1.1.25) lib/phoenix_live_view/tag_engine.ex:894: Phoenix.LiveView.TagEngine.handle_macro_component/3
(phoenix_live_view 1.1.25) lib/phoenix_live_view/tag_engine.ex:250: Phoenix.LiveView.TagEngine.handle_body/1
(language_server 0.30.0) lib/language_server/parser.ex:499: anonymous fn/3 in ElixirLS.LanguageServer.Parser.parse_file/3

The project compiles cleanly with mix compile --force (no warnings or errors).

Reproduction

  1. Create a Phoenix LiveView module with use Phoenix.LiveView (or via a helper like use MyAppWeb, :live_view)
  2. In its colocated .html.heex template, add a colocated hook:
<div id="my-element" phx-hook=".MyHook">
  <script :type={Phoenix.LiveView.ColocatedHook} name=".MyHook">
    export default {
      mounted() { console.log("mounted") }
    }
  </script>
</div>
  1. ElixirLS reports the ArgumentError on line 1, even though mix compile succeeds

Expected behavior

No diagnostic error, since the template compiles successfully.

Actual behavior

ElixirLS shows the ArgumentError as a diagnostic in the editor.

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