Skip to content

Live Reload / DIrty Reload and hidden or temporary files #2519

Open

Description

@osresearch

When using mkdocs serve --livereload or --dirtyreload, mkdocs detects changes to editor temp files like .foo.md.swp or hidden files like .foo and constantly regenerates the documentation. I tried adding the mkdocs-exclude plugin to ignore the glob .*.swp, but this does not stop the live reload from executing.

It seems like mkdocs shouldn't be scanning dot files anyway since these files aren't included in the output. This would produce less noise on the console and fewer browser page re-loads when editing the Markdown files with vi and using the live reload / dirty reload functions.

(although it would be nice to be able to include the .well-known/ directory or have a way to specify which dot files to be included, which I guess is still waiting for a design decision in #2139 )

Activity

  1. aphive commented on Jul 22, 2022

    @aphive

    What editor are you using? I use Atom and VS Code and have not experienced this issue. Could be a plugin on your editor.

  2. truist commented on Aug 23, 2022

    @truist

    @osresearch you can try having vim put the swap files somewhere else, as described here

  3. aphive commented on Dec 27, 2022

    @aphive

    Have you tried starting in a fresh directory? I would suggest using a virtual environment just in case something's off with your setup.

    I had an issue with a plug-in once making it into mkdoks setup when it was for something totally different.

    Just a suggestion.

  4. pkmnsnfrn commented on May 23, 2023

    @pkmnsnfrn

    I am having a similar problem but I wasn't sure if I should open a separate issue.

    I'm on Windows 10.

    When I open a file or directory in my docs/ folder using vim (via WSL), Typora, Sublime Text, or even Notepad, live reload will consistently refresh until I kill the serve script. Interestingly enough, I don't have this problem at all on OSX.

    Any ideas on what the issue could be?

    EDIT: I didn't mention that I moved my swapfiles elsewhere and still had this problem.

  5. liuly0322 commented on Sep 5, 2023

    @liuly0322

    One workaround for vim is config tmp file path or disable them in .vimrc file, for example:

    set backupdir=/tmp,.
    set directory=/tmp,.

    I'm not sure if #3224 is intended to also deal with this problem, but I try mkdocs serve --clean in mkdocs 1.5.2 and it still hot reloads.

  6. alexvoss commented on Oct 31, 2023

    @alexvoss

    I do not think that exclude_docs solves this since the documentation for it says that mkdocs serve still serves up the files, with a note that they are a draft. Drafts are clearly the use case here. Now, the setting already has a way to negate a filespec, perhaps it could gain one to declare it important to make mkdocs serve honor it? Since the exclamation mark is taken, I would suggest - hm - perhaps an ampersand? Would this be sufficiently unlikely to start a filename (like !)?

    In the meantime, I add set noswapfile to a .vimrc in my MkDocs projects. This turns off the swap file, which is the one that causes all those rebuild operations in mkdocs serve. This way I keep my global .vimrc small and cause minimal surprises elsewhere.

    Note that, by default, vim picks up only the .vimrc in the cwd. There are plugins that change this and make the whole thing hierarchical. I usually start vim from the main project directory anyway, so I don`t need this.

    This solves the issue for me but at the cost of edits being lost on a crash. Vim these day hardly ever crashes and neither does MacOS (touch wood), so the swap file is mainly ensuring against user error.

  7. oprypin commented on Oct 31, 2023

    @oprypin
  8. oprypin commented on Oct 31, 2023

    @oprypin
  9. alexvoss commented on Oct 31, 2023

    @alexvoss

    Since a change to make mkdocs serve ignore files listed in exclude_docs would only affect the writing process and not any build product, do you think it would be possible to change this? Drafts are already supported for anyone going via git to publish - just don't commit them or do so in a branch.

    I do think it is important to enable people to use MkDocs even if they are writers not familiar with coding tools like git but there might be better ways of doing this? One idea might be to use page metadata in the header - like in the blog plugin of Materials for MkDocs? IMHO using metadata is better in any case than using a scheme based on filenames. It would not need any changes to MkDocs itself if this plugin does the job

  10. rriemann commented on Apr 1, 2024

    @rriemann

    I have the same problem when editing with the KDE Kate editor. *.kate-swp files lead apparently to a reload if I only press one character. Very annoying.

  11. pawamoy commented on Apr 17, 2024

    @pawamoy
    Contributor

    This might be solved by the upcoming v1.6 of MkDocs where the exclude_docs setting now completely excludes files from being processed. Nowadays it's also possible to unwatch files and folders from the on_serve event, using server.unwatch(...). I'll try to run some experiments to confirm that this can be closed (please do the same if you're interested in this!).

  12. smalers commented on Apr 27, 2024

    @smalers

    I am using MkDocs 1.6.0 and I use vim to edit files in Git Bash window. I started mkdocs serve. Then I edited a Markdown file, which causes a hidden .swp file to be created next to the original file. The MkDocs server immediately refreshed. I waited a while. Then I closed the file in vim and MkDocs immediately refreshed. I assume that MkDocs is detecting changes in those files. Then I added the following to my mkdocs.yaml file, even though it might be the default.

    # ------------------------------------------------
    # Exclude files from being processed.
    exclude_docs: |
      .*
    

    However, the 1.6.0 documentation contains the following, which is confusing to me. I see how things can be added in drafts, but now it seems that exclude_docs is not recognized anymore? How do I exclude temporary editor files that cause extra refreshes?


    Changed in version 1.6:

    This config no longer applies the "drafts" functionality for mkdocs serve. If you have draft documents that you want available in "serve" and not "build", replace exclude_docs with the new draft_docs config option.


  13. oprypin commented on Apr 27, 2024

    @oprypin
  14. oprypin commented on Apr 27, 2024

    @oprypin
  15. smalers commented on Apr 27, 2024

    @smalers

    The configuration documentation is confusing: https://www.mkdocs.org/user-guide/configuration/

    It mentions exclude_docs as if it was implemented in 1.5.0 and then removed in 1.6.0. Therefore, it seems to acknowledge the need for exclude_docs but the use case of excluding hidden files seems to no longer be recognized? Is the functionality of exclude_docs simply not available anymore and if so will it be added in the future? I have some MkDocs sites that are very large and every extra refresh due to editor temporary files causes inefficiencies.

  16. oprypin commented on Apr 27, 2024

    @oprypin
  17. smalers commented on Apr 27, 2024

    @smalers

    @oprypin OK. Thanks for responding. I understand now that there is a difference between the watch software and what files it cares about, and the files that MkDocs compares about. I did not think about the disconnect between the two and I can see how that might be difficult to resolve. It might be worthwhile to explain this a bit in the documentation given that the MkDocs configuration keeps getting more advanced and it may not be obvious. I will wait to see if something changes in a later release. BTW, I use MkDocs on some huge documents. Here is an example with many hundreds of files. Hence, my hope is that fewer watch refreshes can occur. I assume that MkDocs is responding to my legitimate file saves, but also extra vim editor swap file changes, so basically doubling the refreshes and double the delay?

  18. ed2050 commented on Oct 20, 2025

    @ed2050

    @osresearch you can try having vim put the swap files somewhere else, as described here

    changing your editor behavior for one misbehaving tool is not a good solution. there are good reasons for keeping swap files in same dir as source. vi/vim has done this since time immemorial. vim is not the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions