-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
chore: remove rel shortcut
from favicon
#2646
Open
techfg
wants to merge
1
commit into
withastro:main
Choose a base branch
from
techfg:chore/remove-favicon-rel-shortcut
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/starlight': patch | ||
--- | ||
|
||
Remove 'shortcut' from favicon rel attribute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thank you for the PR @techfg!
Could you explain why the
data-favicon
attribute was added in this PR? It’s not mentioned in the PR description and I don’t believe it’s a web standard.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.
@delucis - The previous code detected
shortcut icon
as way to set the sort weight to70
so I needed a way to maintain that behavior and adding a custom attribute seemed like the only way to detect the "starlight" favicon. I considered naming the attributedata-sl-favicon
to clearly identify its a starlight custom attribute but in reviewing other custom attributes throughout the code base, it didn't appear thatsl
was applied so left it asdata-favicon
. Happy to modify this approach and/or name if you'd like, just need another option for maintaining the sort weight adjustment. Let me know, thanks!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.
Ahhh, understood. OK.
Reading the comment in the head processing code, it says:
The current heuristic of relying on
shortcut icon
honestly seems not a great idea (I’m looking at you past self 👀). I wonder if we can just short based on the extension? So instead of needing the extra data attribute, we make sure an SVG favicon is listed last?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.
Agreed on the prior approach not being ideal (e.g., there could be multiple with
shortcut icon
to begin with), was going to mention but wasn't really relevant 😃.The concern I'd have with detecting SVG directly is that there may not even be an SVG and even if there is, there may be multiple (e.g., config contains custom
head
attributes for different sizes).I guess the question comes down to what the comment you referenced was really intending to do - I can think of three ways to interpret:
favicon
defined in the Starlight configuration property was always last (regardless of its type - e.g., svg, png, ico, jpg, etc.) - this is what thedefault favicon
portion of the comment may have been referring to along with potentially assuming it would be an SVG.favicon
defined in the Starlight configuration property if its an SVG was always lasthead
configurationlink
) was lastIt appears that head config was added to Starlight prior to favicon which provides some context to the comment, but it still is a little ambiguous in terms of what it was intending to do unless I'm just overthinking the comment 😄.
In doing some research on how user agents/browsers determine which browser to use, Wikipedia seemed to be provide some information for anything definitive. Unfortunately, every browser is a little different assuming the information there is accurate and at the end of the day, user agents/browsers are free to change how they choose a favicon in the future.
This article seems to be the de facto guide on favicons but there is no way at build/runtime for Starlight to know what was added to
head
configuration regarding favicon reliably (or at least without doing a lot of inspection ofrel
&type
attributes) and it could really be anything with any number of meta tags.All the above said, do you recall what you were ultimately intending to do with the
favicon
config property and sort weight? Depending on that, I can think of a few options:80
link
that is for ansvg
and weight at70
favicon
config property if it's ansvg
and weight at70
favicon
config property regardless of type and weight at70
(this is what the prior code kind of did and what the code in the PR does currently)One other note is that there is no way to "disable" starlight from generating the favicon link (unless
Head
is overridden) since it seems merge would not detect them as the same (see stackblitz repro) so there is no way for a user to completely control sort order short of overridingHead
. Possiblyfavicon
config should support a value offalse
to disable it but that's a separate feature request and may not be necessary.In meantime;
head
config doesn't provide a way to control sort order of meta tags I think minimizing what is sorted may be best so possibly option 1 should be followed especially given how user agents/browsers determine which to use is not part of a spec and varies.favicon
config property will always come last regardless of its type (would require thedata-favicon='default'
attribute)link
,rel='icon'
and eitherhref
ends with.svg
ortype='image/svg+xml'
(note that a customhead
item may not havetype
set so some SVGs may be missed)favicon
config property if SVG - Option 3 with checks forlink
,rel='icon'
andtype='image/svg+xml'
anddata-favicon='default'
Sorry for the long winded comment, this one isn't as straightforward as it may first appear. I think it all comes down to seeing if you can recall why you conditioned the sort weight originally and then deciding from there how to best adjust/handle 😄
Lemme know your thoughts, thanks!