Skip to content

fix: resolve source locations without Array.prototype.toSorted - #5012

Open
eisen0419 wants to merge 1 commit into
graphql:17.x.xfrom
eisen0419:fix/5010-get-locations-no-to-sorted
Open

eisen0419 wants to merge 1 commit into
graphql:17.x.xfrom
eisen0419:fix/5010-get-locations-no-to-sorted

Conversation

@eisen0419

Copy link
Copy Markdown

Fixes #5010.

getLocations sorted each source's positions with Array.prototype.toSorted (introduced in #4958). Engines without ES2023 toSorted (such as Hermes in React Native, Safari < 16, and Chrome < 110) throw a TypeError during validate() or new GraphQLError(...) whenever an error spans two or more nodes.

Because positions is freshly allocated inside getLocations via AccumulatorMap and is never returned or shared with the caller, sorting it in place with positions.sort((a, b) => a.position - b.position) preserves identical results without mutating caller input.

Verification

  • Added a regression test in src/language/__tests__/location-test.ts that temporarily removes Array.prototype.toSorted (restoring the exact property descriptor in finally) and confirms getLocations resolves unsorted positions without mutating frozen caller input.
  • npm run testonly:cover (100% lines / branches / functions)
  • npm run lint, npm run check:ts, npm run check:deno, npm run prettier:check, npm run testonly:examples

getLocations sorted each source's positions with Array.prototype.toSorted.
Hermes and other engines before ES2023 do not implement that method, so
validate() and GraphQLError throw when an error cites more than one node.

The position list is allocated inside getLocations and is not returned,
so sorting it in place keeps the same locations and does not mutate
caller input.

Fixes graphql#5010
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

@eisen0419 is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getLocations uses Array.prototype.toSorted (17.1.0), so validate() throws on Hermes / React Native

1 participant