Comments (2)
Huh, interesting, thanks for reporting this @paulsohn!
it looks like when OutPortal node2 is absent, the detached node2 has been garbage collected and previous timestamp is gone forever.
I don't think that's correct. This is showing that React is doing a re-render for this component, but that doesn't mean the DOM nodes are otherwise affected, they're relatively independent processes. You can see that the DOM nodes aren't garbage collected when removing from the page by testing something where the DOM itself has state (rather than React), e.g. remove and re-add a playing <video>
element or a form containing input.
That doesn't help though, because I'm not sure why React is re-rendering to update the value here! That suggests that it thinks the props for this MemoBox
have been updated during this process for some reason... Any ideas?
I think that React.memo()
is only a shallow comparison over all props, so I suspect this is happening because of some prop update we're doing that means that a prop has a top-level change (e.g. a cloned array or object) even though the internal values haven't changed. Not sure where exactly though.
You might be able to find out more digging into this with the React devtools, which will tell you exactly why each component re-renders.
If the above is correct, you can also probably fix it by passing a 2nd argument to React.memo()
, to define exactly what you're memoizing against. In this case, instead of a shallow comparison of all props, what you really want is something like (oldProps, newProps) => oldProps.txt === newProps.txt
(i.e. props only count as different if txt
changes). If you test that, do let me know if it works, that'd be a strong sign that some props equivalent-but-not-technically-equal update is the cause.
from react-reverse-portal.
Thanks for your comment!
Hotfixing with export const MemoBox = memo(Box, isEqual)
didn't helped me though - the props are already shallow enough.
BTW I'm currently working with my toy project using this awesome package and need to implement this kind of pattern - and that project doesn't suffer from this issue. This makes me more curious than ever... hopefully I can get back after I figured out what's the difference.
from react-reverse-portal.
Related Issues (20)
- iframes reload from source HOT 6
- Race condition when swapping nodes between <OutPortal/>s HOT 5
- Any way to prevent unmounting of the portal contents when changing portals that aren't located within the same component? HOT 2
- Child components are re-rendered when switching their OutPortal HOT 1
- How to Create Multiple InPortals HOT 1
- Not rendering before an outPortal is used HOT 2
- Unhandled Rejection (NotFoundError): Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node. HOT 9
- Giving style to intermediary div HOT 3
- How to *destroy* a portal? HOT 3
- Migrate from Travis to Github Actions? HOT 1
- Rendering portal in a new window causes error: "html" portalNodes must be used with html elements, but OutPortal is within DIV HOT 1
- Nextjs error HOT 1
- Queries around library usage HOT 1
- Doesn't work when there is nested `portals.OutPoral` HOT 6
- moving OutPortal doesn't cause unmount/mount, but *does* cause re-render HOT 2
- Props stay the same when InPortal content is hidden HOT 3
- Text field autoFocus doesn't work in a portal HOT 1
- Scroll position doesn't maintain HOT 2
- Support for Preact HOT 1
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 react-reverse-portal.