Skip to content

Commit a76c816

Browse files
authored
Fix excess execution of fetch (#938)
* Fix excess execution of fetch on invalid url derived from tile coordinates that are out of bounds Fix malformed layer- element in index.html Add test TemplatedMapMLTileLayer.test.js. Closes #936 * Separate popupTabNavigation.test.js and layerContextMenuKeyboard.test.js from the rest of the tests, to see if they will deflake this way
1 parent b85e80d commit a76c816

File tree

23 files changed

+9313
-27
lines changed

23 files changed

+9313
-27
lines changed

.github/workflows/ci-testing.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
- run: npx playwright install --with-deps
1919
- run: npm install -g grunt-cli
2020
- run: grunt default
21-
- run: xvfb-run --auto-servernum -- npx playwright test layerContextMenuKeyboard popup --workers=1 --retries=3
21+
- run: xvfb-run --auto-servernum -- npx playwright test --grep-invert="popupTabNavigation\.test\.js|layerContextMenuKeyboard\.test\.js" --workers=1 --retries=3
22+
- run: xvfb-run --auto-servernum -- npx playwright test --grep="popupTabNavigation\.test\.js|layerContextMenuKeyboard\.test\.js" --workers=1 --retries=3
2223
# - run: xvfb-run --auto-servernum -- npm run jest
2324
env:
2425
CI: true

index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
8484
</map-extent>
8585
</layer->
86-
</layer->
8786
</mapml-viewer>
8887
</body>
8988
</html>

src/mapml/layers/TemplatedTileLayer.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,34 @@ export var TemplatedTileLayer = L.TileLayer.extend({
138138
return this.options.pane;
139139
},
140140
_fetchTile: function (coords, tile) {
141-
fetch(this.getTileUrl(coords), { redirect: 'follow' })
142-
.then(function (response) {
143-
if (response.status >= 200 && response.status < 300) {
144-
return Promise.resolve(response);
145-
} else {
146-
console.log(
147-
'Looks like there was a problem. Status Code: ' + response.status
148-
);
149-
return Promise.reject(response);
150-
}
151-
})
152-
.then(function (response) {
153-
return response.text();
154-
})
155-
.then((text) => {
156-
var parser = new DOMParser();
157-
return parser.parseFromString(text, 'application/xml');
158-
})
159-
.then((mapml) => {
160-
this._createFeatures(mapml, coords, tile);
161-
this._mapmlTileReady(tile);
162-
})
163-
.catch((err) => {
164-
console.log('Error Creating Tile');
165-
});
141+
let url = this.getTileUrl(coords);
142+
if (url) {
143+
fetch(url, { redirect: 'follow' })
144+
.then(function (response) {
145+
if (response.status >= 200 && response.status < 300) {
146+
return Promise.resolve(response);
147+
} else {
148+
console.log(
149+
'Looks like there was a problem. Status Code: ' + response.status
150+
);
151+
return Promise.reject(response);
152+
}
153+
})
154+
.then(function (response) {
155+
return response.text();
156+
})
157+
.then((text) => {
158+
var parser = new DOMParser();
159+
return parser.parseFromString(text, 'application/xml');
160+
})
161+
.then((mapml) => {
162+
this._createFeatures(mapml, coords, tile);
163+
this._mapmlTileReady(tile);
164+
})
165+
.catch((err) => {
166+
console.log('Error Creating Tile');
167+
});
168+
}
166169
},
167170

168171
// TO DO: get rid of this function altogether; see TO DO below re: map-link

test/e2e/data/tiles/osmtile/0/0/0.mapml

Lines changed: 2438 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/1/0/0.mapml

Lines changed: 758 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/1/0/1.mapml

Lines changed: 1325 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/1/1/0.mapml

Lines changed: 315 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/1/1/1.mapml

Lines changed: 516 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/2/0/0.mapml

Lines changed: 223 additions & 0 deletions
Large diffs are not rendered by default.

test/e2e/data/tiles/osmtile/2/0/1.mapml

Lines changed: 175 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)