Skip to content

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

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

Merged
merged 1 commit into from
Jan 24, 2025
Merged

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 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
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy