-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Support Populating head tags in Routes #506
Conversation
Should it be possible to invoke the head method again to update head parameters? Maybe we should define Another thing one could discuss is how nested routes should behave. Given routes e.g. https://www.npmjs.com/package/ember-cli-document-title-northm will merge up to allow easy |
I would be inclined to say no. Is there a use case for updating meta later after rendering the page?
I think for sure you should be able to define a |
I was mostly thinking about it, because the meta method returns |
This hook will be in each route, so there is no need to make it computed or call it again, it will be set per route already. |
I've used a few of the community addons for setting and updating the
|
That was mentioned above. It'll work just like you expect it to, allowing for templates of some sort, like the addons do. <title seems like a very special case for a template concern (i.e. it's kinda sorta global). Does it really make sense to put this concern on a route? I think it does. title is set at the route level with the existing addons, and in other frameworks. I think the use cases for changing any head data, after the page is fully rendered, are pretty minimal. Is there a use case you have in mind for wanting to change it multiple times for a single page?
I think, in theory, we should support all relevant tags, but starting with meta would be a good first step. |
Usually any messenger app will update its page title for new activity. |
Ah gotcha, good point. We probably should provide a way to dynamically update it then. Thanks for giving that example! |
For some uses of head tag substitutions, especially for things like SEO or accessibility, they don't do you a lot of good unless they are in the page as it first hits the browser because the scanners only execute at the usual page load complete events. That usually means the substitutions with this restriction have no effect unless they hit in prember or fastboot. (Of course using routes with a11y is its own story...) You might want a paragraph about where this won't help. |
Pinning this down to something in routes specifically feels like a side step move. Instead of making this a route API what if we made head tag manipulation an official and injectable service. This allows a lot more flexibility meaning users don't have to learn a new API or hook in the route. Instead it becomes a standard service users can interact with via Routes, Components, and Modifiers. I'm inspired a lot by Next.js's use of Head as a context provider (similar to services) which makes it really easy to work with as a standard part of the app (and also really easy to not have be part of your app if you don't want to handle |
I'm a big fan of services. |
For some examples and reasoning, making this a service unlocks:
For example if I have a <li {{did-insert this.addBreadCrumbToHead}} {{will-destroy this.removeBreadCrumbFromHead}}> |
@rtablada @NullVoxPopuli I'm in favor of a service, but I would want to have it injected in routes by default, I think. We could probably work out an API that would work the same regardless of where the service was injected, but the idea would be to set things primarily for pages/routes. I believe Nuxt.js, which may or may not be similar to Next.js, allows setting head data wherever you want, but the API is the same for global, pages, components, etc just a |
The recent initiatives go to an explicit injection. The initializers remain to inject into routes the dependencies of your choice. As you, I am a huge fan of services. It would meet your expectations @rwwagner90, providing clarity and flexibility. |
@tleperou it's just one extra step that people have to do, when I would prefer it to feel built in. Maybe there is a way we can inject on the fly versus always injecting in routes. i.e. only inject if |
What if the default injections are added to the route blueprint? |
I tend to prefer as much magic as possible, but others may prefer more explicit injections. |
Even if in the case of the
However, inject script/link from there seems inappropriate. Meta tags do not alter the execution of the application while scripts and CSS may do it. The risk I see is an unpredictable behavior. |
While I do get the ease of use argument the tools are there to choose your own ease of use. I think it'd be much easier to come to a consensus on an injectable service rather than adding to the already large API surface of routes. For those that want to add their own special I also think that a service would be a first step before recommending adding new hooks and magic to routes. |
There is no disagreement here. Service based is what everyone has asked for here, any and all magic would be in the service itself. Just trying to find ways to make everyone happy here 😃 |
I'm very much in favor of this. Would also add that it has to be flexible enough for a variety of types of apps. Could even be a top level component. A few non traditional examples would include:
If this never makes it out of RFC, I would be in favor of helping out including how one could do this in the docs as well. |
@snewcomer I need to update this RFC based on the comments so far. It has stalled out for a bit. |
@rwwagner90 do you think you're likely to update this RFC? Or would anyone else like to take it over? |
@wagenet is there interest in still moving this forward? I could update it if there is. |
@rwwagner90 we discussed this at Framework Core today and agreed that while we think this is definitely a problem worth solving, we don’t want to solve it by adding more behavior to the existing routing stack. We are, as part of Polaris, looking at how to re-work routing in general, so adding more things that has to solve seems like a bad move. Accordingly, we're putting this in FCP to close today. If you’re still interested in driving forward the solutions here, there are a couple options we’re thinking about in this space:
There might be others! |
Rendered