sveltejs / vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
MIT License
844 stars 103 forks source link

`onwarn` in `svelte.config.js` does not work with Svelte v4.2.0 #732

Closed thdoan closed 1 year ago

thdoan commented 1 year ago

Describe the bug

I just upgraded from Svelte 3.59.2 to 4.2.0 and noticed a regression issue (since it was the only change)...

This was working as expected in v3.59.2 (warnings suppressed):

import sveltePreprocess from 'svelte-preprocess';

export default {
  preprocess: sveltePreprocess(),
  onwarn: (warning, handler) => {
    if (warning.code.startsWith('a11y-')) {
      return;
    }
    handler(warning);
  },
};

After upgrading to v4.2.0, the code above no longer works and warnings are still shown in VS Code.

Reproduction URL

N/A (vite.new doesn't show warnings)

Reproduction

  1. Add code above to svelte.config.js
  2. Update package.json: "svelte": "^4.2.0",
  3. npm install
  4. Reload VS Code
  5. Edit a .svelte file that would trigger an a11y warning, e.g.: <label tabindex="0" on:click={() => console.log('test')}>Test</label>

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 15.92 GB / 31.95 GB
  Binaries:
    Node: 16.20.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.6 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (116.0.1938.69)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/vite-plugin-svelte: ^2.4.5 => 2.4.5
    svelte: ^3.59.2 => 3.59.2
    vite: ^4.4.9 => 4.4.9
bluwy commented 1 year ago

I can't reproduce this locally. We'd need a repro to investigate further, e.g. a github repo if you can't reproduce on stackblitz.

dominikg commented 1 year ago

see https://github.com/sveltejs/language-tools/issues/2149

vite-plugin-svelte handles onwarn for it's own logging, but it cannot control what the vscode extension does.

thdoan commented 1 year ago

I originally submitted issue in Svelte repo, but they said it might be related to this module, that's why I submitted it here. I managed to set up an environment for you to reproduce the issue. Steps:

  1. Go to https://prod.liveshare.vsengsaas.visualstudio.com/join?2A35FC729177C50139EBE3BBD0DD762947B0
  2. Install Svelte for VS Code extension
  3. There should be no warnings.
  4. Update package.json: "svelte": "^4.2.0",
  5. In terminal: npm install
  6. In VS Code: Ctrl + Shift + P -> "Svelte: Restart Language Server"
  7. ISSUE: You should see a11y warning.

Or grab the code from this repo and do the same steps above: https://github.com/thdoan/svelte-vite-starter

dominikg commented 1 year ago

Your reproduction describes that the warning is shown by vscode. vite-plugin-svelte is not responsible for this.

please stop crossposting

https://github.com/sveltejs/language-tools/issues/2149#issuecomment-1705845910