mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 03:33:12 +08:00
Merge remote-tracking branch 'refs/remotes/origin/fix/happy-dom-process-variable' into fix/happy-dom-process-variable
This commit is contained in:
commit
c0bad9fce0
@ -2,6 +2,14 @@ import type { DOMParser as HappyDOMParser, Window as HappyDOMWindow } from 'happ
|
|||||||
|
|
||||||
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
|
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a safe DOMParser instance by wrapping `happy-dom`'s `DOMParser`.
|
||||||
|
* This function ensures that the original `process` is preserved by using
|
||||||
|
* `preserveAndRestoreNodeInternals`.
|
||||||
|
*
|
||||||
|
* @param {HappyDOMWindow} window - The `happy-dom` window object to use for the parser.
|
||||||
|
* @returns {HappyDOMParser} A new instance of `happy-dom`'s `DOMParser`.
|
||||||
|
*/
|
||||||
export function createSafeParser(window: HappyDOMWindow) {
|
export function createSafeParser(window: HappyDOMWindow) {
|
||||||
return preserveAndRestoreNodeInternals(() => {
|
return preserveAndRestoreNodeInternals(() => {
|
||||||
const { DOMParser } = require('happy-dom-without-node')
|
const { DOMParser } = require('happy-dom-without-node')
|
||||||
|
@ -2,6 +2,13 @@ import type { Window as HappyDOMWindow } from 'happy-dom-without-node'
|
|||||||
|
|
||||||
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
|
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new `Window` instance using `happy-dom` and ensures that the original
|
||||||
|
* `process` object is restored after the operation. This function wraps the
|
||||||
|
* creation of the `Window` object to provide a safe environment for DOM manipulation.
|
||||||
|
*
|
||||||
|
* @returns {HappyDOMWindow} A new `Window` instance from `happy-dom`.
|
||||||
|
*/
|
||||||
export function createSafeWindow() {
|
export function createSafeWindow() {
|
||||||
return preserveAndRestoreNodeInternals(() => {
|
return preserveAndRestoreNodeInternals(() => {
|
||||||
const { Window } = require('happy-dom-without-node')
|
const { Window } = require('happy-dom-without-node')
|
||||||
|
@ -7,7 +7,7 @@ export function preserveAndRestoreNodeInternals<T>(operation: () => T): T {
|
|||||||
// Store the original process object
|
// Store the original process object
|
||||||
// see https://github.com/ueberdosis/tiptap/issues/6368
|
// see https://github.com/ueberdosis/tiptap/issues/6368
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const originalProcess = globalThis?.process
|
const originalProcess = globalThis.process
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return operation()
|
return operation()
|
||||||
|
Loading…
Reference in New Issue
Block a user