-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Replace remaining custom deep cloning with 'structuredClone' #67707
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -8 B (0%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
Flaky tests detected in 4fec584. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12211324308
|
The Should I patch it in the tests? That might mean we get different behavior with actual code and tests. |
Could you add it to |
Can we do that without overriding the |
How come, I think we use the
So you can't just use the underlying Node.js modules like this (please correct me if I'm missing something). An easy alternative would be to import the core-js polyfill in import 'core-js/stable/structured-clone'; and then you will be able to expose that as a jsdom global: global.structuredClone = structuredClone; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this is good to go 👍
I'll let @jsnajdr do the final review since I suggested part of the code, so I'm biased 😅
@@ -49,3 +50,6 @@ if ( ! global.TextEncoder ) { | |||
// Override jsdom built-ins with native node implementation. | |||
global.Blob = BlobPolyfill; | |||
global.File = FilePolyfill; | |||
|
|||
// Polyfill structuredClone for jsdom. | |||
global.structuredClone = structuredClone; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyxla writes:
So you can't just use the underlying Node.js modules like this (please correct me if I'm missing something).
The jsdom
environment creates a new global object for the environment, but it still runs in Node.js. If native structuredClone
is available in Node.js, then you should be able to "forward" it from the Node.js global to the jsdom
global.
Could the global.structuredClone = structuredClone
assignment work without importing the CoreJS polyfill? If the structuredClone
reference uses the Node.js globalThis
, it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that initially, but unfortunately, it doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK then let's do the CoreJS version.
…ss#67707) * Replace remaining custom deep cloning with 'structuredClone' * Polyfill structuredClone for jsdom Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
What?
This is similar to #64203.
PR updates remaining places in editors' codebase to use
structuredClone
instead ofJSON.parse( JSON.stringify( value ) )
hack.Testing Instructions
omitStyles
unit tests are passing.Testing Instructions for Keyboard
Same.