{"id":"de3f53d34b6f67aa","repo":"vitejs/vite","slug":"invalid-hot-accept-usage","errorCode":null,"errorMessage":"invalid hot.accept() usage.","messagePattern":"invalid hot\\.accept\\(\\) usage\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/shared/hmr.ts","lineNumber":74,"sourceCode":"    this.newListeners = new Map()\n    hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners)\n  }\n\n  get data(): any {\n    return this.hmrClient.dataMap.get(this.ownerPath)\n  }\n\n  accept(deps?: any, callback?: any): void {\n    if (typeof deps === 'function' || !deps) {\n      // self-accept: hot.accept(() => {})\n      this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod))\n    } else if (typeof deps === 'string') {\n      // explicit deps\n      this.acceptDeps([deps], ([mod]) => callback?.(mod))\n    } else if (Array.isArray(deps)) {\n      this.acceptDeps(deps, callback)\n    } else {\n      throw new Error(`invalid hot.accept() usage.`)\n    }\n  }\n\n  // export names (first arg) are irrelevant on the client side, they're\n  // extracted in the server for propagation\n  acceptExports(\n    _: string | readonly string[],\n    callback?: (data: any) => void,\n  ): void {\n    this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod))\n  }\n\n  dispose(cb: (data: any) => void): void {\n    this.hmrClient.disposeMap.set(this.ownerPath, cb)\n  }\n\n  prune(cb: (data: any) => void): void {\n    this.hmrClient.pruneMap.set(this.ownerPath, cb)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/shared/hmr.ts#L56-L92","documentation":"Vite's HMR client accept() method accepts exactly three valid shapes: no deps / a function (self-accept), a string dep with a callback, or an array of string deps with a callback. If the deps argument is none of these (e.g. a number, an object, or an array containing non-strings), the final else branch throws to signal malformed usage. This protects the HMR dependency graph from invalid registrations.","triggerScenarios":"Calling import.meta.hot.accept() with a first argument that is not undefined, not a function, not a string, and not an array of strings — for example hot.accept({}), hot.accept(123), or hot.accept([{ foo: 1 }]). Triggered at runtime in the browser/module-runner when the HMR context evaluates the accept call.","commonSituations":"Dynamically constructing the deps argument to hot.accept and passing a wrong type due to a bug. Misunderstanding the API and passing an object instead of an array. Tooling or codemods that rewrite HMR calls incorrectly. Spread/rest mistakes that pass an object where an array is expected.","solutions":["Use one of the documented forms: hot.accept(), hot.accept(() => {}), hot.accept('./dep', cb), or hot.accept(['./a','./b'], cb).","If building deps dynamically, ensure the variable is always undefined, a string, or string[] before calling accept.","Check the browser console for the exact call site and fix the argument type at that location."],"exampleFix":"// before — passing an object\nimport.meta.hot.accept({ './dep': handler })\n\n// after — pass a string/array with a callback\nimport.meta.hot.accept(['./dep'], ([dep]) => handler(dep))","handlingStrategy":"validation","validationCode":"// Validate the deps argument shape before calling accept\nfunction isValidAcceptDeps(deps: unknown): boolean {\n  return (\n    deps == null ||\n    typeof deps === 'function' ||\n    typeof deps === 'string' ||\n    (Array.isArray(deps) && deps.every((d) => typeof d === 'string'))\n  )\n}\n\nif (import.meta.hot && isValidAcceptDeps(myDeps)) {\n  import.meta.hot.accept(myDeps as any, cb)\n}","typeGuard":"function isAcceptDeps(deps: unknown): deps is undefined | string | string[] {\n  return (\n    deps == null ||\n    typeof deps === 'string' ||\n    (Array.isArray(deps) && deps.every((d) => typeof d === 'string'))\n  )\n}","tryCatchPattern":null,"preventionTips":["Always use one of the documented accept() signatures.","When constructing deps dynamically, coerce to a string[] and validate before calling.","Avoid passing objects or numbers as the first argument to hot.accept."],"tags":["hmr","client","api-usage"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}