discourse/app
David Taylor 3513835722
DEV: Improve and document __container__ workaround in tests (#15498)
Modern Ember only sets up a container when the ApplicationInstance is booted. We have legacy code which relies on having access to a container before boot (e.g. during pre-initializers).

In production we run with the default `autoboot` flag, which triggers Ember's internal `_globalsMode` flag, which sets up an ApplicationInstance immediately when an Application is initialized (via the `_buildDeprecatedInstance` method).

In tests, we worked around the problem by creating a fresh container, and placing a reference to it under `Discourse.__container__`.

HOWEVER, Ember was still creating a Container instance for each ApplicationInstance to use internally, and make available to EmberObjects via injection. The `Discourse.__container__` instance we created was barely used at all.

Having two different Container instances in play could cause some weird issues. For example, I noticed the problem because the `appEvents` instance held by DiscourseURL was different to the `appEvents` instance held by all the Ember components in our app. This meant that events triggered by DiscourseURL were not picked up by components in test mode.

This commit makes the hack more robust by ensuring that Ember re-uses the Container instance which we created pre-boot. This means we only have one Container instance in play, and makes `appEvents` work reliably across all parts of the app. It also adds detailed comments describing the hack, to help future travelers.

Hopefully in future we can remove this hack entirely, but it will require significant refactoring to our initialization process in Core and Plugins.

The mapping-router and map-routes initializer are updated to avoid the need for `container.lookup` during teardown. This isn't allowed under modern Ember, but was previously working for us because the pre-initializer was using the 'fake' container which was not ember-managed.
2022-01-10 10:34:08 +00:00
..
assets DEV: Improve and document __container__ workaround in tests (#15498) 2022-01-10 10:34:08 +00:00
controllers DEV: Avoid $ globals (#15453) 2022-01-08 23:39:46 +01:00
helpers SECURITY: Remove ember-cli specific response from application routes (#15155) 2021-12-01 16:10:40 +00:00
jobs DEV: Fix methods removed in Ruby 3.2 (#15459) 2022-01-05 18:45:08 +01:00
mailers DEV: Hash tokens stored from email_tokens (#14493) 2021-11-25 09:34:39 +02:00
models DEV: Ignore dropped Bookmark columns. 2022-01-10 16:04:22 +08:00
serializers FEATURE: Experimental support for group membership via google auth (#14835) 2021-12-09 12:30:27 +00:00
services DEV: Avoid $ globals (#15453) 2022-01-08 23:39:46 +01:00
views UX: updated "accept invite" error page (#15490) 2022-01-09 10:21:42 +05:30