Render not updating DOM more than once given replacement with differences.
See original GitHub issueScenario:
- SSRing a trivial page (via
preact-render-to-string
in Deno). - A JS script with a single call to
hydrate
theIndex
component is requested, bundled by the server, and served. - The document
body
is hydrated given theIndex
component. - A websocket is opened with the server and when any changes are made to any
tsx
file, it sends a message to the client (browser). - The browser dynamically imports
Index
and therender
function. - The
Index.tsx
file is requested, bundled with preact and with therender
function re-exported from the bundle, and served. - The updated component is rendered to the document
body
.
The above render
works one time. After that it no longer renders anything further. I am verifying that the component it is being supplied does indeed have the changes (minor changes, it doesn’t work with even a single letter change in a string) and matches the exact structure of the currently mounted DOM (because it is the same component) but for some reason the DOM is not updating. If I do the same thing with hydrate
, it does update as many times as it is called, but only updates text nodes, as far as I can tell and does not render any HTML attribute changes. With hydrate
being what it is though, this is not unexpected to me.
I would expect subsequent calls to render
beyond the first to update the DOM tree of body
with the changes made to that tree.
Note that the h
function is made available via import
in the websocket client file. Thus, it is from the same “instance” of preact in all cases. I tried the above with re-exporting h
from the bundle as I do with render
with no luck.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Yes, the options hooks are a singleton tied to the render process.
OMG… that fixed it. I literally just imported
render
along withh
and used it instead of a per-bundle render. Cheers! Thank you so much!