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

Bug: File watcher / live reload not working when a flake.nix created symlink is present #1641

Open
thilobillerbeck opened this issue Jan 28, 2025 · 5 comments
Assignees

Comments

@thilobillerbeck
Copy link
Collaborator

thilobillerbeck commented Jan 28, 2025

As some already may noticed, live reloading for the NixOS homepage broke when using the development environment provided by our nix flake. After some debugging, I figured out what causes this degradation. It seems to be caused by the presence of symlinks provided by the nix flake.

To make this bug reproducible, I set up the reproduce-symlink-bug branch that provides an environment to easily reproduce the bug.

git clone --branch reproduce-symlink-bug https://github.com/NixOS/nixos-homepage.git

After cloning, entering the flake with the inputsFrom = [ config.pre-commit.devShell ]; line commented out will result in an environment where live reload works perfectly. After uncommenting, the presence of the then generated .pre-commit-config.yaml symlink now breaks live reloading. Commenting out and deleting the symlink again returns the environment to its normal function.

This seems to be an Astro related bug, since I cannot reproduce it with either a blank Vite project nor with a blank script using chokidar, the file watching library used by Vite.

@djacu
Copy link
Member

djacu commented Feb 4, 2025

I found I could reproduce this behavior on the main branch.

nix develop
npm install
npm prebuild
npm run astro dev

This creates the the .pre-commit-config.yaml as well as the 3 result-* symlinks. Changes to to the home page do not reload the page and it does not appear that astro is aware of file changes.

Exit the astro dev environment and delete the 4 symlinks and then re-running npm run astro dev. Now changes to the home page results in the page reloading and the changes showing up on the home page.

@djacu
Copy link
Member

djacu commented Feb 4, 2025

I've also noticed something strange. Certain files do trigger a reload.

  • Changes will cause a reload
    package.json
    tailwind.config.cjs
    tsconfig.json
    astro.config.mjs

  • Changes will not cause a reload
    flake.nix
    src/pages/index.astro
    default.nix
    .prettierrc.mjs

*Note: I didn't go back and retest all these files but at least for astro.config.mjs, just saving the file, even if there are no changes, will cause the site to reload and show changes made in astro files.

@djacu
Copy link
Member

djacu commented Feb 4, 2025

Tried adding this to the astro.config.mjs based on this thread. Didn't help :/

diff --git a/astro.config.mjs b/astro.config.mjs
index e62355357..ab8c5b880 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -35,4 +35,17 @@ export default defineConfig({
     },
   },
   compressHTML: true,
-});
\ No newline at end of file
+  vite: {
+    server: {
+      watch: {
+        ignored: [
+          '**/result-demos',
+          '**/result-manuals',
+          '**/result-pills', 
+          '**/.pre-commit-config.yaml',
+        ],
+        alwaysStat: true,
+      },
+    },
+  },
+});

@djacu
Copy link
Member

djacu commented Feb 4, 2025

Also tried adding these to the vite.server.watch object but still nothing.

+        alwaysStat: true,
+        followSymlinks: false,

@djacu
Copy link
Member

djacu commented Feb 4, 2025

I wanted to check that the configuration mentioned above actually does something and I believe I have verified that it does after the symlinks are deleted. I deleted the symlinks and added src/pages/learn.astro to the files to be ignored by chokidar. After restarting astro, I modified the following files.

  • src/pages/index.astro - triggers a reload
  • src/pages/learn.astro - does not reload
  • src/pages/blog.astro - triggers a reload

I think this confirms that the settings do work. However, the symlinks are still causing issues for some reason.

diff --git a/astro.config.mjs b/astro.config.mjs
index e62355357..404e81730 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -35,4 +35,19 @@ export default defineConfig({
     },
   },
   compressHTML: true,
-});
\ No newline at end of file
+  vite: {
+    server: {
+      watch: {
+        ignored: [
+          '**/result-demos',
+          '**/result-manuals',
+          '**/result-pills', 
+          '**/.pre-commit-config.yaml',
+          '**/src/pages/learn.astro',
+        ],
+        alwaysStat: true,
+        followSymlinks: false,
+      },
+    },
+  },
+});

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

No branches or pull requests

3 participants