Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions module/dist/ai-ui.cjs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions module/dist/ai-ui.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions module/dist/ai-ui.min.cjs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions module/dist/ai-ui.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions module/dist/ai-ui.min.mjs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions module/dist/ai-ui.mjs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions module/esm/ai-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ export const tag = function (_1, _2, _3) {
},
get: (target, p, receiver) => {
if (typeof p === 'string') {
// Check if we've cached this ID already
if (p in target) {
if (this.contains(target[p]))
return target[p];
// Check the element is still contained within this element with the same ID
const ref = target[p].deref();
if (ref && ref.id === p && this.contains(ref))
return ref;
delete target[p];
}
let e;
Expand All @@ -143,7 +146,7 @@ export const tag = function (_1, _2, _3) {
e = this.querySelector('#' + CSS.escape(p)) ?? undefined;
}
if (e)
target[p] = e;
target[p] = new WeakRef(e);
return e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
},
"type": "module",
"types": "./esm/ai-ui.d.ts",
"version": "0.15.1"
"version": "0.15.2"
}
11 changes: 7 additions & 4 deletions module/src/ai-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const tag = <TagLoader>function <Tags extends string,
set: idsInaccessible,
get(this: Element) {
// Now we've been accessed, create the proxy
const idProxy = new Proxy(Object.create(null), {
const idProxy = new Proxy(Object.create(null) as Record<string, WeakRef<Element>>, {
apply: idsInaccessible,
construct: idsInaccessible,
defineProperty: idsInaccessible,
Expand All @@ -211,9 +211,12 @@ export const tag = <TagLoader>function <Tags extends string,
},
get: (target, p, receiver) => {
if (typeof p === 'string') {
// Check if we've cached this ID already
if (p in target) {
if (this.contains(target[p]))
return target[p];
// Check the element is still contained within this element with the same ID
const ref = target[p].deref();
if (ref && ref.id === p && this.contains(ref))
return ref;
delete target[p];
}
let e: Element | undefined;
Expand All @@ -229,7 +232,7 @@ export const tag = <TagLoader>function <Tags extends string,
} else {
e = this.querySelector('#' + CSS.escape(p)) ?? undefined;
}
if (e) target[p] = e;
if (e) target[p] = new WeakRef(e);
return e;
}
}
Expand Down