For some days now, my app is breaking. I first get
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
- Error
, followed by:
Uncaught TypeError: Cannot read property 'suppressHydrationWarning' of null
Here is my ssr:
import React from 'react';
import { ApolloClient, ApolloProvider, createHttpLink } from '@apollo/client';
import { renderToStringWithData, getDataFromTree } from '@apollo/client/react/ssr';
import 'isomorphic-fetch';
import { Meteor } from 'meteor/meteor';
import { onPageLoad, Sink } from 'meteor/server-render';
import { Helmet } from 'react-helmet';
import { StaticRouter } from 'react-router';
import checkIfBlacklisted from '@/modules/server/checkIfBlacklisted';
import InMCache from '@/modules/cache';
import App from '@/ui/layouts/App';
onPageLoad(async (sink: Sink) => {
const apolloClient = new ApolloClient({
ssrMode: true,
link: createHttpLink({
uri: Meteor.settings.public.graphQL.httpUri,
}),
cache: InMCache, // : new InMemoryCache(),
});
const app = (
<ApolloProvider client={apolloClient}>
<StaticRouter location={sink.request?.url} context={{}}>
<App />
</StaticRouter>
</ApolloProvider>
);
const content = await renderToStringWithData(app);
const initialState = apolloClient.extract();
const helmet = Helmet.renderStatic();
sink.appendToHead(helmet.meta.toString());
sink.appendToHead(helmet.title.toString());
sink.renderIntoElementById('react-root', content);
sink.appendToBody(`
<script>
window.__APOLLO_STATE__ = ${JSON.stringify(initialState).replace(/</g, '\\u003c')}
</script>
`);
});
Client:
import React from 'react';
import { ApolloProvider } from '@apollo/client';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { hydrate, render } from 'react-dom';
import { BrowserRouter, Switch } from 'react-router-dom';
import '@/modules/whiteList';
import App from '@/ui/layouts/App';
import apolloClient from './apollo';
Accounts.onLogout(() => apolloClient.resetStore());
Meteor.startup(() => {
const target = document.getElementById('react-root');
const app = (
<ApolloProvider client={apolloClient}>
<BrowserRouter>
<Switch>
<App />
</Switch>
</BrowserRouter>
</ApolloProvider>
);
return !window.noSSR ? hydrate(app, target) : render(app, target);
I am still wondering what has changed as the app used to work just fine. I never got this error befor.