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

feat: Allow reloading the page regardless of the modified file path #5

Merged
merged 2 commits into from
Mar 18, 2021

Conversation

ElMassimo
Copy link
Contributor

Description 📖

This pull request closes #4 by adding an always configuration option that forces reload to happen regardless of the modified file paths.

Usage 🚀

import LiveReload from 'vite-plugin-live-reload'

export default defineConfig({
  plugins: [
    LiveReload(['config/routes.rb', 'app/views/**/*'], { always: true, log: true }),

@arnoson
Copy link
Owner

arnoson commented Mar 17, 2021

Thanks for the PR!
Isn't the plugin forcing a full page reload already, regardless of the path? However, I am not familiar with how the Vite client reacts to different paths

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Mar 17, 2021

Normally it would, but it doesn't seem to work for these use cases, probably because these paths are outside of the root.

I'll read the client to see if I can figure out what's going on. Hold on the merge for now 😃

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Mar 17, 2021

It seems that when the modified file is an .html file, Vite's client only reloads the page if the browser is currently in that HTML page.

Unfortunately, that logic does not work when the HTML file is outside the root, because:

const payloadPath = base + payload.path.slice(1)

will never match the URL.

This is why forcing * is necessary for some use cases.

Vite Client
      if (payload.path && payload.path.endsWith('.html')) {
        // if html file is edited, only reload the page if the browser is
        // currently on that page.
        const pagePath = location.pathname
        const payloadPath = base + payload.path.slice(1)
        if (
          pagePath === payloadPath ||
          (pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath)
        ) {
          location.reload()
        }

@arnoson
Copy link
Owner

arnoson commented Mar 17, 2021

Okay, thanks for researching it further! Would you mind changing the name of the option to something more descriptive? For example alwaysReload or forceReload

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Mar 17, 2021

Sounds good, I like alwaysReload.

At the moment I'm traveling, but I'll update the PR later today. Thanks!

Edit: Submitted the change.

@arnoson arnoson merged commit 6d0bc71 into arnoson:main Mar 18, 2021
@ElMassimo ElMassimo deleted the force branch March 18, 2021 14:33
@arnoson
Copy link
Owner

arnoson commented Mar 18, 2021

Thank you! Just published the new version

@ElMassimo
Copy link
Contributor Author

Excellent, thanks!! 😃

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 this pull request may close these issues.

Enhancement: Allow forcing page reload regardless of the modified file path
2 participants