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

Do not reload the app after a file required during initialization is changed #720

Open
GCorbel opened this issue May 29, 2024 · 3 comments

Comments

@GCorbel
Copy link

GCorbel commented May 29, 2024

During the initialization of a Rails app, some files are required and added to $LOADED_FEATURES so, when they are changed, the whole app reloads.

I want to avoid that and I this commenting the line that add them to the watcher fix my issue.

Is there a proper way to do that ? I don't understand at which step Spring::Application#preload is called but maybe it's a good idea to watch only files loaded before Rails.application.config.after_initialize or Rails.application.config.to_preload.

@rafaelfranca
Copy link
Member

It happens before even the application is loaded, so we can't implement any logic that depends on what happened in the application. Unfortunately there is no way to do this. We could have a Watcher#remove method so you could configure srping to stop watching a file.

@GCorbel
Copy link
Author

GCorbel commented May 30, 2024

I agree with Watcher#remove.

I tried to do Spring.watcher.files.reject! { |k, v| $LOADED_FEATURES.include?(k) } but it's not enough because spring is running in a different thread. I'm not sure how to do.

@GCorbel
Copy link
Author

GCorbel commented May 31, 2024

I gave a closer look and I don't see how to change files watched once the server is running.

The best solution I found ATM is adding this in config/spring.rb :

module OverrideWatcher
  def add(*items)
    items.reject! { |k, _v| $LOADED_FEATURES.include?(k) }
    super
  end
end
Spring.watcher.extend(OverrideWatcher)

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

No branches or pull requests

2 participants