Skip to content

fix: improve ordering of head elements#15232

Merged
elliott-with-the-longest-name-on-github merged 4 commits intomainfrom
kit-15224
Feb 3, 2026
Merged

fix: improve ordering of head elements#15232
elliott-with-the-longest-name-on-github merged 4 commits intomainfrom
kit-15224

Conversation

@elliott-with-the-longest-name-on-github
Copy link
Contributor

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented Jan 30, 2026

Closes #15224

While I was fixing the above, I noticed that it's kind of hard to see where the head is being constructed, and also hard to figure out what order that's happening in. This is just a drive-by improvement to add a bit more structure -- smash stuff into head, build it at the end, and everything will always be in the optimal order.

The new order is:

  1. HTTP equivalent metatags (only applies on prerender pages)
  2. Link tags (also only applies in prerendering)
  3. Script preloads
  4. User content
  5. Style tags
  6. Stylesheet links (these are all "disabled" and only exist to instruct Vite)

I'm open to suggestions on reordering this if there's a better order, but it seemed better to put the network-request-creating stuff earlier than the others.


Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: c6ce897

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@kiwixz
Copy link

kiwixz commented Feb 1, 2026

Hi, and first of all thanks for fixing this so quickly!

I wonder if "user content" should go between preload (3) and styles (4).
I'm not sure what else could be in there, but I would imagine titles, metatags, preloads, favicons; which all would benefit from being a little earlier in the order.

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github merged commit 37293a5 into main Feb 3, 2026
39 of 44 checks passed
@github-actions github-actions bot mentioned this pull request Feb 3, 2026
benmccann pushed a commit that referenced this pull request Feb 12, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/adapter-netlify@6.0.0

### Major Changes

- breaking: `platform.context` is now the [modern Netlify Functions
(\[#15203\](#15203))

context](https://docs.netlify.com/build/functions/api/#netlify-specific-context-object)

    Previously, this was the [AWS Lambda-style

context](https://github.com/netlify/primitives/blob/c1ae30f2745f0a73e26e83334695e205a04ab47d/packages/functions/prod/src/function/handler_context.ts).

If you were using this in your app (unlikely), you will need to update
your code to read from new fields.

### Minor Changes

- feat: Migrate to the modern Netlify Functions API
([#15203](#15203))

The Netlify adapter now generates "v2" Netlify Functions, which uses
modern standards (ESM, `Request`, `Response`) instead of the legacy
"Lambda-compatible" or "v1" format. Under the hood, this greatly
simplifies the adapter code and improves maintainability.

For more details on features this unlocks for your SvelteKit app, see

<https://developers.netlify.com/guides/migrating-to-the-modern-netlify-functions/>.

- feat: allow configuring redirects in `netlify.toml`
([#15203](#15203))

The limitation of only being able to configure redirects via the
`_redirects` file has been removed.

### Patch Changes

- fix: populate `App.Platform` with `context` property
([#15203](#15203))

- Updated dependencies
\[[`37293a5`](37293a5),
[`5d05ca6`](5d05ca6),
[`ed69b77`](ed69b77),
[`b1fc959`](b1fc959),
[`159aece`](159aece),
[`c690579`](c690579),
[`dc8cf2d`](dc8cf2d),
[`ace2116`](ace2116),
[`0f38f49`](0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/kit@2.51.0

### Minor Changes

- feat: add `scroll` property to `NavigationTarget` in navigation
callbacks ([#15248](#15248))

Navigation callbacks (`beforeNavigate`, `onNavigate`, and
`afterNavigate`) now include scroll position information via the
`scroll` property on `from` and `to` targets:

- `from.scroll`: The scroll position at the moment navigation was
triggered
- `to.scroll`: In `beforeNavigate` and `onNavigate`, this is populated
for `popstate` navigations (back/forward) with the scroll position that
will be restored, and `null` for other navigation types. In
`afterNavigate`, this is always the final scroll position after
navigation completed.

This enables use cases like animating transitions based on the target
scroll position when using browser back/forward navigation.

- feat: `hydratable`'s injected script now works with CSP
([#15048](#15048))

### Patch Changes

- fix: put preloads before styles
([#15232](#15232))


- fix: suppress false-positive inner content warning when children prop
is forwarded to a child component
([#15269](#15269))


- fix: `fetch` not working when URL is same host but different than
`paths.base` ([#15291](#15291))


- fix: navigate to hash link when base element is present
([#15236](#15236))


- fix: avoid triggering `handleError` when redirecting in a remote
function ([#15222](#15222))


- fix: include `test` directory in generated `tsconfig.json` alongside
existing `tests` entry
([#15254](#15254))


- fix: generate `tsconfig.json` using the value of `kit.files.src`
([#15253](#15253))

## @sveltejs/adapter-cloudflare@7.2.7

### Patch Changes

- fix: error if `_routes.json` is in the `/static` public directory
([#12821](#12821))


- fix: correctly handle pathnames found in the `_redirects` file
([#12821](#12821))

- Updated dependencies
\[[`37293a5`](37293a5),
[`5d05ca6`](5d05ca6),
[`ed69b77`](ed69b77),
[`b1fc959`](b1fc959),
[`159aece`](159aece),
[`c690579`](c690579),
[`dc8cf2d`](dc8cf2d),
[`ace2116`](ace2116),
[`0f38f49`](0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/adapter-node@5.5.3

### Patch Changes

- fix: validate `ORIGIN` env var at startup
([#15045](#15045))


- chore(deps): update dependency `@rollup/plugin-commonjs` to v29
([#14856](#14856))

- Updated dependencies
\[[`37293a5`](37293a5),
[`5d05ca6`](5d05ca6),
[`ed69b77`](ed69b77),
[`b1fc959`](b1fc959),
[`159aece`](159aece),
[`c690579`](c690579),
[`dc8cf2d`](dc8cf2d),
[`ace2116`](ace2116),
[`0f38f49`](0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/enhanced-img@0.10.1

### Patch Changes

- fix: replace erroneous `import.meta.DEV` with `import.meta.env.DEV` in
generated code ([#15285](#15285))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
* fix: improve ordering of `head` elements

* formatting

* simplify

* Apply suggestion from @elliott-with-the-longest-name-on-github

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/adapter-netlify@6.0.0

### Major Changes

- breaking: `platform.context` is now the [modern Netlify Functions
(\[sveltejs#15203\](sveltejs#15203))

context](https://docs.netlify.com/build/functions/api/#netlify-specific-context-object)

    Previously, this was the [AWS Lambda-style

context](https://github.com/netlify/primitives/blob/c1ae30f2745f0a73e26e83334695e205a04ab47d/packages/functions/prod/src/function/handler_context.ts).

If you were using this in your app (unlikely), you will need to update
your code to read from new fields.

### Minor Changes

- feat: Migrate to the modern Netlify Functions API
([sveltejs#15203](sveltejs#15203))

The Netlify adapter now generates "v2" Netlify Functions, which uses
modern standards (ESM, `Request`, `Response`) instead of the legacy
"Lambda-compatible" or "v1" format. Under the hood, this greatly
simplifies the adapter code and improves maintainability.

For more details on features this unlocks for your SvelteKit app, see

<https://developers.netlify.com/guides/migrating-to-the-modern-netlify-functions/>.

- feat: allow configuring redirects in `netlify.toml`
([sveltejs#15203](sveltejs#15203))

The limitation of only being able to configure redirects via the
`_redirects` file has been removed.

### Patch Changes

- fix: populate `App.Platform` with `context` property
([sveltejs#15203](sveltejs#15203))

- Updated dependencies
\[[`37293a5`](sveltejs@37293a5),
[`5d05ca6`](sveltejs@5d05ca6),
[`ed69b77`](sveltejs@ed69b77),
[`b1fc959`](sveltejs@b1fc959),
[`159aece`](sveltejs@159aece),
[`c690579`](sveltejs@c690579),
[`dc8cf2d`](sveltejs@dc8cf2d),
[`ace2116`](sveltejs@ace2116),
[`0f38f49`](sveltejs@0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/kit@2.51.0

### Minor Changes

- feat: add `scroll` property to `NavigationTarget` in navigation
callbacks ([sveltejs#15248](sveltejs#15248))

Navigation callbacks (`beforeNavigate`, `onNavigate`, and
`afterNavigate`) now include scroll position information via the
`scroll` property on `from` and `to` targets:

- `from.scroll`: The scroll position at the moment navigation was
triggered
- `to.scroll`: In `beforeNavigate` and `onNavigate`, this is populated
for `popstate` navigations (back/forward) with the scroll position that
will be restored, and `null` for other navigation types. In
`afterNavigate`, this is always the final scroll position after
navigation completed.

This enables use cases like animating transitions based on the target
scroll position when using browser back/forward navigation.

- feat: `hydratable`'s injected script now works with CSP
([sveltejs#15048](sveltejs#15048))

### Patch Changes

- fix: put preloads before styles
([sveltejs#15232](sveltejs#15232))


- fix: suppress false-positive inner content warning when children prop
is forwarded to a child component
([sveltejs#15269](sveltejs#15269))


- fix: `fetch` not working when URL is same host but different than
`paths.base` ([sveltejs#15291](sveltejs#15291))


- fix: navigate to hash link when base element is present
([sveltejs#15236](sveltejs#15236))


- fix: avoid triggering `handleError` when redirecting in a remote
function ([sveltejs#15222](sveltejs#15222))


- fix: include `test` directory in generated `tsconfig.json` alongside
existing `tests` entry
([sveltejs#15254](sveltejs#15254))


- fix: generate `tsconfig.json` using the value of `kit.files.src`
([sveltejs#15253](sveltejs#15253))

## @sveltejs/adapter-cloudflare@7.2.7

### Patch Changes

- fix: error if `_routes.json` is in the `/static` public directory
([sveltejs#12821](sveltejs#12821))


- fix: correctly handle pathnames found in the `_redirects` file
([sveltejs#12821](sveltejs#12821))

- Updated dependencies
\[[`37293a5`](sveltejs@37293a5),
[`5d05ca6`](sveltejs@5d05ca6),
[`ed69b77`](sveltejs@ed69b77),
[`b1fc959`](sveltejs@b1fc959),
[`159aece`](sveltejs@159aece),
[`c690579`](sveltejs@c690579),
[`dc8cf2d`](sveltejs@dc8cf2d),
[`ace2116`](sveltejs@ace2116),
[`0f38f49`](sveltejs@0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/adapter-node@5.5.3

### Patch Changes

- fix: validate `ORIGIN` env var at startup
([sveltejs#15045](sveltejs#15045))


- chore(deps): update dependency `@rollup/plugin-commonjs` to v29
([sveltejs#14856](sveltejs#14856))

- Updated dependencies
\[[`37293a5`](sveltejs@37293a5),
[`5d05ca6`](sveltejs@5d05ca6),
[`ed69b77`](sveltejs@ed69b77),
[`b1fc959`](sveltejs@b1fc959),
[`159aece`](sveltejs@159aece),
[`c690579`](sveltejs@c690579),
[`dc8cf2d`](sveltejs@dc8cf2d),
[`ace2116`](sveltejs@ace2116),
[`0f38f49`](sveltejs@0f38f49)]:
    -   @sveltejs/kit@2.51.0

## @sveltejs/enhanced-img@0.10.1

### Patch Changes

- fix: replace erroneous `import.meta.DEV` with `import.meta.env.DEV` in
generated code ([sveltejs#15285](sveltejs#15285))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link preload should be in front of inlined CSS

3 participants