-
I feel like this is a dumb question, but following the docs in the My understanding is that I can wrap my route or certain portion of my application with the However, when I do this, I'm still running into issues that In this specific instance, I am building a leaflet map as the primary function of my import type { MetaFunction } from '@remix-run/node'
import { Provider } from 'react-redux'
import MapEngine from '~/components/MapEngine'
import { store } from '~/store'
import { ClientOnly } from 'remix-utils/client-only'
export const meta: MetaFunction = () => {
return [
{ title: 'Title' },
{ name: 'description', content: 'Description.' },
]
}
const Index = (): JSX.Element => {
return (
<ClientOnly>
{() => <Application />}
</ClientOnly>
)
}
const Application = (): JSX.Element => {
return (
<Provider store={store}>
<MapEngine />
</Provider>
)
}
export default Index My expectation is that now when I go to my site, it runs only on the client. However, when attempting to work with the site (particularly in dev environment), I receive the following error:
Now granted, there are a few things going on here
Following the stack trace, it looks like it starts from the Any help here would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
If you are accessing window inside your MapEngine component, you need to ensure that it is not undefined. |
Beta Was this translation helpful? Give feedback.
-
Most likely MapEngine or a dependency of MapEngine is trying to access something from window at the module level instead of component level. This cause that just by importing the module it tries to use window and fails to. Try to rename your MapEngine file to have the .client extension, this will tell Remix to only include the module client side Now the exported component will be undefined server side and that's where ClientOnly will prevent rendering (or trying to render it) server-side. |
Beta Was this translation helpful? Give feedback.
You need to wrap the component in ClientOnly, because as I mentioned on the server the export will be undefined and you can't render undefined, so you wrap MapEngine in ClientOnly to prevent trying to render it.