From 7153cfc6568ee14244bf89332ac23e9ae989f596 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 10:11:35 +0300 Subject: [PATCH] Fix map staying blank until moved 1. Apply the current style on the map's style.load event 2. Add an e2e test that pauses animation frames until the style has loaded 3. Add a CHANGELOG entry Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WDkBFXcoMv8K4QSHA6P3Fg --- CHANGELOG.md | 1 + e2e/map.spec.ts | 14 ++++++++++++++ e2e/playwright-helper.ts | 23 +++++++++++++++++++++++ src/components/MapMaplibreGl.tsx | 1 + 4 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f36b2eff..e3199d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - The map's data listener now fires on tile loads again, so source and vector layer field autocompletion is populated - The `maputnik` desktop binary now opens the default browser automatically on startup (opt out with `--no-browser`) - Keyboard shortcuts now keep working while the map has focus, instead of going dead until the map is blurred +- The map no longer stays blank on load until it is moved, when the style loads before the map is ready - _...Add new stuff here..._ ## 3.1.0 diff --git a/e2e/map.spec.ts b/e2e/map.spec.ts index b33fdc66..6eb0cbd8 100644 --- a/e2e/map.spec.ts +++ b/e2e/map.spec.ts @@ -64,4 +64,18 @@ describe("map", () => { await then(get.elementByTestId("feature-layer-popup")).shouldBeVisible(); }); }); + + describe("style loaded while animation frames are paused", () => { + beforeEach(async () => { + await given.pausedAnimationFrames(); + await when.setStyle("rectangles", 5); + await then(get.elementByTestId("layer-list-item:rectangles")).shouldBeVisible(); + await when.resumeAnimationFrames(); + }); + + test("should render without moving the map", async () => { + await when.clickCenter("maplibre:map"); + await then(get.elementByTestId("feature-layer-popup")).shouldBeVisible(); + }); + }); }); diff --git a/e2e/playwright-helper.ts b/e2e/playwright-helper.ts index e0d73c8d..4adac34c 100644 --- a/e2e/playwright-helper.ts +++ b/e2e/playwright-helper.ts @@ -235,6 +235,26 @@ export class PlaywrightHelper { }); }, + /** + * Holds back requestAnimationFrame callbacks until + * when.resumeAnimationFrames(), the way a background tab does. Must be + * called before the page under test is loaded. + */ + pausedAnimationFrames: async () => { + await this.page.addInitScript(() => { + const requestAnimationFrame = window.requestAnimationFrame.bind(window); + const paused: FrameRequestCallback[] = []; + window.requestAnimationFrame = (callback) => { + paused.push(callback); + return 0; + }; + (window as any).resumeAnimationFrames = () => { + window.requestAnimationFrame = requestAnimationFrame; + paused.forEach((callback) => requestAnimationFrame(callback)); + }; + }); + }, + intercept: async (pattern: RegExp, alias: string, _method = "GET") => { this.recordedRequests.set(alias, []); await this.page.route(pattern, (route) => { @@ -271,6 +291,9 @@ export class PlaywrightHelper { wait: (ms: number) => this.page.waitForTimeout(ms), + /** Releases the frames held back by given.pausedAnimationFrames(). */ + resumeAnimationFrames: () => this.page.evaluate(() => (window as any).resumeAnimationFrames()), + tab: () => this.page.keyboard.press("Tab"), typeKeys: (keys: string) => typeSequence(this.page, keys), diff --git a/src/components/MapMaplibreGl.tsx b/src/components/MapMaplibreGl.tsx index d6135b35..5d81b499 100644 --- a/src/components/MapMaplibreGl.tsx +++ b/src/components/MapMaplibreGl.tsx @@ -236,6 +236,7 @@ class MapMaplibreGlInternal extends React.Component {