Open BJTerry opened 5 years ago
I've created a reproduction of the issue here:
https://github.com/BJTerry/relay-examples
todo
yarn install
yarn build
yarn update-schema
yarn start
Delete entry
. Click that button. You should see an error in the console like this:
TodoList.js:77 Uncaught TypeError: Cannot read property 'edges' of undefined
at TodoList.renderTodos (TodoList.js:77)
at TodoList.render (TodoList.js:101)
at finishClassComponent (react-dom.development.js:13393)
at updateClassComponent (react-dom.development.js:13356)
at beginWork (react-dom.development.js:13945)
at performUnitOfWork (react-dom.development.js:16249)
at workLoop (react-dom.development.js:16287)
at HTMLUnknownElement.callCallback (react-dom.development.js:145)
at Object.invokeGuardedCallbackDev (react-dom.development.js:195)
at invokeGuardedCallback (react-dom.development.js:248)
react-dom.development.js:14389 The above error occurred in the <TodoList> component:
in TodoList (created by ContainerConstructor)
in ContainerConstructor (created by ForwardRef(Relay(TodoList)))
in section (created by TodoApp)
in div (created by TodoApp)
in TodoApp (created by ContainerConstructor)
in ContainerConstructor (created by ForwardRef(Relay(TodoApp)))
in ReactRelayQueryRenderer (created by App)
in div (created by App)
in App
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
And the entire page crashes. I've created a video of the reproduction here: https://cl.ly/cdab28ee298f
cc @jstejada
Thanks for reporting this! As a workaround note that GC can be disabled with environment.getStore().__disableGC()
.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If you include two
QueryRenderer
s on a page that have the same query, and then you remove one, it deletes the store data associated with the component becausefetchQueryAndComputeStateFromProps
inReactRelayQueryRenderer.jsx
doesn't properly handle duplicate requests from different components.When
fetchQueryAndComputeStateFromProps
is called the first time, it callsfetch
inReactRelayQueryFetcher
, which then callsexecute
. After the environment executes, eventuallyenvironment.retain
is called inReactRelayQueryFetcher.execute
, which retains the returned data in theRelayMarkSweepStore
(assuming you are using the normal store setup). The second timefetchQueryAndComputeStateFromProps
is called it does not callexecute
because the query matches an in-flight request. Therefore, the data is not retained a second time in theRelayMarkSweepStore
. When you unmount either component, itdispose
s the selector inRelayMarkSweepStore
, which performs agc
, deleting the data for all remaining components.I attempted to create a repro of this, but the glitch site linked in the Issues description is extremely out of date and doesn't support Relay Modern. The above was determined using Relay 1.7.0.