happy-dom 14.11.0 → 14.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (51) hide show
  1. package/cjs/PropertySymbol.cjs +3 -1
  2. package/cjs/PropertySymbol.cjs.map +1 -1
  3. package/cjs/PropertySymbol.d.ts +2 -0
  4. package/cjs/PropertySymbol.d.ts.map +1 -1
  5. package/cjs/nodes/html-element/HTMLElement.cjs +14 -1
  6. package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
  7. package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
  8. package/cjs/nodes/html-style-element/HTMLStyleElement.cjs +15 -11
  9. package/cjs/nodes/html-style-element/HTMLStyleElement.cjs.map +1 -1
  10. package/cjs/nodes/html-style-element/HTMLStyleElement.d.ts +5 -0
  11. package/cjs/nodes/html-style-element/HTMLStyleElement.d.ts.map +1 -1
  12. package/cjs/nodes/node/Node.cjs +27 -6
  13. package/cjs/nodes/node/Node.cjs.map +1 -1
  14. package/cjs/nodes/node/Node.d.ts +1 -0
  15. package/cjs/nodes/node/Node.d.ts.map +1 -1
  16. package/cjs/nodes/text/Text.cjs +3 -0
  17. package/cjs/nodes/text/Text.cjs.map +1 -1
  18. package/cjs/nodes/text/Text.d.ts.map +1 -1
  19. package/cjs/window/BrowserWindow.cjs +9 -6
  20. package/cjs/window/BrowserWindow.cjs.map +1 -1
  21. package/cjs/window/BrowserWindow.d.ts +2 -0
  22. package/cjs/window/BrowserWindow.d.ts.map +1 -1
  23. package/lib/PropertySymbol.d.ts +2 -0
  24. package/lib/PropertySymbol.d.ts.map +1 -1
  25. package/lib/PropertySymbol.js +2 -0
  26. package/lib/PropertySymbol.js.map +1 -1
  27. package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
  28. package/lib/nodes/html-element/HTMLElement.js +14 -1
  29. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  30. package/lib/nodes/html-style-element/HTMLStyleElement.d.ts +5 -0
  31. package/lib/nodes/html-style-element/HTMLStyleElement.d.ts.map +1 -1
  32. package/lib/nodes/html-style-element/HTMLStyleElement.js +15 -11
  33. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  34. package/lib/nodes/node/Node.d.ts +1 -0
  35. package/lib/nodes/node/Node.d.ts.map +1 -1
  36. package/lib/nodes/node/Node.js +27 -6
  37. package/lib/nodes/node/Node.js.map +1 -1
  38. package/lib/nodes/text/Text.d.ts.map +1 -1
  39. package/lib/nodes/text/Text.js +3 -0
  40. package/lib/nodes/text/Text.js.map +1 -1
  41. package/lib/window/BrowserWindow.d.ts +2 -0
  42. package/lib/window/BrowserWindow.d.ts.map +1 -1
  43. package/lib/window/BrowserWindow.js +9 -6
  44. package/lib/window/BrowserWindow.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/PropertySymbol.ts +2 -0
  47. package/src/nodes/html-element/HTMLElement.ts +17 -1
  48. package/src/nodes/html-style-element/HTMLStyleElement.ts +14 -9
  49. package/src/nodes/node/Node.ts +27 -2
  50. package/src/nodes/text/Text.ts +4 -0
  51. package/src/window/BrowserWindow.ts +6 -1
@@ -11,6 +11,7 @@ import Node from '../node/Node.js';
11
11
  */
12
12
  export default class HTMLStyleElement extends HTMLElement {
13
13
  private [PropertySymbol.sheet]: CSSStyleSheet | null = null;
14
+ public [PropertySymbol.styleNode] = this;
14
15
 
15
16
  /**
16
17
  * Returns CSS style sheet.
@@ -84,9 +85,7 @@ export default class HTMLStyleElement extends HTMLElement {
84
85
  */
85
86
  public override [PropertySymbol.appendChild](node: Node): Node {
86
87
  const returnValue = super[PropertySymbol.appendChild](node);
87
- if (this[PropertySymbol.sheet]) {
88
- this[PropertySymbol.sheet].replaceSync(this.textContent);
89
- }
88
+ this[PropertySymbol.updateSheet]();
90
89
  return returnValue;
91
90
  }
92
91
 
@@ -95,9 +94,7 @@ export default class HTMLStyleElement extends HTMLElement {
95
94
  */
96
95
  public override [PropertySymbol.removeChild](node: Node): Node {
97
96
  const returnValue = super[PropertySymbol.removeChild](node);
98
- if (this[PropertySymbol.sheet]) {
99
- this[PropertySymbol.sheet].replaceSync(this.textContent);
100
- }
97
+ this[PropertySymbol.updateSheet]();
101
98
  return returnValue;
102
99
  }
103
100
 
@@ -106,9 +103,7 @@ export default class HTMLStyleElement extends HTMLElement {
106
103
  */
107
104
  public override [PropertySymbol.insertBefore](newNode: Node, referenceNode: Node | null): Node {
108
105
  const returnValue = super[PropertySymbol.insertBefore](newNode, referenceNode);
109
- if (this[PropertySymbol.sheet]) {
110
- this[PropertySymbol.sheet].replaceSync(this.textContent);
111
- }
106
+ this[PropertySymbol.updateSheet]();
112
107
  return returnValue;
113
108
  }
114
109
 
@@ -125,4 +120,14 @@ export default class HTMLStyleElement extends HTMLElement {
125
120
  this[PropertySymbol.sheet] = null;
126
121
  }
127
122
  }
123
+
124
+ /**
125
+ * Updates the CSSStyleSheet with the text content.
126
+ */
127
+ public [PropertySymbol.updateSheet](): void {
128
+ if (this[PropertySymbol.sheet]) {
129
+ this[PropertySymbol.ownerDocument][PropertySymbol.cacheID]++;
130
+ this[PropertySymbol.sheet].replaceSync(this.textContent);
131
+ }
132
+ }
128
133
  }
@@ -61,6 +61,7 @@ export default class Node extends EventTarget {
61
61
  public [PropertySymbol.formNode]: Node = null;
62
62
  public [PropertySymbol.selectNode]: Node = null;
63
63
  public [PropertySymbol.textAreaNode]: Node = null;
64
+ public [PropertySymbol.styleNode]: Node = null;
64
65
  public [PropertySymbol.observers]: MutationListener[] = [];
65
66
  public [PropertySymbol.childNodes]: NodeList<Node> = new NodeList<Node>();
66
67
 
@@ -516,6 +517,7 @@ export default class Node extends EventTarget {
516
517
  const formNode = (<Node>this)[PropertySymbol.formNode];
517
518
  const selectNode = (<Node>this)[PropertySymbol.selectNode];
518
519
  const textAreaNode = (<Node>this)[PropertySymbol.textAreaNode];
520
+ const styleNode = (<Node>this)[PropertySymbol.styleNode];
519
521
 
520
522
  if (this[PropertySymbol.nodeType] !== NodeTypeEnum.documentFragmentNode) {
521
523
  this[PropertySymbol.parentNode] = parentNode;
@@ -539,6 +541,12 @@ export default class Node extends EventTarget {
539
541
  ? (<Node>parentNode)[PropertySymbol.textAreaNode]
540
542
  : null;
541
543
  }
544
+
545
+ if (this['tagName'] !== 'STYLE') {
546
+ (<Node>this)[PropertySymbol.styleNode] = parentNode
547
+ ? (<Node>parentNode)[PropertySymbol.styleNode]
548
+ : null;
549
+ }
542
550
  }
543
551
 
544
552
  if (this[PropertySymbol.isConnected] !== isConnected) {
@@ -551,7 +559,23 @@ export default class Node extends EventTarget {
551
559
  }
552
560
 
553
561
  if (isConnected && this.connectedCallback) {
554
- this.connectedCallback();
562
+ const result = <void | Promise<void>>this.connectedCallback();
563
+ /**
564
+ * It is common to import dependencies in the connectedCallback() method of web components.
565
+ * As Happy DOM doesn't have support for dynamic imports yet, this is a temporary solution to wait for imports in connectedCallback().
566
+ *
567
+ * @see https://github.com/capricorn86/happy-dom/issues/1442
568
+ */
569
+ if (result instanceof Promise) {
570
+ const asyncTaskManager =
571
+ this[PropertySymbol.ownerDocument][PropertySymbol.ownerWindow][
572
+ PropertySymbol.asyncTaskManager
573
+ ];
574
+ const taskID = asyncTaskManager.startTask();
575
+ result
576
+ .then(() => asyncTaskManager.endTask(taskID))
577
+ .catch(() => asyncTaskManager.endTask(taskID));
578
+ }
555
579
  } else if (!isConnected && this.disconnectedCallback) {
556
580
  this.disconnectedCallback();
557
581
  }
@@ -568,7 +592,8 @@ export default class Node extends EventTarget {
568
592
  } else if (
569
593
  formNode !== this[PropertySymbol.formNode] ||
570
594
  selectNode !== this[PropertySymbol.selectNode] ||
571
- textAreaNode !== this[PropertySymbol.textAreaNode]
595
+ textAreaNode !== this[PropertySymbol.textAreaNode] ||
596
+ styleNode !== this[PropertySymbol.styleNode]
572
597
  ) {
573
598
  for (const child of this[PropertySymbol.childNodes]) {
574
599
  (<Node>child)[PropertySymbol.connectToNode](this);
@@ -38,6 +38,10 @@ export default class Text extends CharacterData {
38
38
  if (this[PropertySymbol.textAreaNode]) {
39
39
  (<HTMLTextAreaElement>this[PropertySymbol.textAreaNode])[PropertySymbol.resetSelection]();
40
40
  }
41
+
42
+ if (this[PropertySymbol.styleNode]) {
43
+ this[PropertySymbol.styleNode][PropertySymbol.updateSheet]();
44
+ }
41
45
  }
42
46
 
43
47
  /**
@@ -153,6 +153,7 @@ import RangeImplementation from '../range/Range.js';
153
153
  import INodeJSGlobal from './INodeJSGlobal.js';
154
154
  import CrossOriginBrowserWindow from './CrossOriginBrowserWindow.js';
155
155
  import Response from '../fetch/Response.js';
156
+ import AsyncTaskManager from '../async-task-manager/AsyncTaskManager.js';
156
157
 
157
158
  const TIMER = {
158
159
  setTimeout: globalThis.setTimeout.bind(globalThis),
@@ -495,6 +496,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
495
496
  public [PropertySymbol.captureEventListenerCount]: { [eventType: string]: number } = {};
496
497
  public readonly [PropertySymbol.mutationObservers]: MutationObserver[] = [];
497
498
  public readonly [PropertySymbol.readyStateManager] = new DocumentReadyStateManager(this);
499
+ public [PropertySymbol.asyncTaskManager]: AsyncTaskManager | null = null;
498
500
  public [PropertySymbol.location]: Location;
499
501
  public [PropertySymbol.history]: History;
500
502
  public [PropertySymbol.navigator]: Navigator;
@@ -520,6 +522,8 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
520
522
  constructor(browserFrame: IBrowserFrame, options?: { url?: string }) {
521
523
  super();
522
524
 
525
+ const asyncTaskManager = browserFrame[PropertySymbol.asyncTaskManager];
526
+
523
527
  this.#browserFrame = browserFrame;
524
528
 
525
529
  this.customElements = new CustomElementRegistry(this);
@@ -529,13 +533,13 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
529
533
  this[PropertySymbol.sessionStorage] = StorageFactory.createStorage();
530
534
  this[PropertySymbol.localStorage] = StorageFactory.createStorage();
531
535
  this[PropertySymbol.location] = new Location(this.#browserFrame, options?.url ?? 'about:blank');
536
+ this[PropertySymbol.asyncTaskManager] = asyncTaskManager;
532
537
 
533
538
  this.console = browserFrame.page.console;
534
539
 
535
540
  WindowBrowserSettingsReader.setSettings(this, this.#browserFrame.page.context.browser.settings);
536
541
 
537
542
  const window = this;
538
- const asyncTaskManager = this.#browserFrame[PropertySymbol.asyncTaskManager];
539
543
 
540
544
  this[PropertySymbol.setupVMContext]();
541
545
 
@@ -1302,6 +1306,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
1302
1306
  }
1303
1307
 
1304
1308
  (<boolean>this.closed) = true;
1309
+ this[PropertySymbol.asyncTaskManager] = null;
1305
1310
  this.Audio[PropertySymbol.ownerDocument] = null;
1306
1311
  this.Image[PropertySymbol.ownerDocument] = null;
1307
1312
  this.DocumentFragment[PropertySymbol.ownerDocument] = null;