TanStack / TanStack/router

Unnecessary CSS being imported

Open
#4,396 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

When using normal css imports or css modules, css from other routes is requested on the page load

Your Example Website or App

https://codesandbox.io/p/devbox/smoosh-platform-5ws8gt?workspaceId=ws_KBZbFGeuhMkBGc8o1kN3wx

Steps to Reproduce the Bug or Issue

From start basic example:

  1. Add a new css file
  2. Import that file from any route with a normal import, not using ?url
  3. Create a production build (also happens in dev)
  4. Load the home page, here you can see that both css files are requested, and the newly created css file should only be requested in its own page, or on link hover.

Image

this is demostrated in the codesandbox example

Expected behavior

Only the css file being used in that specific route being requested (only in users in this example)

Screenshots or Videos

No response

Platform
  • OS:any
  • Browser: any
  • Version: latest
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Start basic example and reproduce the issue in both development and production builds. Inspect how normal CSS imports from routes become requested when the home page loads, then verify that only the CSS for the active route is requested, with the other route's CSS deferred until its page or link hover.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, typescript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.