question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When .html files are served from public directory, page reload is not working

See original GitHub issue

Describe the bug

When you move index.html to public directory, or if you have any other file there, the changes are not reloaded in browser.

Reproduction

Create example.html file in public directory and run vite, then try to change anything in that file. Server will not refresh.

11:20:51 [vite] page reload public/example.html

If you run the file on public/example.html, it works correctly but then you get this warning, which is correct.

files in the public directory are served at the root path.
Instead of /public/example.html, use /example.html.

Page reload should work in both cases - example.html and public/example.html

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
    Memory: 8.46 GB / 15.96 GB
  Binaries:
    Node: 14.15.5 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.11.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.51)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    vite: ^2.2.3 => 2.2.3

Used package manager: npm

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
CHOYSENcommented, May 15, 2021
0reactions
lubomirblazekczcommented, May 17, 2021

Ok I am propably a comment spammer today, sorry about that, I managed to workaround this as well.

So if anyone wants to workaround this as me, you can watch for changes with plugin api. You can handle reload in public directory with this aswell.

{
    name: 'reload',
    handleHotUpdate({ file, server }) {
        if (file.endsWith('.html')) {
            server.ws.send({
                type: 'full-reload',
                path: '*'
            });
        }
    },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why won't my web browser reflect changes I made on the ...
html file and upload in using the 'Secure File Transfer Client' to my public_html folder. I'd hit refresh, and bingo. I used ssh...
Read more >
After Uploading an Update to My Web Page, It Looks the Same
Save page. First, make sure the page you are uploading is saved on your computer or server. If the page has not been...
Read more >
React Getting Started - W3Schools
Try changing the HTML content and save the file. Notice that the changes are visible immediately after you save the file, you do...
Read more >
Using the Public Folder - Create React App
The public folder contains the HTML file so you can tweak it, for example, to set the page title. The <script> tag with...
Read more >
Browsersync options
Use the built-in static server for basic HTML/JS/CSS websites. // Serve files from the app directory server: "app" // Serve files from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found