Dodgy HMR notifications
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 279
- PR merge metrics
- No merged PRs in 30d
Description
Using the vite-plugin-vue-dev-tools package in vite (all latest, at time of writing), I often see log spam in the console, like:
Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
parse https://localhost:8888/__devtools__/assets/index-BSzMGd0T.js line 154 > srcScript:23
on https://localhost:8888/__devtools__/assets/index-BSzMGd0T.js line 154 > srcScript:23
notifyListeners https://localhost:8888/@vite/client:154
notifyListeners https://localhost:8888/@vite/client:154
handleMessage https://localhost:8888/@vite/client:862
createHMRHandler https://localhost:8888/@vite/client:458
dequeue https://localhost:8888/@vite/client:480
enqueue https://localhost:8888/@vite/client:472
enqueue https://localhost:8888/@vite/client:466
createHMRHandler https://localhost:8888/@vite/client:458
onMessage https://localhost:8888/@vite/client:305
connect https://localhost:8888/@vite/client:413
connect https://localhost:8888/@vite/client:412
connect https://localhost:8888/@vite/client:751
connect https://localhost:8888/@vite/client:289
connect https://localhost:8888/@vite/client:373
<anonymous> https://localhost:8888/@vite/client:823
index-BSzMGd0T.js line 154 > srcScript:23:58828
turns out, sometimes the HMR client is being called with no data for notifyListeners (vite/client/dist/client.mjs). Sometimes this seems to get into a tight loop, spamming hundreds of console errors over the course of a second or two, and continually rising.
Right now, I've worked around it with an automated patch applied before starting up vite that modifies the notifyListeners method from:
async notifyListeners(event, data) {
const cbs = this.customListenersMap.get(event);
if (cbs) await Promise.allSettled(cbs.map((cb) => cb(data)));
}
to
async notifyListeners(event, data) {
if (!data) { return; }
const cbs = this.customListenersMap.get(event);
if (cbs) await Promise.allSettled(cbs.map((cb) => cb(data)));
}
because the call will definitely fail when data is undefined (the value I'm seeing come through). I believe this is coming from the embedded vite-plugin-vue-devtools because I can trigger it by navigating about in the overlay that the button shows when clicked - simply changing which sub-view is used from the navigation buttons highlighted below will be enough to (on one or more of them) trigger the issue:
The overall effect, when not patched, is sometimes just annoying log spam, but quite often, when getting into a loop, degraded performance in the browser, which I can only stop by fully reloading the page.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with vite/client/dist/client.mjs, especially notifyListeners, and reproduce the issue by navigating between views in the vite-plugin-vue-dev-tools overlay. Trace which HMR notification supplies no data and verify the fix by confirming that navigation no longer causes JSON.parse errors, console spam, or a performance-degrading loop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- devtools, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100