delete in removeAttribute causes TypeError
CetinSert opened this issue ยท 7 comments
Please note that in the following only the second delete
is in a try
catch
:
diffhtml/packages/diffhtml/lib/node/patch.js
Lines 87 to 105 in cab7fb3
The first delete
in
causes https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete exceptions for some web components that implement attribute โ property reflection with Object.defineProperty
.
Can you post an example of what is breaking? The first delete is not in a try/catch intentionally for performance reasons. This code attempts to delete a property and if it succeeds, marks that property as safe for a given tag name. That's the only way the first delete will be reached.
Here is an absolutely minimal case: https://tw.uido.co/test/index.html
<script src="//webpdf.co/<>" type=module></script>
<pdf-file id=f src=//pdf.ist/web.pdf></pdf-file>
<div id=i><pdf-page off=f></pdf-page></div>
<script type=module>
import * as diff from '//esm.run/diffhtml'; window.diff = diff;
await customElements.whenDefined('pdf-page');
await diff.innerHTML(i, `<pdf-page of=f></pdf-page>`); // patch.js setAttribute does allowlist.add(blocklistName)
await diff.innerHTML(i, `<pdf-page off=f></pdf-page>`); // patch.js removeAttribute checks allowlist TypeError
</script>
The of
attribute is defined using Object.defineProperty
(with configurable
set to false
; as is default).
So of
- can be
set
(setAttribute
extendsallowlist
)
but - cannot be
delete
d (removeAttribute
check sameallowlist
)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete#examples
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#configurable
diffhtml/packages/diffhtml/lib/node/patch.js
Lines 92 to 94 in cab7fb3
setAttribute
and removeAttribute
would need different
allowlist
s
orblocklistName
s
for HTML custom elements that define attribute
โ property
mirroring via Object.defineProperty
.
@tbranyen โ I have demoed and described the problem/solution in the above 2 comments.
Fix opened here @CetinSert #262
Darnit, so my Travis CI account just ran out of open source credits. The credits should reset in an hour and a half when the new month starts. Would be awesome to convert this project to GitHub Actions CI infra instead.