[Feat] Add SSR support or safe usage of AdvancedMarker and DOM-dependent components
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- react, typescript
Research direction
Start by reading the AdvancedMarker, MapControl, and APIProvider entry points mentioned in the issue, then reproduce their behavior in an SSR and hydration setup. Decide on the supported SSR-safe or client-only behavior, add coverage for server rendering and hydration, and document the recommended usage for SSR frameworks.
Written by the indexing model from the issue text.
Description
Target Use Case
We are using @vis.gl/react-google-maps in a project that renders pages using server-side rendering, and then hydrates them on the client.
However, the current package assumes a browser environment by default — for example, components like AdvancedMarker use ReactDOM.createPortal and interact with the DOM, which causes SSR crashes when the page is pre-rendered on the server.
We are currently forced to wrap these components in client-only guards like:
if (typeof window !== 'undefined') {
return <AdvancedMarker ... />;
}
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
return isClient ? <AdvancedMarker ... /> : null;
It would be helpful if the library could offer a built-in way to make components like AdvancedMarker SSR-safe or optionally lazy-loadable so that SSR apps don’t crash or require workarounds.
Adding SSR support (or safe lazy loading) would benefit anyone using React frameworks like Next.js, Remix, or custom SSR setups that render Google Maps on the server and hydrate them client-side.
This is especially important for:
- SEO-sensitive apps
- Performance-focused web apps
- Sites with server-rendered landing pages that contain maps
It would also reduce the need for wrapping AdvancedMarker and other DOM-dependent components in custom client-only guards, simplifying code and avoiding errors during hydration.
Proposal
- Provide a
ssr: falseorclientOnly: trueprop on components likeAdvancedMarkerorAPIProviderthat tells them to skip rendering during SSR. - Internally guard browser-only operations in DOM-based components like
AdvancedMarkerby checkingtypeof window !== 'undefined'before callingReactDOM.createPortal. - Document a recommended pattern or wrapper component for SSR users, such as a ClientOnly wrapper like:
function ClientOnly({ children }) {
const [isClient, setIsClient] = useState(false);
useEffect(() => setIsClient(true), []);
return isClient ? children : null;
}
- Optionally provide a utility from the package itself:
import { ClientOnly } from '@vis.gl/react-google-maps';
// or
<AdvancedMarker ssr={false} ... />
Even a small guard inside AdvancedMarker (as well as MapControl) would prevent runtime crashes and improve compatibility across frameworks.
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 195
- Avg merge
- 6h 26m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/react-google-maps
-
Polygon / Polyline: edits after a controlled `paths` update never reach `onPathsChanged`Possibly taken @anubhavlal07 claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
visgl/react-google-maps#1120 ·
Maintainers usually reply within 1 day
-
google maps issue
Difficulty 3/5 1-2 days Newbie friendliness 74/100
visgl/react-google-maps#1080 · 1 comment ·
Maintainers usually reply within 1 day
-
bug needs more info
Difficulty 3/5 1-2 days Newbie friendliness 45/100
visgl/react-google-maps#1039 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
visgl/react-google-maps#918 · 9 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
visgl/react-google-maps#905 ·
Maintainers usually reply within 1 day
All issues in visgl/react-google-maps
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day