Skip to content

fix(serialize): make key comparison locale-independent#178

Open
cernymatej wants to merge 2 commits intounjs:mainfrom
cernymatej:fix/locale-independent-string-comparison
Open

fix(serialize): make key comparison locale-independent#178
cernymatej wants to merge 2 commits intounjs:mainfrom
cernymatej:fix/locale-independent-string-comparison

Conversation

@cernymatej
Copy link
Copy Markdown

@cernymatej cernymatej commented Feb 3, 2026

fix nuxt/nuxt#34236
fix #177

This PR aims to solve a problem with the result of serialize() being locale-dependent, which was introduced in #113.

@cernymatej cernymatej changed the title test(serialize): add locale independence test fix(serialize): make key comparison locale-independent Feb 3, 2026
@cernymatej
Copy link
Copy Markdown
Author

@pi0 is there a reasony why localeCompare is used?

@cernymatej cernymatej force-pushed the fix/locale-independent-string-comparison branch from c895083 to 0f949b2 Compare February 3, 2026 11:32
@cernymatej cernymatej marked this pull request as ready for review February 3, 2026 11:51
map.set({ x: 42 }, "3");

expect(serialize(map)).toMatchInlineSnapshot(
`"Map{{x:42}:'3',1:4,2:3,a:'1',z:2}"`,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think this snapshot was generated on a system with a different locale. The changes made in this PR should now ensure that the order is deterministic.

@zsilbi
Copy link
Copy Markdown
Collaborator

zsilbi commented Feb 3, 2026

I have this also in #144 but purely for perf reasons.
This would break previous hashes so I'd consider this a breaking change.

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.

Locale-dependant string comparison causes hash to produce inconsistent results useFetch key is not stable

2 participants