Skip non-MVT content types when fetching tiles#3269
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| VectorTileSource, | ||
| GetTileParameters, | ||
| GetTileDataParameters | ||
| GetTileDataParameters, | ||
| parseContentType | ||
| } from '@loaders.gl/loader-utils'; |
There was a problem hiding this comment.
Import parseContentType as a value, not type-only
Because parseContentType is imported via a type-only import, it is erased from the JS output. When getTile executes, parseContentType is not defined and a ReferenceError is thrown before any tile parsing can happen. This will break all runtime tile fetching paths that call MVTTileSource.getTile, regardless of the response headers. Import parseContentType as a value (or add a separate non-type import) so it is available at runtime.
Useful? React with 👍 / 👎.
Motivation
Description
parseContentTypeinmodules/loader-utils/src/lib/request-utils/parse-content-type.tsand exported it frommodules/loader-utils/src/index.ts.MVTTileSource.getTile(modules/mvt/src/mvt-source.ts) to callparseContentTypeonresponse.headers.get('content-type')and early-returnnullfor known non-MVT types (e.g.text/*,application/json,application/xml) or when the header is present but not in the allowlist.MVTFormat.mimeTypesand additionally acceptsimage/*andapplication/octet-streamas valid tile payloads.parseContentType(modules/loader-utils/test/lib/request-utils/parse-content-type.spec.ts) and amvttest that simulates atext/htmlresponse to verifyMVTTileSource#getTileDatareturnsnulland does not callMVTLoader.parse(modules/mvt/test/mvt-source.spec.ts).Testing
modules/loader-utils/test/lib/request-utils/parse-content-type.spec.ts(verifies header normalization)modules/mvt/test/mvt-source.spec.ts(new test verifies HTML responses returnnullandMVTLoader.parseis not invoked)yarn lint fixandyarn test node— both could not be executed in this environment due to missingnode_modules/ install state (install required).Codex Task