[Feat] Add SSR support or safe usage of AdvancedMarker and DOM-dependent components
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- react, typescript
调研方向
首先阅读 issue 中提到的 AdvancedMarker、MapControl 和 APIProvider 入口点,然后在 SSR 和 hydration 设置中复现它们的行为。确定应支持 SSR 安全行为还是仅客户端行为,为服务器端渲染和 hydration 添加覆盖,并记录 SSR 框架的推荐用法。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 1.9k
- 派生
- 195
- 平均合并
- 2 天 11 小时
- 30 天内合并 PR
- 14
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
visgl/react-google-maps 的其他 Issue
-
google maps issue
难度 3/5 1-2 天 新手友好度 74/100
visgl/react-google-maps#1080 · 1 条评论 ·
维护者通常 2 天内回复
-
bug needs more info
难度 3/5 1-2 天 新手友好度 45/100
visgl/react-google-maps#1039 · 1 条评论 ·
维护者通常 2 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 35/100
visgl/react-google-maps#918 · 9 条评论 ·
维护者通常 2 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 45/100
visgl/react-google-maps#905 ·
维护者通常 2 天内回复
-
google maps issue
难度 3/5 1-2 天 新手友好度 45/100
visgl/react-google-maps#889 · 1 条评论 ·
维护者通常 2 天内回复
查看 visgl/react-google-maps 的全部 Issue
相似的 Issue
-
Mend: dependency security vulnerability untriaged
难度 2/5 1-3 小时 新手友好度 68/100
opensearch-project/security-dashboards-plugin#2545 ·
维护者通常 1 天内回复
-
Add: Dream TR SD未关闭check:passed streams:add
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
doctor integrity sample scans soft-deleted pages on Postgres (batch path has no deleted_at filter)未关闭
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
SocialGouv/egapro#4672 · 1 条评论 ·
维护者通常 2 天内回复
-
area:agents area:tui bug
难度 2/5 1-3 小时 新手友好度 74/100
anthropics/claude-code#98358 ·
维护者通常 1 天内回复