Repository navigation
feat(web): support Expo Snack web preview - #4408
Merged
Merged
Conversation
Snack's bundler has no CSS loader, so the web MapView now injects mapbox-gl's CSS (inlined into src/web/mapboxglCss.ts by yarn generate) unless the page already has it. Snack also breaks mapbox-gl's built-in worker, so add Mapbox.setWorkerUrl to point it at the CSP worker build; it's a no-op on iOS and Android.
2 of 8 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes the web implementation load and run in Expo Snack's web preview, so docs examples can later link to a Snack.
import 'mapbox-gl/dist/mapbox-gl.css'stopped the package from loading. The import is gone. When the webMapViewmounts, it now injects mapbox-gl's CSS into one id-guarded<style>element, unless the page already has the CSS (the same.mapboxgl-canarycheck mapbox-gl uses).yarn generateinlines the CSS string intosrc/web/mapboxglCss.ts._ is not defined). The newMapbox.setWorkerUrl(url)setsmapboxgl.workerUrland is a no-op on iOS and Android. It's documented insrc/web/install.md.Existing web apps behave the same, except that they no longer need a CSS loader.
Verified:
mapbox-gl.css; this branch bundles.setWorkerUrlthe worker throws_ is not defined. With it, both maps load with no worker errors, and there is one style element across two maps and a remount.setWorkerUrl.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp (web only)./example)Screenshot OR Video
Component to reproduce the issue you're fixing