Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset extension matching not consistent between DEV and PREVIEW #4931

Closed
Laavenx opened this issue May 15, 2022 · 6 comments · Fixed by #5047
Closed

Asset extension matching not consistent between DEV and PREVIEW #4931

Laavenx opened this issue May 15, 2022 · 6 comments · Fixed by #5047
Milestone

Comments

@Laavenx
Copy link

Laavenx commented May 15, 2022

Describe the bug

Preview build of sveltekit doesn't match asset paths the same way as dev build.

Reproduction

Put let's say image.PNG inside of static then in index.svelte <img src="/image.png" /> and let's run npm run dev, then run build and preview and the image won't be displayed anymore.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19041
    CPU: (6) x64 Intel(R) Core(TM) i5-8600K CPU @ 3.60GHz
    Memory: 6.21 GB / 15.94 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.8.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (97.0.1072.76)
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.40
    @sveltejs/kit: next => 1.0.0-next.328
    svelte: ^3.44.0 => 3.48.0

Severity

annoyance

Additional Information

No response

@Conduitry
Copy link
Member

I can't reproduce this. It's working fine for me. Please provide a complete clonable repo that reproduces the issue.

@Laavenx
Copy link
Author

Laavenx commented May 15, 2022

All you have to do is rename svelte-welcome.png and webp to svelte-welcome.PNG and WEBP in demo template (build should also throw 404 error). If that doesn't work then its interesting why it works this way on my system.
Screenshot_2

@Conduitry
Copy link
Member

This sounds like a case sensitivity thing. I see you're on Windows and you're requesting the file with a lower case extension and it looks like the file is named with an upper case extension.

@Rich-Harris
Copy link
Member

We should probably enforce correct case at dev time

@Conduitry
Copy link
Member

Do we have the access/control necessary for that? Isn't Vite solely responsible for serving those assets, and we just give it the directory to use?

@Rich-Harris
Copy link
Member

No, we use sirv so that we have more control:

if (fs.existsSync(file) && !fs.statSync(file).isDirectory()) {
req.url = encodeURI(pathname); // don't need query/hash
asset_server(req, res);
return;
}

const asset_server = sirv(config.kit.files.assets, {
dev: true,
etag: true,
maxAge: 0,
extensions: []
});

I don't recall if sirv can enforce the correct case, but we could do it easily enough before handing off to sirv.

@Rich-Harris Rich-Harris added this to the 1.0 milestone May 17, 2022
Rich-Harris added a commit that referenced this issue May 24, 2022
* ensure correct case is used for static assets - closes #4931

* Update packages/kit/test/apps/basics/test/test.js

Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com>

* Update packages/kit/src/core/dev/plugin.js

Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com>

Co-authored-by: Maurício Kishi <mrkishi@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 a pull request may close this issue.

3 participants