Skip to content

Commit

Permalink
Remove Application wrapper div
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Dec 11, 2017
1 parent 1b3e82a commit 1afce81
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions text/0000-remove-application-wrapper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
- Start Date: 2017-12-11
- RFC PR: https://github.com/emberjs/rfcs/pull/280
- Ember Issue: (leave this empty)

# Summary

Introduce a low-level "flag" to remove the automatic wrapper `<div>` around
Ember apps and tests.

# Motivation

In Ember applications today, applications are anchored to some existing html
element in the page. Usually, this element is the `<body>` of the document, but it
can be configured to be a different one when the application is defined,
passing a CSS selector to the `rootElement` property:

```js
export default Ember.Application.extend({
rootElement: '#app'
});
```

However, whatever the root is, the application adds another `<div>` wrapper
that it's not requited anymore. It's just a vestigial reminder of some implementation
detail of how views worked in Ember 1.x. Some sort of wisdom tooth of the original
rendering system that it serves no purpose today.

Furthermore, much like a wisdom tooth, it can gives us problems. In the past this element
was configurable using the `ApplicationView`, but when views were removed we lost that
ability. Right now we are stuck with a wrapper element we can't remove and we also can't
customize, which is why some apps target the selector `body > .ember-view` to style this
element.

Similarly, in testing there is another `.ember-view` wrapper inside the
`#ember-testing` container for no good reason.

This RFC proposes to add a global flag to remove those wrapper elements,
effectively making the `application.hbs` template have "Outer HTML" semantics, which aligns
well with [the changes proposed recently](#278) for template-only components and the way glimmer
apps work.

The same flag will also remove the unnecessary extra wrapper inside the testing
container.

# Detailed design

## API Surface

The proposed approach is identical to the one proposed in #278, that I reproduce
pristine below in italic:

*We should not expose the flag directly as a public API. Instead, we should
abstract the flag with a "privileged addon" whose only purpose is to enable
the flag. Applications will enable the flag by installing this addon. This
will allow for more flexibility in changing the flag's implementation (the
location, naming, value, or even the existence of it) in the future. From the
user's perspective, it is the addon that provides this functionality. The
flag is simply an internal implementation detail.*

*We have done this before in other cases (such as the legacy view addon during
the 2.0 transition period), and it has generally worked well.*

*When landing this feature, it will be entirely opt-in for existing apps, but
the Ember CLI application blueprint should be updated to include the addon by
default. At a later time, we should provide another addon that _disables_ the
flag explicitly (installing both addons would be an install-time error). At
that time, we will issue a deprecation warning if the flag is *not set*, with
a message that directs the user to install one of the two addons.*

## Migration Path

Given that this change only affects one single point in your application,
I do not believe we need any specific strategy. If the users want to bring
back the wrapper because it breaks their styles or some other reason,
they can just add it manually on the `application.hbs` template, with
any class or id they want.

# How We Teach This

This addon will be an opt in, but at some point it will become part of
the default blueprint. This change, rather than introducing a new concept, it *removes*
an old one. Users won't have to google what is the way to remove or customize
the implicit application wrapper of the app (to sadly discover that is not
even possible), but instead they will just add a wrapper only if they want,
and in the same way they would add a wrapper in any other point of their application,
with regular handlebars.

# Drawbacks

There is a possibility that removing the wrapper can break styles for some apps,
but since adding the wrapper back is just of editing the `application.hbs` template,
that is probably a despicable drawback.

There is also a non-zero chance that some testing addon is relying on the `#ember-testing > .ember-view`
html hierarchy for some reason, and those addons would have to be updated.

# Alternatives

Leave things as they are today.

0 comments on commit 1afce81

Please sign in to comment.