Skip to content

Adapter-static not applying CSS on index page #9404

@universallyleo

Description

@universallyleo

Describe the bug

This is what I expect:
image

But when I upload it to Github pages, the index page has no CSS applied to it:
image

The strange thing is that CSS get applies correctly on other pages, only the index page (i.e. from src/+page.svelte) has this problem. Even stranger is if I click a link to go to another page, and then click a link coming back to the index page, the CSS will be applied! You can see this on my demo pages. Can anyone explains why this is happening?

The build produce no error of course. It is the final result that is the problem.

There was no such problem before on my old project (built around the time when SvelteKit1.0 comes out). But when I update my npm packages everything breaks. So I start afresh and checked that I really doesn't show the way I expect. If any of my steps is wrong, perhaps some clarification in the documentation will be very helpful. Perhaps some clarification on the correct steps to how to update the svelte packages in the documentation will be helpful too.

Reproduction

Link to the repo containing the demo.

This is how I come to it:

  1. npm create svelte@latest testapp
  2. npm install
  3. npm i @sveltejs/adapter-static
  4. change svelte.config.js as follows
import adapter from "@sveltejs/adapter-static";

const dev = process.argv.includes("dev");

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
        // If your environment is not supported or you settled on a specific environment, switch out the adapter.
        // See https://kit.svelte.dev/docs/adapters for more information about adapters.
        adapter: adapter({
            pages: "docs",
            assets: "docs",
        }),
        paths: {
            base: dev ? "" : "/testapp",
        },
    },
};

export default config;
  1. Add export const prerender=true to +layout.js
  2. Add +layout.svelte and style it (this is where the CSS are set).
  3. Add another page about/+page.svelte to demonstrate that the CSS get applies correctly on the non-index page
  4. Add a blank .nojekyll to static folder
  5. npm run dev checked it is producing the result I wanted
  6. npm run build to built to docs folder
  7. Upload to repo to Github and have Github Page points to docs
    image
  8. Check result on Github pages

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 2.93 GB / 15.81 GB
  Binaries:
    Node: 18.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.4.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 111.0.5563.64
    Edge: Spartan (44.19041.1266.0), Chromium (110.0.1587.63)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.0
    @sveltejs/adapter-static: ^2.0.1 => 2.0.1
    @sveltejs/kit: ^1.5.0 => 1.11.0
    svelte: ^3.54.0 => 3.56.0
    vite: ^4.0.0 => 4.1.4

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions