Typelizer.InertiaPage.ValidateProps (Typelizer v0.1.0)

Copy Markdown View Source

A plug that checks, in dev and test, that each rendered Inertia page sends exactly the props declared with Typelizer.InertiaPage.page/2.

# config/dev.exs and config/test.exs
config :typelizer, validate_inertia_props: true

# lib/my_app_web/router.ex
pipeline :browser do
  # ...
  plug Inertia.Plug
  plug Typelizer.InertiaPage.ValidateProps
end

When a page renders, the plug compares the top-level keys of its props with the page props, the shared props, errors and flash:

  • a declared prop is missing and it is not {:optional, _} → error;
  • a deferred prop is declared without {:optional, _} → error;
  • a prop is present but not declared → error;
  • the component has no declaration → error, unless config :typelizer, undeclared_inertia_pages: :ignore.

On a partial reload only undeclared props are reported. The error is a Typelizer.InertiaPage.PropsError, raised before the response is sent.

With validate_inertia_props: false (the default) the plug does nothing. Both config keys are read at runtime.