Skip to content

Guard defining ComponentPreviewController on feature flag#7200

Merged
zachmargolis merged 7 commits intomainfrom
margolis-guard-component-controller
Oct 24, 2022
Merged

Guard defining ComponentPreviewController on feature flag#7200
zachmargolis merged 7 commits intomainfrom
margolis-guard-component-controller

Conversation

@zachmargolis
Copy link
Contributor

🎫 Ticket

slack discussion of error

🛠 Summary of changes

Why: we avoid loading lookbook gem unless the feature flag is on, so the classes to subclass and the mixins will fail due to load errors

How: I went with the sneaky trailing if to minimize diff noise

📜 Testing Plan

  • Deploy to a lower env with the feature disabled (int)

**Why**: we avoid loading lookbook gem unless the feature flag
is on, so the classes to subclass and the mixins will fail due to
load errors

**How**: I went with the sneaky trailing if to minimize diff noise
Copy link
Contributor

@tomas-nava tomas-nava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 that's a new trick to me! I might suggest adding a comment to explain why it's there, but functionally looks good to me.

@zachmargolis
Copy link
Contributor Author

🤯 that's a new trick to me! I might suggest adding a comment to explain why it's there, but functionally looks good to me.

trailing if statements work on blocks! so even each, loop, etc. Is 7ed4d9d what you were looking for?

@aduth
Copy link
Contributor

aduth commented Oct 24, 2022

I'm seeing a different error when testing this locally:

/path/to/gems/3.0.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader/callbacks.rb:25:in `on_file_autoloaded': expected file /path/to/identity-idp/app/controllers/component_preview_controller.rb to define constant ComponentPreviewController, but didn't (Zeitwerk::NameError)

@aduth
Copy link
Contributor

aduth commented Oct 24, 2022

ViewComponentsController is from the view_component gem so that should be defined regardless of feature flag status, and we could move the condition inside the class.

class ComponentPreviewController < ViewComponentsController
  if IdentityConfig.store.component_previews_enabled
    # ...
  end
end

Or, could it make sense to add a require 'lookbook' to the top of the file?

@zachmargolis
Copy link
Contributor Author

ViewComponentsController is from the view_component gem so that should be defined regardless of feature flag status, and we could move the condition inside the class.

Oh yeah I like that better than my first instinct, 5603a0a, so I updated to do this in 5031d89.

I thought loading lookbook did bad things (like compiling YARD) and so that's why we left it out in the first place

Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov>
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@zachmargolis zachmargolis merged commit 20b4a65 into main Oct 24, 2022
@zachmargolis zachmargolis deleted the margolis-guard-component-controller branch October 24, 2022 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants