-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Migrate away from ember-cli-head for <title> updates #168
Migrate away from ember-cli-head for <title> updates #168
Conversation
tests/dummy/app/index.html
Outdated
@@ -1,7 +1,7 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<title>Initial page title - removed by addon initializer</title> | |||
<!-- <title>Initial page title - removed by addon initializer</title> --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fastboot tests are green only if this is removed. But this is conflicting with the default app setup from ember new
. It seems there is no access via service:-document
to original title
element to update it or remove it. This needs to be solved before this PR can move forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue any ideas here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think apps will always have to remove this, we should remove it for them in our blueprint (making an ember-page-title
blueprint). And in the RFC that suggests adding ember-page-title to all new apps we should explicitly state that this will be removed in favor of actually invoking {{title}}
in the application.hbs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I'm pretty sure that this was already a constraint and not something new. Users of existing ember-page-title releases that are using ember-cli-fastboot along with ember-cli-head would have had to remove <title>
from app/index.html
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, how we can do this? If app/index.html has no <title>
then search engines index pages without titles out of the box. All non fastboot apps that today set meaningful static title for search engines will have conflicting setup out of box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could have ember-cli-fastboot's blueprint remove it? But for the most part, isn't it safe to assume the search engine will run our JS nowadays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about.
https://html.spec.whatwg.org/multipage/semantics.html#the-title-element - it does not say directly title is mandatory but seems strongly recommended.
https://validator.w3.org/ - from this tool perspective page without title is not valid HTML page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made tests assertions smarter to cope with 2 title tags being present for Fastboot tests with knowledge that in real life we'll ask people or make ember-cli-fastboot blueprint remove title from index.html.
addon/helpers/page-title.js
Outdated
let childNodes = document.head.childNodes; | ||
for (let i = 0; i < childNodes.length; i++) { | ||
let node = childNodes.item(i); | ||
if (node.tagName.toLowerCase() === 'title') { | ||
document.head.removeChild(node); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to remove the prior <title>
tags that we find? In FastBoot the only thing that would be here that might include the prior <title>
would have been someones head.hbs
or something, the static <title>
that is included in app/index.html
would not be overridden by this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not about the index.html static title
tag, its about nested routes page-title invocations. We either lookup existing title
element or clean up them all, so nested route titles like A | B | C
- would render correctly.
What we can do is lookup existing title
element we add on our own and remove all textNodes from it but end result is kind of the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe we can track the current element and just update its contents on subsequent invocations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ember-fastboot/simple-dom/blob/master/packages/%40simple-dom/document/src/node.ts#L38 - I have not found any update methods on simple-dom node
implementation to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can track either, because if we imagine nested routes:
A -> B -> C ... n
Then each of them has page-title
invocation in template, each of them triggers run.schedule afterRender
queueing and the fact that the update method is separate method here, is only thing that helps runloop to run it just once, although N number of invocations tried to initiate it again before afterRender queue ran.
Not sure how we could keep track of the element if don't know which of the helper instances has latest element reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we need to put the update logic into a service and the helper only updates some datastructure that keeps the order and builds out a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually will not be a problem if we properly wait for transition to finish for all title updates.
tests/dummy/app/index.html
Outdated
@@ -1,7 +1,7 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<title>Initial page title - removed by addon initializer</title> | |||
<!-- <title>Initial page title - removed by addon initializer</title> --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think apps will always have to remove this, we should remove it for them in our blueprint (making an ember-page-title
blueprint). And in the RFC that suggests adding ember-page-title to all new apps we should explicitly state that this will be removed in favor of actually invoking {{title}}
in the application.hbs
.
@@ -0,0 +1,7 @@ | |||
// Testem appends progress to the title... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, that sucks 😭
Ready for a rebase now |
522834b
to
1de2674
Compare
It is rebased and I will continue addressing PR feedback after CI run. |
Interesting, it seems by adding ember try scenario for fastboot and moving related dependencies out of package.json - made previously failing |
I removed ember-try fastboot scenario because the "typeof FastBoot" check allows us to run all other scenarios with browser + fastboot for more coverage. beta and canary fails again which is good, because with previous ember-try scenario we would have missed that unless we duplicated all the scenarios for all default ones. |
Beta and Canary failure seems to be coming from here: Not sure how and why this happens though. Any ideas @rwjblue?
Seems there issue open over here: glimmerjs/glimmer-vm#1141 |
The test / dummy app has few bugs still from previous times already. It's broken on Github pages current version as well, I'll see if it is an easy fix or evolves separate PR after this one. |
Canary is green now, beta bump is not available yet, therefore it's still failing. |
Restarted the beta CI job |
1fc75be
to
4746f01
Compare
4746f01
to
0bb7d33
Compare
@rwjblue any updates on review here? |
Any updates here? |
1583326
to
04dc0a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple questions, or potential changes
Thank you so much for pushing this to completion @raido! |
Use direct page title manipulation instead of ember-cli-head.
Fastboot apps have to remove
<title>
from app/index.html as before and for non-fastboot apps everything should work out of the box.Closes #167