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; |
| global.File = FilePolyfill; | ||
|
|
||
| // Polyfill structuredClone for jsdom. | ||
| global.structuredClone = structuredClone; |
There was a problem hiding this comment.
@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.
I tried that initially, but unfortunately, it doesn't work.
There was a problem hiding this comment.
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
structuredCloneinstead ofJSON.parse( JSON.stringify( value ) )hack.Testing Instructions
omitStylesunit tests are passing.Testing Instructions for Keyboard
Same.