Skip to content

Commit e0832fc

Browse files
committed
Create a proper DeviceViewport interface
1 parent 20e3ca1 commit e0832fc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/webflo-runtime/webflo-client/DeviceViewport.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class DeviceViewport {
6969
#render() {
7070
const state = this.peek();
7171
const viewportDirectives = [];
72-
const activeKeys = new Set(Object.keys(state).filter(k => !k.startsWith('_')));
72+
const activeKeys = new Set(Object.keys(state).filter(k => k !== 'id' && !k.startsWith('_')));
7373

7474
// 1. Handle Title
7575
if ('title' in state) {
@@ -131,26 +131,29 @@ export class DeviceViewport {
131131
#setAttr(jsKey, val, media = null) {
132132
const cacheKey = media ? `${jsKey}-${media}` : jsKey;
133133
const config = this.#specials[jsKey];
134+
const attrName = config.type === 'link' ? 'href' : 'content';
134135

135136
if (val !== undefined && val !== null) {
136137
const el = this.#getOrCreate(jsKey, media);
137-
el.setAttribute(config.type === 'link' ? 'href' : 'content', val);
138+
if (el.getAttribute(attrName) !== val) {
139+
el.setAttribute(attrName, val);
140+
}
138141
} else {
139142
const el = this.#elements[cacheKey];
140143
if (el) {
141144
if (this.#ownedElements.has(el)) {
142145
el.remove();
143146
delete this.#elements[cacheKey];
144-
} else {
145-
el.setAttribute(config.type === 'link' ? 'href' : 'content', '');
147+
} else if (el.getAttribute(attrName) !== '') {
148+
el.setAttribute(attrName, '');
146149
}
147150
}
148151
}
149152
}
150153

151154
#parseViewport = (c) => Object.fromEntries(c.split(',').filter(Boolean).map(s => {
152155
const [k, v] = s.split('=').map(p => p.trim());
153-
return [k.replace(/-([a-z])/g, g => g.toUpperCase()), v || true];
156+
return [k.replace(/-([a-z])/g, g => g[1].toUpperCase()), v || true];
154157
}));
155158

156159
push(id, config) {

0 commit comments

Comments
 (0)