eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Config file (.eleventy.js) dependencies in watch/serve mode are found but not reloaded

Open TigersWay opened this issue 2 years ago • 5 comments

Describe the bug It seems that any change over .eleventy.js dependencies - like filters, shortcodes, etc - is detected but not reloaded. The change is not applied.

To Reproduce With this kind of line: eleventyConfig.addFilter('outside_filter', require('./site/filters.js').outside_filter);, any change to the file while running in watch/serve mode, will be logged: [11ty] File changed: site\filters.js as expected. But the old code is "still cached".

repo

TigersWay avatar Aug 15 '22 02:08 TigersWay

HMM, your test case works for me on Mac OS Monterey. Can anyone else confirm? Are you on Windows?

zachleat avatar Aug 22 '22 15:08 zachleat

Was on Windows 10 last time. Now on Windows 11 with the exact same result! The change is logged but the modification is not there (cache maybe?).

TigersWay avatar Aug 22 '22 20:08 TigersWay

Just in case.... I'm usually working with VSCode with the terminal set as "Git bash", and script-shell=C:\Program Files\git\bin\bash.exe in .npmrc. I'm also using pnpm not npm.

I tried all the possible combinations I could imagine down to bare "windows cmd" and npm for the exact same result: Both changes to index.md or filter.js are detected, only the index.md ones are served in the same run.

TigersWay avatar Aug 22 '22 23:08 TigersWay

Getting the same issue on Linux, think this is related https://github.com/11ty/eleventy/issues/1052

The fix for this will ship with 2.0.0-canary.11

lukeliasi avatar Aug 28 '22 00:08 lukeliasi

The cause of this bug is that file paths in EleventyWatch are platform-dependent style and those in the other parts of Eleventy, in this case EleventyWatchTargets, are posix style.

This inconsistency makes this.watchManager.hasQueuedFile(dep) returns always false on Windows (Eleventy.js#L677), which makes _shouldResetConfig() return false. https://github.com/11ty/eleventy/blob/e9ca971210fa06efd2af3a7931ef368dcb085a79/src/Eleventy.js#L665-L687

(this.watchManager.activeQueue is [ "./site\\filters.js"] on Windows, but dep is "./site/filters.js" at Eleventy.js#L677, when you change ./site/filters.js in the provided project.)

I wonder if the platform-dependent style of paths in EleventyWatch is intentional or not.

If it is intentional this should be fixed in hasQueuedFile() in EleventyWatch, for example.

However, if the platform-dependent style of paths in EleventyWatch is a mistake, it will be fixed in addToPendingQueue() in EleventyWatch by replacing path = TemplatePath.addLeadingDotSlash(path); with path = TemplatePath.addLeadingDotSlash(TemplatePath.normalize(path));. https://github.com/11ty/eleventy/blob/e9ca971210fa06efd2af3a7931ef368dcb085a79/src/EleventyWatch.js#L97-L102

kentaroi avatar Aug 30 '22 12:08 kentaroi

Just did a quick test hoping one/some of the last commits would have solved the problem.... It did!!!

Can anyone else confirm? I would love to close this 😃

TigersWay avatar Dec 13 '22 00:12 TigersWay

I believe this was a dupe of #1312

zachleat avatar Dec 13 '22 23:12 zachleat

I believe I still have this issue. I add all my shortcodes in a loop as follows:

.eleventy.js

config.addWatchTarget('./_includes/shortcodes/*.js');
const shortcode_files = require("fs").readdirSync("./_includes/shortcodes");
for (const file of shortcode_files) {
  const shortcode = require(`./_includes/shortcodes/${file}`);
  config.addShortcode(shortcode.name, shortcode.function);
}

_includes/shortcodes/myshortcode.js

module.exports = {
    name: "myshortcode",
    function: myshortcode,
};

function myshortcode() {
    return "MYSHORTCODE"
}

My eleventy version is 2.0.0-canary.23. I must add that I am running Windows 10, I will try tomorrow from Linux

Basically, I have to stop eleventy serve and re-run the whole thing for it to update the website

druskus20 avatar Dec 26 '22 01:12 druskus20

@druskus20 2.0.0-beta.2 has some additional fixes for config reloads, please retest! Via #2773

zachleat avatar Jan 27 '23 14:01 zachleat

Seems to work now, thanks for letting me know!

druskus20 avatar Jan 27 '23 15:01 druskus20