Skip to content

Add Edit in Snack buttons to example pages - #26

Merged
mfazekas merged 2 commits into
mainfrom
docs/snack-links
Oct 27, 2026
Merged

mfazekas merged 2 commits into
mainfrom
docs/snack-links

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds an "Edit in Snack" button to example pages, next to the existing web example link, which becomes a "Run on web" button in the same row. "Edit in Snack" opens an unsaved Snack in web-only mode with @rnmapbox/maps@10.3.14 and mapbox-gl. The Snack's App.js calls setWorkerUrl and fetches the public Snack token from rnmapbox/ci-config at runtime. The example and the shared helpers it imports are loaded by URL from the v10.3.14 tag, so the code matches the pinned release. Inlining the examples would push some URLs past snack.expo.dev's ~15k limit, which returns HTTP 431.

Which examples get the button comes from rnmapbox/maps: the example's snackSupported metadata (defaulting to webSupported) is written to the page's snack_supported front matter, see rnmapbox/maps#4416. Until those pages are regenerated, the button follows the "Try it on web" link, so this works with the current docs too (40 pages; GeoJSONSource and ImageOverlay are skipped because their URL can't be built). The build fails if a page has snack_supported: true but imports files the Snack can't load.

With the docs regenerated from #4416, 49 pages get the button. Each was opened from the locally built page in headless Chromium and showed a rendered map, mapbox tiles returning 200, and no error overlay; TransparentMap requests no tiles by design and was checked visually against the hosted web app. CameraAnimation and QueryTerrainElevation now work: @turf/bbox needs @turf/helpers and @turf/meta added explicitly, and @turf/length is pinned to 6.3.0 for Snack because 6.5.0 needs @babel/runtime, which Snackager can't bundle. GeoJSONSource and ImageOverlay opt out in #4416: Snack parses URL-loaded PNGs as code even when passed as assets.

When bumping RNMAPBOX_MAPS_VERSION in plugins/snack/snackUrl.js, recheck the Snack-enabled examples.

A remark plugin adds a button above the code of allowlisted examples that
opens an unsaved Snack on web with @rnmapbox/maps 10.3.14, loading the
example and its helpers from the release tag.
rnmapbox/maps writes the example's snackSupported (defaulting to
webSupported) to the snack_supported front matter; pages without it fall
back to the "Try it on web" link. The web link becomes a "Run on web"
button next to "Edit in Snack". CameraAnimation and QueryTerrainElevation
now run in Snack with the turf dependencies Snackager leaves out.
@mfazekas mfazekas changed the title Add Open in Snack buttons to example pages Add Edit in Snack buttons to example pages Oct 27, 2026
@mfazekas
mfazekas marked this pull request as ready for review October 27, 2026 20:38
@mfazekas
mfazekas merged commit 4242a69 into main Oct 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant