Skip to content

Add handleError hook for plugins to respond to the errorMiddleware #3194

@myleshyson

Description

@myleshyson

Clear and concise description of the problem

Currently there doesn't seem to be a dedicated way to hook into compile errors such that you can stop all subsequent hmr updates until it's fixed.

I'm needing to do this because when using something like tailwindcss in JIT mode, since tailwind has it's own watcher, whenever I for example introduce a fatal error to a svelte component, the tailwind watcher will still update the css file, which clears the browser overlay error message immediately after it shows up.

There doesn't seem to be a way to easily enact a middleware right after errorMiddleware fires to stop future hmr updates.

Suggested solution

It would be nice if there was some hook like handleError or something that allowed someone to do respond to errors.

Additional context

RIght now the way I'm doing this is by adding a post middleware in configureServer with the copied code from error.ts, and in that adding a server.hasError = true property which I then respond to in handleHotUpdate like so

 handleHotUpdate (context) {
      if (context.server.hasError) {
        context.server.hasError = false
        return []
      }

      return context.modules
    },

You can see here that with tailwind JIT running (before adding my hotfix), the css file is updated immediately after my svelte file, blowing away the overlay error message in the browser.
Screen Shot 2021-04-28 at 4 02 27 PM

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions