inertia-rails icon indicating copy to clipboard operation
inertia-rails copied to clipboard

feat: add `inertia_config` to enable controller-specific config

Open ElMassimo opened this issue 1 year ago • 0 comments

Description 📖

This pull request is a complete refactor of the implementation in order to introduce controller-specific configuration.

inertia_config

A new way for controllers to override the global configuration, and provide dynamic values, such as:

class PostsController < ApplicationController
  inertia_config(
    ssr_enabled: -> { action_name == "index" },
  )
end

Just like inertia_share, configuration is inheritable, and subclasses can override values.

In addition, all configuration options can now be procs (before only version supported this).

Performance 🚀

The implementation of inertia_share no longer relies on before_action, improving performance when calculating shared data at runtime, and reducing object allocations.

As an additional benefit, we no longer run this code unnecessarily for non-Inertia requests.

Notes ✏️

Each commit is a gradual refactoring, and can be read in isolation (and passes all tests). I'd still suggest using Squash and Merge.

We also freeze config and shared data to prevent any mutations, ensuring it's safe for multiple threads to access the configuration from the controller class.

ElMassimo avatar Jun 26 '24 01:06 ElMassimo