Hey guys,
we are using Meteor + React with the SSR package. When I do multiple request on the same page, the app crashes with the following error message on the server side:
Cannot read properties of null (reading 'useMemo')
The component where I use useMemo looks like this:
function myComponent() {
const value = useMemo(() => { .. some code ..},[location.pathname]);
}
I import useMemo like this:
import {useEffect, useMemo} from 'react';
Does anybody have an idea what could cause the issue? If I remove useMemo, everything works finde. I’ve already checked for multiple React version but only have 1 (18.2.0)? I’m wondering why it works on a single request but fails on multiple requests at once?
// Edit:
I noticed that the issue is caused by another hook which I use to load initial data on the server side, which gets passed to the client.
useRunOnce(() => {
if (Meteor.isServer) {
Meteor.wrapAsync(async (cb) => {
await loadCategory();
cb();
})();
}
});
It seems that a delay causes the issue. I get the same error when I do something like this:
useRunOnce(() => {
if (Meteor.isServer) {
Meteor.wrapAsync(async (cb) => {
setTimeout(() => {cb()},5000);
})();
}
});
So I basically want to block “rendering” on the server side until the initial data has been loaded. Is this an anti-pattern?