Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: allow attributes on the title element#15983

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
jschaf wants to merge2 commits intosveltejs:main
base:main
Choose a base branch
Loading
fromjschaf:joe/allow-title-attrs

Conversation

jschaf
Copy link

The spec states the title element supports global attributes.https://html.spec.whatwg.org/#the-title-element

Reverts the title attribute validation introduced in#1721.

Fixes#5198.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC:https://github.com/sveltejs/rfcs
  • Prefix your PR title withfeat:,fix:,chore:, ordocs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code withinpackages/svelte/src, add a changeset (npx changeset).

Tests and linting

The test plan is to re-use packages/svelte/tests/validator/samples/title-no-attributes. By removing errors.json, we test that svelte compiles the title element with attributes.

  • Run the tests withpnpm test and lint the project withpnpm lint

The tests pass, butpnpm lint failed with:

> svelte-monorepo@0.0.1 lint /opt/p/svelte> eslint && prettier --check .Oops! Something went wrong! :(ESLint: 9.9.1Error: Cannot find module '/opt/p/svelte/node_modules/.pnpm/svelte-eslint-parser@0.43.0_svelte@packages+svelte/node_modules/svelte/compiler/index.js'    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1441:15)    at finalizeEsmResolution (node:internal/modules/cjs/loader:1430:15)

The spec states the title element supports global attributes.https://html.spec.whatwg.org/#the-title-elementReverts the title attribute validation introduced insveltejs#1721.Fixessveltejs#5198.
@changeset-botchangeset-bot
Copy link

changeset-botbot commentedMay 22, 2025
edited
Loading

🦋 Changeset detected

Latest commit:8740110

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
sveltePatch

Not sure what this means?Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@Rich-Harris
Copy link
Member

Thank you. Thearia-live thing seems like a good reason to have this but it's not quite as straightforward as this PR — you've removed the validation, but the<title> still won't have any attributes.

When you create a<title> in a component, Svelte doesn't actually create a<title> element and append it to the head, it instead setsdocument.title, because you're only supposed to have one. We could probably change that (each new<title> inside a<svelte:head> would be prepended to the<head> instead, and removed when the component was unmounted — browsers will do the right thing in that case) but we'd need to change the implementation in addition to removing the validation.

@jschaf
Copy link
Author

Thank you. Thearia-live thing seems like a good reason to have this but it's not quite as straightforward as this PR — you've removed the validation, but the<title> still won't have any attributes.

Ah, I see. I'll take a crack at rendering the attributes. Should I limit attributes to a subset?

@Rich-Harris
Copy link
Member

I don't think there's any reason to limit it, it's extra work to prevent something that someone might find useful in ways we don't anticipate.

I think the most interesting challenge here will be hydration, since in the (admittedly rare!) case of duplicate elements they need to be rendered in reverse order, so that 'later'<title> elements (e.g. in a+page.svelte) take precedence over 'earlier' ones (e.g. a fallback in a+layout.svelte). Quitewhy browsers work that way is a mystery, of course.

jschaf reacted with thumbs up emoji

SSR is pretty straight-forward. The client side is more difficult sincethe TitleElement doesn't have a node_id.
@jschaf
Copy link
Author

I added SSR title tag attributes by cribbing code from RegularElement in the latest commit. Client-side rendering is trickier, and I could use some pointers.

The TitleElement doesn't have a reference to the HTML element because we didn't need one before. To call build_set_attributes, I need a node_id, fromcontext.state.node.

The code for adding attributes is inlined in the client RegularElement. I extracted the smallest chunk of code into TitleElement to make it work.

  • How should I go about getting the node_id for a TitleElement?

  • Should I use RegularElement to render TitleElement?

  • I'm still using the assignment to document.title to set the title value. Should I keep that approach or append the title element to the head element
    The challenge with appending is that spec states multiple title tags are not allowed: The title tag may be used in "head element containing no othertitle elements."

@jschafjschaf marked this pull request as draftMay 22, 2025 23:14
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Allow attributes on the<title> element
2 participants
@jschaf@Rich-Harris

[8]ページ先頭

©2009-2025 Movatter.jp