capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.09k stars 185 forks source link

new Text() class gives 'Failed to construct "Node": No owner document in queue' #1387

Closed UserNobody14 closed 3 months ago

UserNobody14 commented 3 months ago

Describe the bug When new Text() is called, happy-dom throws the error: image

To Reproduce Steps to reproduce the behavior:

  1. In an empty directory, create a file named checkbun.test.ts, and put the following into it:
    
    import { GlobalRegistrator } from "@happy-dom/global-registrator";
    import { describe, it } from 'bun:test';

GlobalRegistrator.register();

describe('Should make a text node', () => { it('Should make a text node', () => { // alternatively you can just call new Text('test') by itself to view the stacktrace a bit easier. // const alternativeTest = new Text('test'); expect(() => new Text('test')).not.toThrow(); }); });


2. run "bun add -D \@happydom/global-registrator"
3. run "bun test"

Same issue can be reproduced on vitest:

1. Go to vitest.new
2. Add "happy-dom": latest to package.json and rerun npm install
3. Go to vite.config.ts and set the environment to "happy-dom"
4. Add "const myTest = Text('whatever');" to any of the tests, and they will throw the same error

**Expected behavior**
A new text node that can be tested with, and no error

**Screenshots**
![image](https://github.com/capricorn86/happy-dom/assets/38988442/52fbcacd-681d-4a5d-997c-b5e28196dd0e)
![image](https://github.com/capricorn86/happy-dom/assets/38988442/4a786d3a-f870-4677-ac0d-6b9933cdc082)

**Device:**
 - OS: Linux Mint
 - Runner: bun 1.0.35 (940448d6)
 - Version: 14.6.2

**Additional context**
May be related to the error in [this issue](https://github.com/oven-sh/bun/issues/8669#issuecomment-1983751824). It gives an error no matter what's provided to the Text constructor, empty string or no. 
Discovered this while testing a library I'm working on. Not sure what's causing the issue exactly but given how critical the Text node class can be, I assume this isn't intentional or desired. I'm gonna look into this further and see whether I can figure out whether I can figure out a solution, wanted to bring this to everyone's attention in case someone knew more than me about it.
capricorn86 commented 3 months ago

Thank you for reporting @UserNobody14! :slightly_smiling_face:

This has been fixed now: https://github.com/capricorn86/happy-dom/releases/tag/v14.7.0