New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: WeakMap when environments are referenced #3014
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would fix SSR use cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jstejada has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Thanks for that @alunyov, I have made those Also; should we try and implement something that mimic's the |
Thanks for the update!
IMO, we may just keep it as it is right now. They're just a few instances where we are using WeakMap, so - not a huge overhead. And also pulling in the polyfill will most likely conflict with our internal setup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alunyov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Oh sorry, I may have no articulated myself correctly. My bad. I'm not saying we include the polyfill within this repo. Im merely saying, that bundlers, runtimers etc.. That they include the polyfill, if they choose. Much like how react isnt including a polyfill for Map, but rather saying that if IE9 is your target, then you'll need to include a polyfill for Map. What I'm really trying to say is, let this library articulate that we want the behavior of a WeakMap by using it - and simply say that for environments where that isn't directly available, that you have to use polyfill's, by whatever means your setup is like.. So Facebook might use rome, babel, whatever. |
Summary: With this PR I aim to address the situation where environments are removed, but never garbage collected as references are held onto in this Map. A simple case could be: ```js const MyApp = () => { const [environment, setEnvironment] = useState(new Environment({ network, store })); useEffect(() => { setTimeout(() => { setEnvironment(new Environment({ network, store })); }, 1e3); }, []); return (<RelayEnvironmentProvider environment={environment}> <MyComponentTreeWith_A_useFragment/> </RelayEnvironmentProvider>); }; ``` as you'll find from that example, the `dataResources` map will be forever growing, with nothing clearing. fixes: #3013 Pull Request resolved: #3014 Reviewed By: jstejada Differential Revision: D19797050 Pulled By: alunyov fbshipit-source-id: 4ef18e7634c7d50597944967e9ffc0a330ac3633
With this PR I aim to address the situation where environments are removed, but never garbage collected as references are held onto in this Map.
A simple case could be:
as you'll find from that example, the
dataResources
map will be forever growing, with nothing clearing.fixes: #3013