Comments (12)
@kruczy excellent catch, I don't know how I missed this! It'll need something more complicated than deepHook since there could be grandchild components. I'll get a fix out right away.
from preact.
@kruczy Sorry, I must have been tired earlier - you were exactly right, it just needed to be a deepHook()
.
I just released 3.3.0
, which includes this fix (JSFiddle example).
from preact.
Hey @developit, been testing this today and it seems deepHook
is not enough as it only calls one level down, components that are below that do not get the hook fired. maybe deepHook
should be walking the tree all the way down?
from preact.
@kruczy yeah deepHook only handles high-order components. You're seeing grandchild components not unmount?
Component
div
Component - this one?
from preact.
From my observation that would work
but if you create a deeper hierarchy it does not
in my case the tree is 6 components deep I unmount the whole thing at once but unmount hook seems to be called only on the first 2 levels
from preact.
I modified your example to show the problem http://jsfiddle.net/orgkorjc/10/
Notice that C only logs on the first iteration and then does not log mounts or unmounts
from preact.
Perfect, that is immensely useful. Will get a fix out for this ASAP.
from preact.
@kruczy This was possibly the biggest rabbit hole I've encountered since adding support for High-Order components to Preact, but I think I've got it solved.
The solution actually necessitated a slight change in how Preact mounts and re-mounts Components, but I think it's a better long-term approach: components will now own their rendered content. Unmounting a component now retains the most recently rendered snapshot (this.base
) in-tact with the component when reclaimed by the recycler. Previously, unmounting a component would retain the old DOM within the render parent, and diff it against whatever replaced the component (including if that happened to be null
, which would be a recursive recycling op - not very efficient!
With the new semantics for component mount/unmount, the second time you mount a component, it simply diffs against the most recent snapshot. I think this will help with use-cases like routers, where the DOM rendered by different child components of a router is expected to change by somewhere near 100%. It will incur a small overhead when swapping two components that render nearly identical DOM structures, but this can be avoided by serving that use-case using Pure Functions, which always diff against the previous render, even if the component/function is a different reference.
Apologies for the long-winded and perhaps slightly unrelated comment - just useful for my own brain and to document this somewhere! Expect a release soon that fixes your issue.
from preact.
Thanks for support and explanation, always great to have a responsive maintainer 👍
from preact.
@kruczy This is fixed in 4.0.0
(currently released under a beta tag, npm i preact@beta
).
from preact.
thanks, this is fixed: http://jsfiddle.net/z43dp0ok/1/
from preact.
Thanks again for that JSFiddle demo - it's so much easier to diagnose issues with minimal examples. 👍
from preact.
Related Issues (20)
- onFocusIn and onFocusOut events incorrectly set HOT 4
- Cannot read properties of undefined (reading '__m')
- `hydrate` doesn't replace attributes at root replaced node HOT 4
- Unable to use hooks in compiled package
- Compatibility issue: Jest mock works in React / fails in Preact when using ForwardRef in a component HOT 2
- Using useState leads to error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__H') HOT 3
- Render mui cache inside shadow dom leaves style sheets in head and content unstyled HOT 2
- `defaultValue` incorrectly (?) diffed against prerendered HTML
- Preact 10.20 + @mui/x-data-grid v7 causes datagrid to appear multiple times in dev-mode, but not in preview-mode HOT 1
- Performance of unmounting a context provider
- Runtime error when using an external react module HOT 5
- Incorrect namespacing of MathML elements
- `createRoot` uses an unsupported syntax for IE11
- [preact/compat] Difference in how events are processed (floating-ui) HOT 2
- [preact/compat] [Next.js] Uncaught TypeError: (0 , l.use) is not a function HOT 3
- Headless ui issues after 1.7.17 HOT 4
- render() with popover doesn't work HOT 2
- False positive on render loop detection HOT 1
- Rendering just gets slower over time HOT 18
- hate your ukraine banner
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preact.