overlookmotel / livepack

Serialize live running code to Javascript
MIT License
45 stars 1 forks source link

`URL` and its `.searchParams` not serialized as related in Node v20 #524

Open overlookmotel opened 1 year ago

overlookmotel commented 1 year ago

Input:

const url = new URL('http://foo.com/?x=1&y=2'),
  search = url.searchParams;
export default () => search === url.searchParams;

Output in Node v18.18.0:

const url = new URL("http://foo.com/?x=1&y=2");
export default ((search, url) => () => search === url.searchParams)(
  url.searchParams,
  url
);

This is correct. Function returns true in both original and serialized code.

Output in Node v20.0.0 (and latest v20.8.0):

export default ((search, url) => () => search === url.searchParams)(
  new URLSearchParams("x=1&y=2"),
  new URL("http://foo.com/?x=1&y=2")
);

The exported function here returns false (incorrect).

The problem is due to removal of the Symbol(context) property on URLs in Node v20.0.0, which Livepack relies on to link URLs and their URLSearchParams.