···11+---
22+'@urql/core': patch
33+---
44+55+Fix incorrect JSON stringification of objects from different JS contexts. This could lead to invalid variables being generated in the Vercel Edge runtime specifically.
+33
packages/core/src/utils/variables.test.ts
···2233import { stringifyVariables, extractFiles } from './variables';
44import { describe, it, expect } from 'vitest';
55+import { Script } from 'vm';
5667describe('stringifyVariables', () => {
78 it('stringifies objects stabily', () => {
···4041 expect(stringifyVariables(Object.create(null))).toBe('{}');
4142 });
42434444+ it('recovers if the root object is a dictionary (Object.create(null)) and nests a plain object', () => {
4545+ const root = Object.create(null);
4646+ root.data = { test: true };
4747+ expect(stringifyVariables(root)).toBe('{"data":{"test":true}}');
4848+ });
4949+5050+ it('recovers if the root object contains a dictionary (Object.create(null))', () => {
5151+ const data = Object.create(null);
5252+ data.test = true;
5353+ const root = { data };
5454+ expect(stringifyVariables(root)).toBe('{"data":{"test":true}}');
5555+ });
5656+5757+ it('replaces non-plain objects at the root with keyed replacements', () => {
5858+ expect(stringifyVariables(new (class Test {})())).toMatch(
5959+ /^{"__key":"\w+"}$/
6060+ );
6161+ expect(stringifyVariables(new Map())).toMatch(/^{"__key":"\w+"}$/);
6262+ });
6363+4364 it('stringifies files correctly', () => {
4465 const file = new File([0] as any, 'test.js');
4566 const str = stringifyVariables(file);
4667 expect(str).toBe('null');
6868+ });
6969+7070+ it('stringifies plain objects from foreign JS contexts correctly', () => {
7171+ const global: typeof globalThis = new Script(
7272+ 'exports = globalThis'
7373+ ).runInNewContext({}).exports;
7474+7575+ const plain = new global.Function('return { test: true }')();
7676+ expect(stringifyVariables(plain)).toBe('{"test":true}');
7777+7878+ const data = new global.Function('return new (class Test {})')();
7979+ expect(stringifyVariables(data)).toMatch(/^{"__key":"\w+"}$/);
4780 });
4881});
4982