vite-plugin-inspect icon indicating copy to clipboard operation
vite-plugin-inspect copied to clipboard

fix: remove unnecessary `load` hook

Open younggglcy opened this issue 1 year ago • 0 comments

Description

IMHO, the load hook of the plugin is not necessary at all.

Let's take a glance at the logic of hijackHood(plugin, 'load').

  1. first we execute hooks to get the result
  2. check whether it's valid
  3. if it's valid, then put in into the map, which refers transformMap or transformMapSSR.

So we add the correct result into the map in step 3. However, the load hook of vite-plugin-inspect is executed first in step 1, and there is no corresponding result in the map at this time, because the correct result is obtained by calling the load hooks of other plugins.

I added some console.logs to the hook and tested it in /playground, the result could prove too.

    load: {
      order: 'pre',
      handler(id, { ssr } = {}) {
        const map = ssr ? transformMapSSR : transformMap
        console.log(id in map)
        delete map[id]
        return null
      },
    },

image

Linked Issues

None

Additional context

None

younggglcy avatar Sep 23 '22 08:09 younggglcy