Skip to content
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

(regression) TypeError: Cannot set property loading of [object Object] which has only a getter #1218

Closed
Yberion opened this issue Jan 16, 2024 · 4 comments · Fixed by #1297
Closed
Assignees
Labels
bug Something isn't working

Comments

@Yberion
Copy link

Yberion commented Jan 16, 2024

Describe the bug

Hello, on my Angular application I'm using this lib https://github.com/justinribeiro/lite-youtube.

When testing a component that uses this lib with Vitest (I import the lib in the test setup) and happy-dom, on versions before 13.1.0 I had no problem rendering the Angular component on happy-dom.

Since 13.1.0 I'm getting the following error:

TypeError: Cannot set property loading of [object Object] which has only a getter
 ❯ LiteYTEmbed.initImagePlaceholder ../../../../../node_modules/.pnpm/@justinribeiro+lite-youtube@1.5.0/node_modules/@justinribeiro/lite-youtube/lite-youtube.js:227:41
 ❯ LiteYTEmbed.setupComponent ../../../../../node_modules/.pnpm/@justinribeiro+lite-youtube@1.5.0/node_modules/@justinribeiro/lite-youtube/lite-youtube.js:164:14
 ❯ LiteYTEmbed.attributeChangedCallback ../../../../../node_modules/.pnpm/@justinribeiro+lite-youtube@1.5.0/node_modules/@justinribeiro/lite-youtube/lite-youtube.js:178:26
 ❯ _ZoneDelegate.invoke ../../../../../node_modules/.pnpm/zone.js@0.14.3/node_modules/zone.js/bundles/zone.umd.js:411:30
 ❯ Zone.runGuarded ../../../../../node_modules/.pnpm/zone.js@0.14.3/node_modules/zone.js/bundles/zone.umd.js:176:51
 ❯ LiteYTEmbed.<anonymous> ../../../../../node_modules/.pnpm/zone.js@0.14.3/node_modules/zone.js/bundles/zone.umd.js:159:33
 ❯ HTMLElementNamedNodeMap.setNamedItem ../../../../../node_modules/.pnpm/happy-dom@13.1.4/node_modules/happy-dom/lib/nodes/element/ElementNamedNodeMap.js:66:47     
 ❯ HTMLElementNamedNodeMap.setNamedItem ../../../../../node_modules/.pnpm/happy-dom@13.1.4/node_modules/happy-dom/lib/nodes/html-element/HTMLElementNamedNodeMap.js:13:36
 ❯ LiteYTEmbed.setAttributeNode ../../../../../node_modules/.pnpm/happy-dom@13.1.4/node_modules/happy-dom/lib/nodes/element/Element.js:801:48
 ❯ LiteYTEmbed.setAttribute ../../../../../node_modules/.pnpm/happy-dom@13.1.4/node_modules/happy-dom/lib/nodes/element/Element.js:554:14

The path to the code:

TS

JS

I think the regression is related to:

Expected behavior

No error as before and on the browser.

@Yberion Yberion added the bug Something isn't working label Jan 16, 2024
@notTGY
Copy link

notTGY commented Mar 9, 2024

looks like #655 had the same error.

I also encountered this issue while trying to assign loading='lazy' to HTMLImageElement like so:

import { Window } from 'happy-dom'

const window = new Window()
const document = window.document

document.body.innerHTML = '<img>'
const $0 = document.getElementsByTagName('img')[0]

$0.loading = 'lazy'
console.log($0.loading) // 'auto'

It only has getter defined here unlike other properties, which also have setters.

@Yberion
Copy link
Author

Yberion commented Mar 11, 2024

Yeah and the problem only appeared after #1209

@capricorn86 capricorn86 self-assigned this Mar 11, 2024
capricorn86 added a commit that referenced this issue Mar 11, 2024
…annot-set-property-loading-of-object-object-which-has-only-a-getter

fix: [#1218] Adds missing setter for the HTMLImageElement.loading pro…
@capricorn86
Copy link
Owner

Thank you for reporting @Yberion and @notTGY! 🙂

There is a fix in now:
https://github.com/capricorn86/happy-dom/releases/tag/v13.7.7

@Yberion
Copy link
Author

Yberion commented Mar 12, 2024

Thank you for reporting @Yberion and @notTGY! 🙂

There is a fix in now: https://github.com/capricorn86/happy-dom/releases/tag/v13.7.7

Hello @capricorn86, thanks a lot for the fix, I can confirm it fixed my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants