Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict helpers #1987

Open
wants to merge 25 commits into
base: introduce-component-local-config
Choose a base branch
from

Commits on Oct 8, 2024

  1. Use ActiveSupport::Configurable to cascade config

    ViewComponent::Base itself will always use the defaults. Any classes inheriting from ViewComponent::Base will cascade config down using InheritableOptions, only specifying any overrides.
    Generate options being on their own "layer of config is currently unresolved - it might be that config needs to be a new object inheriting from InheritableOptions that has method accessors for everything in that namespace.
    
    This was initially written to support extracting the incoming strict_helpers_enabled? option, but applies to everything.
    boardfish committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    71c23c6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4b4ba76 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0ba800b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    a655192 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f56832e View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    2531907 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    1f40e96 View commit details
    Browse the repository at this point in the history
  8. Remove component-local config for now

    No settings actually use it, but this would be the way to introduce it once we come to need it.
    boardfish committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    4c89cbc View commit details
    Browse the repository at this point in the history
  9. Lint

    boardfish committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    2c0daf6 View commit details
    Browse the repository at this point in the history
  10. Update changelog

    boardfish committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    161cee3 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    caa79f3 View commit details
    Browse the repository at this point in the history
  12. add: strict helpers

    reeganviljoen committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    ab59bdd View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    0ada155 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    6508f28 View commit details
    Browse the repository at this point in the history
  15. fix tests

    reeganviljoen committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    b292de5 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    380fe22 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    fca14b1 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    cb73965 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    6d4bed1 View commit details
    Browse the repository at this point in the history
  20. update changelog

    reeganviljoen committed Oct 8, 2024
    Configuration menu
    Copy the full SHA
    a4a7ed9 View commit details
    Browse the repository at this point in the history

Commits on Oct 11, 2024

  1. Fix duplicate template error bug (ViewComponent#2121)

    * Fix duplicate template error bug
    
    This change fixes the bug reported where a component will report that it
    has both a template and a `call` method defined despite only having an
    HTML template.
    
    I was able to reproduce this bug by pulling in Avo (like reported in the
    initial bug report) and running `vegeta` (to trigger parallel requests
    since I had a hunch this was a race condition):
    
    ```
    echo "GET http://localhost:3000/avo/resources/cars/1" | vegeta attack -duration=2s
    ```
    
    This reliably reproduced the error:
    
    ```
    ActionView::Template::Error (Template file and inline render method found for Avo::CoverPhotoComponent. There can only be a template file or inline render method per component.
    Template file and inline render method found for variant '' in Avo::CoverPhotoComponent. There can only be a template file or inline render method per variant.
    Templates:
    ```
    
    I added _a lot_ of debug logs to understand the race condition that I
    thought was occurring, and realized that multiple threads are calling
    `gather_templates` _and_ mutating the `@templates` array at the
    same.When looking at the old compiler code and realized that this likely
    isn't new behavior. This led the investigation towards how we collect
    and surface errors or otherwise might modify templates. It turns out
    there's a difference in the new and old compiler code after the
    refactor:
    
    ```ruby
    \# old
    def template_errors
      @__vc_template_errors ||=
    
    \# new
    def gather_template_errors(raise_errors)
      errors = []
    ```
    
    _We're not memoizing the errors like we used to_. This is more correct
    behavior, but explains how a race condition would make this error case
    much more difficult to occur in older versions of the compiler.
    
    This change brings us back to the old behavior by memoizing the errors
    we collect in `gather_template_errors` but the `@templates` ivar is
    still being mutated. I don't want to change _too much_ in this PR, but a
    subsequent change might be wrapping the entire `compile` method in the
    `redefinition_lock` (and renaming it to `compile_lock`) to avoid similar
    issues in the future.
    
    I did not include a test because it's dfficult to reproduce this race
    condition reliably in the test environment.
    
    I believe this _should_ close out ViewComponent#2114
    
    * Fix tests, raise errors for compiled components with errors
    
    * There isn't always a default template when there are errors.
    
    * Make standard happy
    
    ugh
    
    * Remove debug code
    
    * Fail compilation when errors present
    
    * Revert default template change
    
    * Add informative comment
    
    * Add changelog
    
    ---------
    
    Co-authored-by: Joel Hawksley <[email protected]>
    2 people authored and boardfish committed Oct 11, 2024
    Configuration menu
    Copy the full SHA
    5da6b23 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    93534b1 View commit details
    Browse the repository at this point in the history
  3. Update CHANGELOG.md

    joelhawksley authored and boardfish committed Oct 11, 2024
    Configuration menu
    Copy the full SHA
    0470809 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b7a6ad0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    dbfc516 View commit details
    Browse the repository at this point in the history