Skip to content
Source
Sign inSign up
TanStack/router

Early hints emit as=script on rel=modulepreload, producing "preloaded but not used" warnings for every route chunk #8464

OpenAvantimeCRM(GitHub profile, opens in a new tab) opened this issue 2 comments

Which project does this relate to?

Router

Describe the bug

Describe the bug

collectStaticHintsFromManifest in @tanstack/start-server-core hardcodes as: "script" on every script hint, regardless of what rel the manifest helper returned.

getScriptPreloadAttrs in @tanstack/router-core correctly returns no as for the module script format — as is only valid alongside rel=preload, which is the iife branch:

// @tanstack/router-core/dist/esm/manifest.js
function getScriptPreloadAttrs(manifest, link, assetCrossOrigin) {
  const preloadLink = resolveManifestAssetLink(link);
  const crossOrigin = getAssetCrossOrigin(assetCrossOrigin, "script") ?? preloadLink.crossOrigin;
  return {
    ...getManifestScriptFormat(manifest) === "iife"
      ? { rel: "preload", as: "script" }
      : { rel: "modulepreload" },          // ← no `as`, correctly
    href: preloadLink.href,
    ...crossOrigin ? { crossOrigin } : {},
  };
}

But the early-hints caller adds it back unconditionally:

// @tanstack/start-server-core/dist/esm/early-hints.js
const attrs = getScriptPreloadAttrs(manifest, link);
const hint = {
  href: attrs.href,
  rel: attrs.rel,     // "modulepreload" for the module format
  as: "script",       // ← always added, even when rel is modulepreload
};

The emitted Link header is therefore:

</assets/index-abc123.js>; rel=modulepreload; as=script

Per the HTML spec, modulepreload does not take an as attribute — the destination is implied ("script"). Browsers register a preload that the module loader never matches, and warn a few seconds after load.

Steps to reproduce

  1. A TanStack Start app with the default module script format and the Link header enabled.
  2. Load any page and open the console.

Expected behaviour

modulepreload hints are emitted without as, matching what getScriptPreloadAttrs already returns. The hint is honoured and no warning is produced.

Actual behaviour

One warning per route chunk, on every page load. On our app that is 14 lines each load:

The resource https://example.com/assets/index-abc123.js was preloaded using link preload
but not used within a few seconds from the window's load event. Please make sure it wasn't
preloaded for nothing.

Observed in Safari 18. No functional impact — but the console becomes unusable for debugging, which is exactly where you look when something actually breaks.

Suggested fix

Carry as through from the helper instead of hardcoding it:

  const attrs = getScriptPreloadAttrs(manifest, link)
  const hint = {
    href: attrs.href,
    rel: attrs.rel,
-   as: 'script',
  }
+ if (attrs.as !== undefined) hint.as = attrs.as

That keeps the iife path (rel=preload; as=script) unchanged and makes the module path spec-correct. The CSS branch below it is already correct — rel=preload; as=style is valid.

Possible origin

#7327 added the Link header, and #7477 later added the iife/module split in getScriptPreloadAttrs. The as: "script" line in early-hints.ts looks like it predates the split and was not revisited when rel stopped always being preload.

Versions

  • @tanstack/start-server-core — reproduced in 1.167.22 (our deployed version, warnings observed in production) and the same code is present in 1.169.37
  • @tanstack/router-core 1.168.17 / 1.171.32
  • @tanstack/react-start 1.167.50
  • @tanstack/react-router 1.168.25
  • Deployed on Cloudflare via Nitro

Workaround

Stripping as=script from modulepreload entries in the Link response header, in our own server entry wrapper. The hint still works — it just becomes valid.

Complete minimal reproducer

see above

Steps to Reproduce the Bug

see above

Expected behavior

see above

Screenshots or Videos

see above

Platform

Not relevant

Additional context

No response

  1. could not reproduce this warning. IMO the spec does allow as for modulepreload : https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload

    please provide a complete minimal reproducer project

  2. schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed

  3. Closing this from my side — I can't reproduce it either, and you were right about the spec.

    Re-checked in production today: the modulepreload hints are emitted in the HTML only — 21 of them, all rel="modulepreload" with no as — and there is no Link response header on the document at all. No console warning in Chrome. Whatever produced the rel=modulepreload; as=script header I reported in September isn't happening in our setup now @.***/start-server-core 1.169.37, Nitro + Cloudflare).

    One thing I'd still mention, for whatever it's worth: collectStaticHintsFromManifest adds as: "script" unconditionally on top of getScriptPreloadAttrs, which deliberately omits as for the module branch. That's a divergence inside the library rather than a spec violation — feel free to ignore it or split it out.

    Sorry for the noise, and thanks for taking the time.

    /C

    From: Manuel Schiller @.> Date: Thursday, 17 September 2026 at 18:39 To: TanStack/router @.> Cc: CRM @.>; Author @.> Subject: Re: [TanStack/router] Early hints emit as=script on rel=modulepreload, producing "preloaded but not used" warnings for every route chunk (Issue #8464)

    You don't often get email from @.*** Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> [https://avatars.githubusercontent.com/u/6340397?s=20&v=4]schiller-manuel left a comment (TanStack/router#8464)<https://github.com/TanStack/router/issues/8464#issuecomment-5717947545>

    could not reproduce this warning. IMO the spec does allow as for modulepreload : https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload

    please provide a complete minimal reproducer project

    — Reply to this email directly, view it on GitHub<https://github.com/TanStack/router/issues/8464?email_source=notifications&email_token=COIWKCUQCTL5K3SF3FPEN235PQHUZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRG44TINZVGQ22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5717947545>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/COIWKCX3CDNU6EWZMASWKVT5PQHUZAVCNFSNUABFKJSXA33TNF2G64TZHMYTMNJWG4YDGMBZHNEXG43VMU5TKNBYG44TANJXGYY2C5QC>. Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/COIWKCR7YCAZDEJ6WKEDKQ35PQHUZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRG44TINZVGQ22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG> and Android<https://github.com/notifications/mobile/android/COIWKCUPCJN2DV7F7VHXKKL5PQHUZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRG44TINZVGQ22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>. Download it today! You are receiving this because you authored the thread.

Sign in to join this conversation.