preactjs / prefresh

Hot Module Reloading for Preact

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hot reloading doesn't work, the application is always fully reloading.

antran22 opened this issue · comments

Description

Hot reloading doesn't work, the application is always fully reloading even on minor changes.

Reproduction setup

Bundler: Webpack

The setup is a bit complex, we want to develop Preact components over a pre-existing backend. The Preact component is wrapped into a custom component using preact-custom-element, then injected into the backend as plain HTML.

After investigating, we found the error by patching

self.location.reload();
to print an error before issuing a full reload. This gives us the following error message.

TypeError: can't access property "__P", vnode.__c is null
    replaceComponent index.js:57
    ...

The faulty line:

if (!vnode.__c.__P) return;

Analysis: this is an unsafe deep access. Patching to if (!vnode.__c || !vnode.__c.__P) return; keeps the error from throwing, and allow the hot reload process to continue.

I have not fully understood the full cause of why vnode.__c is null, however by patching this I managed to get hot reloading working.

A PR with this patch is created #514