You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Live Reload / DIrty Reload and hidden or temporary files #2519
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 )
Reacted by Oleh Prypin, Michael Kriese, Hanno Rein, liuly, Daniel Besmer, Johnson Sun and Ed
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.
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.
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
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.
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!).
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.
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.
@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?
@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.
Activity
aphive commentedon Jul 22, 2022
What editor are you using? I use Atom and VS Code and have not experienced this issue. Could be a plugin on your editor.
truist commentedon Aug 23, 2022
@osresearch you can try having vim put the swap files somewhere else, as described here
aphive commentedon Dec 27, 2022
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.
pkmnsnfrn commentedon May 23, 2023
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 theservescript. 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.
liuly0322 commentedon Sep 5, 2023
One workaround for vim is config tmp file path or disable them in
.vimrcfile, for example:I'm not sure if #3224 is intended to also deal with this problem, but I try
mkdocs serve --cleanin mkdocs 1.5.2 and it still hot reloads.alexvoss commentedon Oct 31, 2023
I do not think that
exclude_docssolves this since the documentation for it says thatmkdocs servestill 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 makemkdocs servehonor 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 noswapfileto a.vimrcin my MkDocs projects. This turns off the swap file, which is the one that causes all those rebuild operations inmkdocs serve. This way I keep my global.vimrcsmall and cause minimal surprises elsewhere.Note that, by default,
vimpicks up only the.vimrcin thecwd. There are plugins that change this and make the whole thing hierarchical. I usually startvimfrom 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.
oprypin commentedon Oct 31, 2023
oprypin commentedon Oct 31, 2023
alexvoss commentedon Oct 31, 2023
Since a change to make
mkdocs serveignore files listed inexclude_docswould 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 viagitto 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
gitbut 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 jobrriemann commentedon Apr 1, 2024
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.
pawamoy commentedon Apr 17, 2024
This might be solved by the upcoming v1.6 of MkDocs where the
exclude_docssetting now completely excludes files from being processed. Nowadays it's also possible to unwatch files and folders from theon_serveevent, usingserver.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!).smalers commentedon Apr 27, 2024
I am using MkDocs 1.6.0 and I use
vimto edit files in Git Bash window. I startedmkdocs serve. Then I edited a Markdown file, which causes a hidden.swpfile to be created next to the original file. The MkDocs server immediately refreshed. I waited a while. Then I closed the file invimand MkDocs immediately refreshed. I assume that MkDocs is detecting changes in those files. Then I added the following to mymkdocs.yamlfile, even though it might be the default.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_docsis 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.
oprypin commentedon Apr 27, 2024
oprypin commentedon Apr 27, 2024
smalers commentedon Apr 27, 2024
The configuration documentation is confusing: https://www.mkdocs.org/user-guide/configuration/
It mentions
exclude_docsas if it was implemented in 1.5.0 and then removed in 1.6.0. Therefore, it seems to acknowledge the need forexclude_docsbut the use case of excluding hidden files seems to no longer be recognized? Is the functionality ofexclude_docssimply 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.oprypin commentedon Apr 27, 2024
smalers commentedon Apr 27, 2024
@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
vimeditor swap file changes, so basically doubling the refreshes and double the delay?ed2050 commentedon Oct 20, 2025
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.