Introducing a new way to review your PRs.

Read the announcement

visgl / react-google-maps

React components and hooks for the Google Maps JavaScript API

View on GitHub

19 documents · Updated Nov 2, 2026

docs / server-safe-integration

Server-safe integration

The server entry point provides a small API for creating Google Static Maps output without loading the interactive Google Maps JavaScript API. It lets a server build a map image URL, sign that URL when needed, and pass it to server-rendered HTML or another image consumer. See Package exports and types for the package entry-point model.

Server entry point

The server entry point is the @vis.gl/react-google-maps/server package path. It exposes the static map surface instead of the full interactive map surface, so server code can create map-related output without browser rendering.

Import boundary

The entry point exposes StaticMap, createStaticMapsUrl, and the types used by the URL builder. The StaticMap component is an image wrapper. The URL builder is the main server-facing API because it returns a URL and does not need a map DOM element.

References: src/…/index.ts• L1-3 src/…/static-map.tsx• L1-20

Package build surface

The package publishes the server entry point as its own ESM, CommonJS, and type declaration paths. The ./server export maps those three consumer needs to the server build outputs. This gives server-aware tools a direct import target and keeps the intended server API separate from the root package surface.

References: package.json• L13-23 rollup.config.mjs• L29-32 rollup.config.mjs• L72-87

Static map output

Static map output is an image request rather than an interactive map. The server prepares the request URL, while Google Maps Static API returns the image when the URL is used.

URL construction

createStaticMapsUrl accepts an API key and image size, then adds view, map, marker, path, visible-location, and style data when supplied. Locations can be coordinate objects or address strings. A plain map needs a center and zoom; map content can instead provide the locations that define the view.

References: src/…/index.ts• L8-32 src/…/index.ts• L77-144 src/…/types.ts• L1-37

Image rendering

StaticMap accepts the completed URL and emits an image element for server-rendered output. It does not build the URL, call the Static Maps service, or create an interactive map. The URL must be present before the component renders.

References: src/…/static-map.tsx• L6-20

Server request flow

The server flow separates request preparation from image display. This separation lets server code add a digital signature before the URL reaches a browser or another public client.

The following diagram shows the path from server input to map image output.

flowchart LR
  A[Server map data] --> B[createStaticMapsUrl]
  B --> C[Optional server-side URL signing]
  C --> D[StaticMap or image consumer]
  D --> E[Google Static Maps API image]

The URL builder places the API key and map settings in the request. If the project uses a signing secret, signing must happen on the server before the URL is exposed. The server can then use StaticMap for HTML output or return the URL to a controlled image flow.

References: src/…/index.ts• L77-144 src/…/static-map.tsx• L14-19 docs/…/static-map.md• L134-163

Runtime boundary

The server surface is intended for map image requests, not browser map behavior. It does not provide interactive maps, map controls, browser event handling, or client-side API loading.

Use the server entry point when the output only needs a static image or a URL. Use the root entry point when the application must create and control an interactive map in a browser. See Static maps and Static Maps URL assembly for the related product flows.

The API key is part of every URL built by the helper. A URL signing secret is a separate private value and must stay on the server. Missing API key, width, or height values produce warnings and can result in an unusable request, so the calling system must validate its input before publishing the URL.

References: src/…/index.ts• L94-112 src/…/static-map.tsx• L14-19 docs/…/static-map.md• L136-149

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep src/…/index.ts, the ./server export map, and the server/index build entry aligned. A mismatch can leave runtime imports or type imports without a matching published file.
  • Keep the exported static map types aligned with the URL fields assembled by createStaticMapsUrl. A field can be accepted by TypeScript but omitted from the external Static Maps request if only one side changes.
  • Preserve the server-only handling of URL signing secrets. Changes to examples or docs must not move the secret into browser code or public request data.
  • Keep the required request inputs clear across the type contract, URL builder, and server integration docs. The builder warns for missing values instead of stopping the request.

Important failure modes

TriggerConsequenceGuard
The server publishes a URL with a missing API key, width, or height.The Static Maps request can fail or return unusable output.Validate these values before calling or publishing the URL.
A signing secret reaches client code or a public request.An attacker can create signed requests under the project identity.Sign on the server and keep the secret in server-only configuration.
Server code imports the interactive root surface for static output.The integration gains browser-oriented behavior that the server path is meant to avoid.Import @vis.gl/react-google-maps/server for static map URL and image output.
The image URL is empty when StaticMap renders.Rendering throws before an image element is returned.Build and validate the URL before rendering StaticMap.

Key files

FileWhy to read it
src/…/index.tsDefines the server-facing export boundary.
src/…/static-map.tsxShows the image output contract and the public static map exports.
src/…/index.tsDefines how server input becomes a Google Static Maps request URL.
src/…/types.tsDefines the map request data that server callers can provide.
package.jsonDeclares the published ./server import path and its ESM, CommonJS, and type targets.
rollup.config.mjsShows how the server entry point is built for supported module formats.