Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(schema): cleanup meta tags and deduplicate charset/viewport #6378

Merged
merged 3 commits into from
Aug 7, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#14477, resolves nuxt/nuxt#13758

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This sanitises user input for meta config, including preventing duplicate viewport + charsets (via meta and also top-level setting). It also removes a bit of code that was previously added for Bridge support, which didn't have access to schema.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added bug Something isn't working dx 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Aug 5, 2022
@danielroe danielroe requested a review from pi0 August 5, 2022 11:19
@danielroe danielroe self-assigned this Aug 5, 2022
@netlify
Copy link

netlify bot commented Aug 5, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit f554de3
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62ed42b02285350008eaf17d

viewport: 'width=device-width, initial-scale=1',
const resolved = defu(val, get('meta'), {
charset: val?.meta?.find(m => m.charset)?.charset ?? 'utf-8',
viewport: val?.meta?.find(m => m.name === 'viewport')?.content ?? 'width=device-width, initial-scale=1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be simpler if we resolver after applying defu to conditionally set default viewport/charset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I want to distinguish between which is source of truth. So if head.charset is resolved to utf-8 - was that because user set it or because that was the default value?

Copy link
Member

@pi0 pi0 Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, we can add 3rd arg to defu too for real defaults. Not sure which syntax is more readable. One liner looks little bit unreadable. But we also have a find to filter below. It could be used to handle both filter and defaults for each.

@danielroe danielroe requested a review from pi0 August 5, 2022 17:45
@pi0 pi0 merged commit fc1d7d9 into main Aug 7, 2022
@pi0 pi0 deleted the fix/cleanup-head branch August 7, 2022 09:53
@pi0 pi0 mentioned this pull request Aug 9, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x bug Something isn't working dx 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot read properties of null (reading 'getAttribute') infinite log loop nuxt3 meta tag error
2 participants