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

Extension continually restarts when running Next.js dev server #149

Open
tommy-mitchell opened this issue Feb 12, 2025 · 3 comments
Open

Comments

@tommy-mitchell
Copy link

tommy-mitchell commented Feb 12, 2025

It seems that the longer I run the Next.js dev server, the slower the xo extension gets (when using codeActionsOnSave, at least). Eventually, the extension crashes on every save:

xo-next-crash.mp4

My configs are:

// settings.json
{
  "xo.enable": true,
  "xo.format.enable": true,
  "xo.overrideSeverity": "warn",
  "xo.debounce": 300,
  "[javascript][javascriptreact][typescript][typescriptreact]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "dprint.dprint",
    "editor.codeActionsOnSave": {
      "source.fixAll.xo": "explicit",
    },
  },
  "files.exclude": {
    "**/.next": true,
  },
}
// xo.config.js
import * as configs from "@tommy-mitchell/eslint-config-xo";

export default [
  { ignores: [".next/**", ".yarn/**"] },
  ...configs.xo,
  ...configs.react,
  ...configs.next,
  ...configs.tailwind,
  ...configs.dprint,
  {
    rules: {
      "n/prefer-global/process": "off",
    },
  },
];

I used DEBUG=* npx xo to confirm that only my files are being linted (e.g. ignores node_modules/, .next/, etc). I'm not sure how further to inspect the extension to see why it's stalling.

@spence-s
Copy link
Collaborator

Hey @tommy-mitchell thanks for the bug report.

This is likely due that we watch certain globs of files that the next js dev process copies while running/changing things.

You can see the files we are watching here and that we restart the extension when they are changed. This is because restarting the extension is the only way to reload some rules when they change. https://github.com/xojs/vscode-linter-xo/blob/master/client/extension.ts#L95

My guess is that you need the watcher to ignore the .next directory as we don't expose an API in the extension to ignore anything.

However, you can set up vscode watcher to NOT signal xo extension when a dir changes with the setting files.watcherExclude.

TL;DR
add your ignored directories to the files.watcherExclude setting. We will work on adding an ignore option directly in the extension soon as this is not an obvious work around. I will leave this issue open in the mean time so its visible to others.

@tommy-mitchell
Copy link
Author

I couldn't seem to get files.watcherExclude to ignore the .next directory, here's what I tried:

// settings.json
"files.watcherExclude": {
  "**/.next/**": true,
},

As a temporary fix I've just removed the workspace.createFileSystemWatcher('**/package.json') line and it seems to have resolved the issue. I don't configure xo via package.json anyway so this should be fine for me for now.


On a related note, it may be helpful to rename dist/server.js to something like dist/xo-server.js to help with visibility in tools like the Process Explorer.

@spence-s
Copy link
Collaborator

So I created a nextjs project to test. I don't really use it myself, and I could NOT reproduce this issue on mac. I did not even need to add anything to files.watcherExclude, it just didn't restart on unrelated tsx file changes for me...

this is my files.watcherExclude

  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/.history/**": true,
    "**/env/**": true,
    "**/node_modules/**": true,
    "**/venv/**": true,
    "env-*": true
  },

I wonder if you are clobbering the defaults when you set just **/.next/**: true?

Anyway, now I am really unsure about this problem for you. If you have some extra time and would be willing, could you see if this problem reproduces on Vscode when you turn all other extensions off and use default settings?

I think you might could create a throw away profile to do this, I honestly am not sure the best way to do it. I just need a way to isolate the problem a little better so we can be sure what's causing it.

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

2 participants