Skip to content

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

Merged
sapphi-red merged 1 commit intovitejs:mainfrom
askoufis:fix/deep-clone-regexp
Jan 24, 2025
Merged

fix(utils): clone RegExp values with new RegExp instead of structuredClone (fix #19245, fix #18875)#19247
sapphi-red merged 1 commit intovitejs:mainfrom
askoufis:fix/deep-clone-regexp

Conversation

@askoufis
Copy link
Copy Markdown
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 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
Copy Markdown
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
@askoufis askoufis deleted the fix/deep-clone-regexp branch January 24, 2025 02:55
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
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