Skip to content

Commit 4a47937

Browse files
mournergithub-actions[bot]
authored andcommitted
Switch render/query tests to the ESM bundle
GitOrigin-RevId: 64646eeffc0d665736caa60d908fd101d77dd5c8
1 parent ebf6a2f commit 4a47937

7 files changed

Lines changed: 26 additions & 7 deletions

File tree

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,20 @@
138138
"test-esm": "npx vitest run --config vitest.config.esm.ts",
139139
"test-csp": "npm run build-token && vitest --config vitest.config.csp.ts --run",
140140
"watch-render": "npx vitest watch --config vitest.config.render.ts",
141-
"pretest-render": "npm run build-dev",
141+
"pretest-render": "npm run build-esm-dev",
142142
"test-render": "npx vitest run --config vitest.config.render.ts",
143143
"test-render-firefox": "RENDER_BROWSER=firefox npm run test-render",
144144
"test-render-safari": "RENDER_BROWSER=webkit npm run test-render",
145+
"pretest-render-dev": "npm run build-dev",
146+
"test-render-dev": "RENDER_BUNDLE=dev npx vitest run --config vitest.config.render.ts",
147+
"pretest-render-esm-prod": "npm run build-esm-prod",
148+
"test-render-esm-prod": "RENDER_BUNDLE=esm-prod npx vitest run --config vitest.config.render.ts",
145149
"pretest-render-prod": "npm run build-prod",
146150
"test-render-prod": "RENDER_BUNDLE=prod npx vitest run --config vitest.config.render.ts",
147151
"pretest-render-csp": "npm run build-csp",
148152
"test-render-csp": "RENDER_BUNDLE=csp npx vitest run --config vitest.config.render.ts",
149153
"watch-query": "npx vitest watch --config vitest.config.query.ts",
154+
"pretest-query": "npm run build-esm-dev",
150155
"test-query": "npx vitest run --config vitest.config.query.ts",
151156
"test-expressions": "tsx ./test/expression.test.ts",
152157
"test-typings": "tsx ./build/generate-typed-style-spec.ts && npm run tsc",

rollup.config.esm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function assertWorkerChunkIsolation(): Plugin {
121121
name: 'assert-worker-chunk-isolation',
122122
generateBundle(_options, bundle) {
123123
const chunks = Object.values(bundle).filter(output => output.type === 'chunk');
124-
const workerEntry = chunks.find(chunk => chunk.isEntry && chunk.facadeModuleId && chunk.facadeModuleId.endsWith('/src/source/worker.ts'));
124+
const workerEntry = chunks.find(chunk => chunk.isEntry && chunk.facadeModuleId && chunk.facadeModuleId.replace(/\\/g, '/').endsWith('/src/source/worker.ts'));
125125
if (!workerEntry) {
126126
this.error('worker entry chunk not found — cannot verify main/worker chunk isolation');
127127
return;

src/render/painter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ async function setupStandard(painter?: Painter) {
184184
Object.assign(prepare, {
185185
model: Standard.prepare,
186186
});
187-
if (painter && !painter._shadowRenderer) {
187+
// The Standard module loads asynchronously (a lazy import in ESM builds), so the
188+
// map may have been removed while it was still loading — bail out to avoid touching
189+
// a destroyed WebGL context.
190+
if (painter && !painter._destroyed && !painter._shadowRenderer) {
188191
const SR = (Standard as {ShadowRenderer?: new (p: Painter) => ShadowRenderer}).ShadowRenderer;
189192
if (SR) painter._shadowRenderer = new SR(painter);
190193
}
@@ -276,6 +279,7 @@ class Painter {
276279
_fogVisible: boolean;
277280
_cachedTileFogOpacities: Record<number, [number, number]>;
278281
_shadowRenderer?: ShadowRenderer;
282+
_destroyed?: boolean;
279283
_devtools?: IDevTools;
280284
_wireframeDebugCache: WireframeDebugCache;
281285

@@ -1909,6 +1913,8 @@ class Painter {
19091913
if (this.emptyDepthTexture) {
19101914
this.emptyDepthTexture.destroy();
19111915
}
1916+
1917+
this._destroyed = true;
19121918
}
19131919

19141920
prepareDrawTile() {

src/source/worker_tile.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ class WorkerTile {
413413
assert(layer.source === this.source);
414414
if (!this.isLayerActiveForTile(layer)) continue;
415415

416-
recalculateLayers(family, this.zoom, options.brightness, availableImages, this.worldview, options.activeFloors);
417-
418416
// Assign bucket.index and register the layer-id mapping synchronously in
419417
// style order. The async prepare() chain below can resolve out of order
420418
// (HD layers add a microtask tick for the dynamic-import await), and
@@ -424,6 +422,10 @@ class WorkerTile {
424422
featureIndex.bucketLayerIDs.push(family.map((l) => makeFQID(l.id, l.scope)));
425423

426424
const processBucket = () => {
425+
// Recalculate right before populate: `family` layers are shared across tiles and recalculate
426+
// mutates their zoom-dependent layout in place. On the async prepare() path another tile could
427+
// otherwise recalculate at a different zoom in between, giving wrong zoom-stepped values (e.g. model-id).
428+
recalculateLayers(family, this.zoom, options.brightness, availableImages, this.worldview, options.activeFloors);
427429
const styleLayer: StyleLayer = layer;
428430
assert(styleLayer.createBucket);
429431
const bucket: Bucket = buckets[layer.id] = styleLayer.createBucket({

test/integration/lib/mapboxgl.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ if (typeof import.meta.env !== 'undefined' && import.meta.env.VITE_DIST_BUNDLE =
1818
await import(/* @vite-ignore */ modulePath);
1919

2020
mapboxgl = globalThis.mapboxgl;
21+
} else if (typeof import.meta.env !== 'undefined' && import.meta.env.VITE_DIST_BUNDLE === 'esm') {
22+
modulePath = '../../../dist/esm-dev/mapbox-gl.js';
23+
mapboxgl = await import(/* @vite-ignore */ modulePath);
24+
} else if (typeof import.meta.env !== 'undefined' && import.meta.env.VITE_DIST_BUNDLE === 'esm-prod') {
25+
modulePath = '../../../dist/esm/mapbox-gl.js';
26+
mapboxgl = await import(/* @vite-ignore */ modulePath);
2127
} else {
2228

2329
mapboxgl = globalThis.mapboxgl;

vitest.config.query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default mergeConfig(baseConfig, defineConfig({
99
// Opt-in embedding of passed-test images in the report (local dev only;
1010
// forced off on CI to keep the report small).
1111
'import.meta.env.VITE_EMBED_PASSED_IMAGES': JSON.stringify(String(!isCI && process.env.EMBED_PASSED_IMAGES === 'true')),
12-
'import.meta.env.VITE_DIST_BUNDLE': JSON.stringify('dev'),
12+
'import.meta.env.VITE_DIST_BUNDLE': JSON.stringify(process.env.QUERY_BUNDLE || 'esm'),
1313
},
1414
test: {
1515
include: ['test/integration/query-tests/index.test.ts'],

vitest.config.render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {integrationTests, setupIntegrationTestsMiddlewares, serveDistPlugin, sui
77
import type {BrowserConfigOptions} from 'vitest/node';
88

99
const renderBrowser = process.env.RENDER_BROWSER || 'chromium';
10-
const bundle = process.env.RENDER_BUNDLE || 'dev';
10+
const bundle = process.env.RENDER_BUNDLE || 'esm';
1111

1212
const getAngle = () => {
1313
if (os.platform() === 'darwin' && os.arch() === 'arm64') return '--use-angle=metal';

0 commit comments

Comments
 (0)