Skip to content

Conversation

@ibgreen
Copy link
Collaborator

@ibgreen ibgreen commented Dec 19, 2025

Motivation

  • Avoid attempting to parse HTML/text/JSON responses (error pages, HTML error bodies, etc.) as Mapbox Vector Tiles which causes parsing errors and wasted CPU.
  • Make Content-Type handling reusable and robust by centralizing header normalization logic.

Description

  • Added a Content-Type parser utility parseContentType in modules/loader-utils/src/lib/request-utils/parse-content-type.ts and exported it from modules/loader-utils/src/index.ts.
  • Updated MVTTileSource.getTile (modules/mvt/src/mvt-source.ts) to call parseContentType on response.headers.get('content-type') and early-return null for known non-MVT types (e.g. text/*, application/json, application/xml) or when the header is present but not in the allowlist.
  • Positive allowlist uses MVTFormat.mimeTypes and additionally accepts image/* and application/octet-stream as valid tile payloads.
  • Added tests: a unit test for parseContentType (modules/loader-utils/test/lib/request-utils/parse-content-type.spec.ts) and a mvt test that simulates a text/html response to verify MVTTileSource#getTileData returns null and does not call MVTLoader.parse (modules/mvt/test/mvt-source.spec.ts).

Testing

  • Added unit tests (not run in this environment):
    • 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 return null and MVTLoader.parse is not invoked)
  • Attempted to run formatting and tests: yarn lint fix and yarn test node — both could not be executed in this environment due to missing node_modules / install state (install required).

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 10 to 14
VectorTileSource,
GetTileParameters,
GetTileDataParameters
GetTileDataParameters,
parseContentType
} from '@loaders.gl/loader-utils';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants