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

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

Closed
TigersWay opened this issue Aug 15, 2022 · 10 comments
Labels
bug: --serve restart Changes to projects shouldn’t need to restart dev server bug: windows Issue reported for the Windows environment feature: 🛠 configuration Related to Eleventy’s Configuration file

Comments

@TigersWay
Copy link
Contributor

TigersWay commented Aug 15, 2022

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

@zachleat zachleat self-assigned this Aug 22, 2022
@zachleat
Copy link
Member

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

@zachleat zachleat removed their assignment Aug 22, 2022
@zachleat zachleat added needs-reproduction Having trouble reproducing! Can anyone confirm? on-hold and removed needs-triage labels Aug 22, 2022
@TigersWay
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@lukeliasi
Copy link

Getting the same issue on Linux, think this is related #1052

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

@kentaroi
Copy link
Contributor

kentaroi commented Aug 30, 2022

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.

eleventy/src/Eleventy.js

Lines 665 to 687 in e9ca971

_shouldResetConfig() {
let configFilePaths = this.eleventyConfig.getLocalProjectConfigFiles();
let configFilesChanged = this.watchManager.hasQueuedFiles(configFilePaths);
if (configFilesChanged) {
return true;
}
for (const configFilePath of configFilePaths) {
// Any dependencies of the config file changed
let configFileDependencies =
this.watchTargets.getDependenciesOf(configFilePath);
for (let dep of configFileDependencies) {
if (this.watchManager.hasQueuedFile(dep)) {
// Delete from require cache so that updates to the module are re-required
deleteRequireCache(dep);
return true;
}
}
}
return false;
}

(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));.

addToPendingQueue(path) {
if (path) {
path = TemplatePath.addLeadingDotSlash(path);
this.pendingQueue.push(path);
}
}

@TigersWay
Copy link
Contributor Author

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 😃

@zachleat zachleat added bug: windows Issue reported for the Windows environment feature: 🛠 configuration Related to Eleventy’s Configuration file and removed on-hold needs-reproduction Having trouble reproducing! Can anyone confirm? labels Dec 13, 2022
@zachleat zachleat added this to the Eleventy 2.0.0 milestone Dec 13, 2022
@zachleat
Copy link
Member

I believe this was a dupe of #1312

@druskus20
Copy link

druskus20 commented Dec 26, 2022

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

@zachleat zachleat added the bug: --serve restart Changes to projects shouldn’t need to restart dev server label Jan 27, 2023
@zachleat
Copy link
Member

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

@druskus20
Copy link

Seems to work now, thanks for letting me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: --serve restart Changes to projects shouldn’t need to restart dev server bug: windows Issue reported for the Windows environment feature: 🛠 configuration Related to Eleventy’s Configuration file
Projects
None yet
Development

No branches or pull requests

5 participants