Skip to content

Commit eea3d5a

Browse files
committed
Revert lazy routesets (rails#52012) due to polymorphic routing regression
References rails#52012 (comment) Revert "Merge pull request rails#52033 from Shopify/amend_lazy_routes_changelog" This reverts commit 743128b, reversing changes made to 6622075. Revert "Merge pull request rails#52012 from Shopify/defer_route_drawing" This reverts commit 6622075, reversing changes made to 5dabff4.
1 parent 16d8b82 commit eea3d5a

24 files changed

+47
-377
lines changed

actionpack/lib/action_dispatch/testing/assertions/routing.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def with_routing(&block)
4646
def create_routes
4747
app = self.app
4848
routes = ActionDispatch::Routing::RouteSet.new
49-
middleware = app.config.middleware.dup
50-
middleware.delete(Rails::Rack::LoadRoutes) if defined?(Rails::Rack::LoadRoutes)
51-
rack_app = middleware.build(routes)
49+
rack_app = app.config.middleware.build(routes)
5250
https = integration_session.https?
5351
host = integration_session.host
5452

actionpack/test/abstract_unit.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ def env
3434
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test")
3535
end
3636

37-
def application; end
38-
3937
def root; end
4038
end
4139
end

actionpack/test/dispatch/routing_assertions_test.rb

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
require "rails/engine"
55
require "controller/fake_controllers"
66

7-
class SecureArticlesController < ArticlesController
8-
def index
9-
render(inline: "")
10-
end
11-
end
7+
class SecureArticlesController < ArticlesController; end
128
class BlockArticlesController < ArticlesController; end
139
class QueryArticlesController < ArticlesController; end
1410

@@ -280,20 +276,6 @@ class RoutingAssertionsControllerTest < ActionController::TestCase
280276

281277
class WithRoutingTest < ActionController::TestCase
282278
include RoutingAssertionsSharedTests::WithRoutingSharedTests
283-
284-
test "with_routing routes are reachable" do
285-
@controller = SecureArticlesController.new
286-
287-
with_routing do |routes|
288-
routes.draw do
289-
get :new_route, to: "secure_articles#index"
290-
end
291-
292-
get :index
293-
294-
assert_predicate(response, :ok?)
295-
end
296-
end
297279
end
298280
end
299281

@@ -313,18 +295,6 @@ class RoutingAssertionsIntegrationTest < ActionDispatch::IntegrationTest
313295

314296
class WithRoutingTest < ActionDispatch::IntegrationTest
315297
include RoutingAssertionsSharedTests::WithRoutingSharedTests
316-
317-
test "with_routing routes are reachable" do
318-
with_routing do |routes|
319-
routes.draw do
320-
get :new_route, to: "secure_articles#index"
321-
end
322-
323-
get "/new_route"
324-
325-
assert_predicate(response, :ok?)
326-
end
327-
end
328298
end
329299

330300
class WithRoutingSettingsTest < ActionDispatch::IntegrationTest

railties/CHANGELOG.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
*Deepak Mahakale*
44

5-
* Defer route drawing to the first request, or when url_helpers are called
6-
7-
Executes the first routes reload in middleware, or when a route set's
8-
url_helpers receives a route call / asked if it responds to a route.
9-
Previously, this was executed unconditionally on boot, which can
10-
slow down boot time unnecessarily for larger apps with lots of routes.
11-
12-
Environments like production that have `config.eager_load = true` will
13-
continue to eagerly load routes on boot.
14-
15-
*Gannon McGibbon*
16-
175
* Add Rubocop and GitHub Actions to plugin generator.
186
This can be skipped using --skip-rubocop and --skip-ci.
197

railties/lib/rails/application.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
require "active_support/encrypted_configuration"
1010
require "active_support/hash_with_indifferent_access"
1111
require "active_support/configuration_file"
12-
require "active_support/parameter_filter"
1312
require "rails/engine"
1413
require "rails/autoloaders"
1514

@@ -154,10 +153,6 @@ def reload_routes!
154153
routes_reloader.reload!
155154
end
156155

157-
def reload_routes_unless_loaded # :nodoc:
158-
initialized? && routes_reloader.execute_unless_loaded
159-
end
160-
161156
# Returns a key generator (ActiveSupport::CachingKeyGenerator) for a
162157
# specified +secret_key_base+. The return value is memoized, so additional
163158
# calls with the same +secret_key_base+ will return the same key generator

railties/lib/rails/application/default_middleware_stack.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def build_stack
6262
middleware.use ::ActionDispatch::ActionableExceptions
6363
end
6464

65-
middleware.use ::Rails::Rack::LoadRoutes unless app.config.eager_load
66-
6765
if config.reloading_enabled?
6866
middleware.use ::ActionDispatch::Reloader, app.reloader
6967
end

railties/lib/rails/application/finisher.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def self.complete(_state)
160160
initializer :set_routes_reloader_hook do |app|
161161
reloader = routes_reloader
162162
reloader.eager_load = app.config.eager_load
163+
reloader.execute
163164
reloaders << reloader
164165

165166
app.reloader.to_run do
@@ -177,12 +178,7 @@ def self.complete(_state)
177178
ActiveSupport.run_load_hooks(:after_routes_loaded, self)
178179
end
179180

180-
if reloader.eager_load
181-
reloader.execute
182-
ActiveSupport.run_load_hooks(:after_routes_loaded, self)
183-
elsif reloader.loaded
184-
ActiveSupport.run_load_hooks(:after_routes_loaded, self)
185-
end
181+
ActiveSupport.run_load_hooks(:after_routes_loaded, self)
186182
end
187183

188184
# Set clearing dependencies after the finisher hook to ensure paths

railties/lib/rails/application/routes_reloader.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Application
77
class RoutesReloader
88
include ActiveSupport::Callbacks
99

10-
attr_reader :route_sets, :paths, :external_routes, :loaded
10+
attr_reader :route_sets, :paths, :external_routes
1111
attr_accessor :eager_load
1212
attr_writer :run_after_load_paths # :nodoc:
1313
delegate :execute_if_updated, :execute, :updated?, to: :updater
@@ -17,11 +17,9 @@ def initialize
1717
@route_sets = []
1818
@external_routes = []
1919
@eager_load = false
20-
@loaded = false
2120
end
2221

2322
def reload!
24-
@loaded = true
2523
clear!
2624
load_paths
2725
finalize!
@@ -30,14 +28,6 @@ def reload!
3028
revert
3129
end
3230

33-
def execute_unless_loaded
34-
unless @loaded
35-
execute
36-
ActiveSupport.run_load_hooks(:after_routes_loaded, Rails.application)
37-
true
38-
end
39-
end
40-
4131
private
4232
def updater
4333
@updater ||= begin

railties/lib/rails/commands/routes/routes_command.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def invoke_command(*)
2323
desc "routes", "List all the defined routes"
2424
def perform(*)
2525
boot_application!
26-
Rails.application.reload_routes_unless_loaded
2726
require "action_dispatch/routing/inspector"
2827

2928
say inspector.format(formatter, routes_filter)

railties/lib/rails/commands/unused_routes/unused_routes_command.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def action_missing?
4141

4242
def perform(*)
4343
boot_application!
44-
Rails.application.reload_routes_unless_loaded
4544
require "action_dispatch/routing/inspector"
4645

4746
say(inspector.format(formatter, routes_filter))

0 commit comments

Comments
 (0)