-
Notifications
You must be signed in to change notification settings - Fork 12
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
As a user I would like to Customize HEAD contents with application state #8
Comments
👍 IMO head should be passed whatever is passed to the page. It is part of the page after all |
I agree with @jlipps. I think the fact that the API for head is different than the one for pages and custom elements is confusing. I'd expect to have access to |
any movement on this? i really want to give my pages different titles for SEO and general sanity :-) |
noodling on the right solution here. one thought is a special set of |
Yeah, there are 100 ways to skin the cat (gross?), but I think the choices the helmet team made are a reasonable place to start: https://github.com/nfl/react-helmet#readme I will also say that this topic (how to include custom |
ok, so the ideal here is symmetrical api signature. I get that. I am thinking rn that maybe we do the following instead:
its important to note you cannot use custom elements in a head per the browser spec so we don't want to give an impression you can or should do that. we'd probably warn or error out in this case. wdyt? |
@brianleroux on that plan where would 'common' head stuff go, if not |
When you say "support Developers need to be able to render markup in the |
unsure still! looks like our parser impl strips |
think we'll always support the current the other footgun here is |
This isn't limited to this issue, but I think the fact that Enhance uses HTML custom elements as it's server-side templating/rendering solution for developers is cool but will require intense education on what HTML custom elements are, what you can do, and what you can't do. Above you stated that
...even if you could get your parser to accept/parse it, because it would fly in the face of the spec violation, which you are trying to educate your users about. |
yeah @kristoferjoseph is looking at this because we want you to be able to pass state to the head. idea rn is something like this (notice the <head>
<my-social-tags title="a cool title" is=title></my-social-tags>
</head>``` |
This is a valid use case that we should support. I would like to focus on the use case and the possible solutions. Use case seems clear; As a developer I would like to customize the contents of the Solutions are going to need some understanding of the real world constraints.
Keep these considerations in mind when we outline the possible solutions
We would still need to do something like add support for the contentious Open to other ideas but this is much as my poor brain can come up with in my current sickly state. Hoping I can thought much gooder soon in order to help solve this for you good people. |
Oh this is a more interesting problem than I thought. Thanks for explaining these points, KJ. Side-note: As for rendering a custom element in the Head function (number 2 above) and returning anything other than a string: I don't really think that's necessary and not so much what my original post was about -- though, I understand how we got there because it would be a slick shortcut. IMO, sending I do like the helmet idea from an ergonomics perspective. But it does add a bit of magic; which Enhance has mostly shied away from. Which I appreciate. I'm torn. If it comes down to spec compliance or ergonomics, I will always be in favor of compliance. I need to think on it some more... :D |
@kristoferjoseph, addressing your points one by one:
I'm surprised to hear that creating an Regarding the inability to stream the HTML response prior to full rendering the entirety of the HTML document, that's a tradeoff I could live with. |
Just to say I agree with @crtr0 that trading off HTML streaming for greater ergonomics here is worth it to me as well. Maybe just documenting that if you take advantage of custom stuff in head you give up streaming would be enough to let people make the decision on their own? |
@crtr0 What you are outlining there is JavaScript that manipulates the DOM in the browser. You are allowed to manipulate the DOM with JavaScript in the browser but at that time it will be after the page and JavaScript has been parsed which is too late for most head use cases. You can however create a string template literal that returns html that is allowed in the head and use that inside your head component if you'd like.
Then in your
It's subtle but the difference is this is just returning a string without custom element parsing since they aren't allowed. |
I've added a PR for |
It would be great to get the state returned from an api middleware/handler/fn/thing.
Use case:
I have
app/api/users/$id.mjs
I use the
id
param to look up a user in my db to get their username (like "tbeseda").I want to set the
<title>
of my view to "tbeseda's profile" when a visitor lands on /users/303 (where 303 is tbeseda's id).Right now I don't think this is possible without running another query in my Head fn. I believe the Head fn only gets the incoming request, so I do have the id, but not the db record.
The text was updated successfully, but these errors were encountered: