Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): clone RegExp values with new RegExp instead of structuredClone (fix #19245, fix #18875) #19247

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

askoufis
Copy link
Contributor

@askoufis askoufis commented Jan 21, 2025

Fixes #19245. Fixes #18875.

Description

Jest appears to provide its own global structuredClone that modifies RegExps in such a way that they fail instanceof RegExp checks, causing an error in a rollup plugin used by vite (and likely other errors elsewhere). As suggested, new RegExp seems to correctly clone RegExps in Jest.

I thought about writing a test that modified the structuredClone global but decided against it as that's more like testing jest implementation detail rather than regexp cloning behaviour (which is already tested).

…turedClone` (fix #19245, fix #18875)

- Jest appears to provide its own global `structuredClone` that modifies
  `RegExp`s in such a way that they fail `instanceof RegExp` checks,
  causing an error in a rollup plugin used by `vite` (and likely elsewhere).
  `new RegExp` seems to correctly clone `RegExp`s in Jest.
@askoufis askoufis force-pushed the fix/deep-clone-regexp branch from 313966b to 672e2ea Compare January 21, 2025 02:53
@askoufis askoufis changed the title fix(utils): Clone RegExp values with new RegExp instead of structuredClone (fix #19245, fix #18875) fix(utils): clone RegExp values with new RegExp instead of structuredClone (fix #19245, fix #18875) Jan 21, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks!

@sapphi-red sapphi-red added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Jan 24, 2025
@sapphi-red sapphi-red merged commit 56ad2be into vitejs:main Jan 24, 2025
17 checks passed
@askoufis askoufis deleted the fix/deep-clone-regexp branch January 24, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
3 participants