Skip to content

Commit 8ea82ee

Browse files
committed
more tweaks
1 parent 358b5ea commit 8ea82ee

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/svelte/src/internal/client/operations.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const has_browser_globals = typeof window !== 'undefined';
77
// We cache the Node and Element prototype methods, so that subsequent calls-sites are monomorphic rather
88
// than megamorphic.
99
const node_prototype = /** @type {Node} */ (has_browser_globals ? Node.prototype : {});
10-
const html_element_prototype = /** @type {Element} */ (
11-
has_browser_globals ? HTMLElement.prototype : {}
12-
);
10+
const element_prototype = /** @type {Element} */ (has_browser_globals ? Element.prototype : {});
1311
const text_prototype = /** @type {Text} */ (has_browser_globals ? Text.prototype : {});
1412
const map_prototype = Map.prototype;
1513
const append_child_method = node_prototype.appendChild;
@@ -18,11 +16,11 @@ const map_set_method = map_prototype.set;
1816
const map_get_method = map_prototype.get;
1917
const map_delete_method = map_prototype.delete;
2018
// @ts-expect-error improve perf of expando on DOM events
21-
html_element_prototype.__click = undefined;
19+
element_prototype.__click = undefined;
2220
// @ts-expect-error improve perf of expando on DOM text updates
2321
text_prototype.__nodeValue = ' ';
2422
// @ts-expect-error improve perf of expando on DOM className updates
25-
html_element_prototype.__className = '';
23+
element_prototype.__className = '';
2624

2725
const first_child_get = /** @type {(this: Node) => ChildNode | null} */ (
2826
// @ts-ignore
@@ -39,6 +37,11 @@ const text_content_set = /** @type {(this: Node, text: string ) => void} */ (
3937
has_browser_globals ? get_descriptor(node_prototype, 'textContent').set : null
4038
);
4139

40+
const class_name_set = /** @type {(this: Element, class_name: string) => void} */ (
41+
// @ts-ignore
42+
has_browser_globals ? get_descriptor(element_prototype, 'className').set : null
43+
);
44+
4245
/**
4346
* @template {Element} E
4447
* @template {Node} T
@@ -144,6 +147,16 @@ export function sibling(node) {
144147
return next_sibling;
145148
}
146149

150+
/**
151+
* @template {Element} N
152+
* @param {N} node
153+
* @param {string} class_name
154+
* @returns {void}
155+
*/
156+
export function set_class_name(node, class_name) {
157+
class_name_set.call(node, class_name);
158+
}
159+
147160
/**
148161
* @template {Node} N
149162
* @param {N} node

packages/svelte/src/internal/client/render.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { DEV } from 'esm-env';
2-
import { append_child, child, clone_node, create_element, map_get, map_set } from './operations.js';
2+
import {
3+
append_child,
4+
child,
5+
clone_node,
6+
create_element,
7+
map_get,
8+
map_set,
9+
set_class_name
10+
} from './operations.js';
311
import {
412
create_root_block,
513
create_each_item_block,
@@ -349,7 +357,7 @@ export function class_name(dom, value) {
349357
if (next_class_name === '') {
350358
dom.removeAttribute('class');
351359
} else {
352-
dom.className = next_class_name;
360+
set_class_name(dom, next_class_name);
353361
}
354362
// @ts-expect-error need to add __className to patched prototype
355363
dom.__className = next_class_name;

0 commit comments

Comments
 (0)