Skip to content

Commit c644c24

Browse files
committed
chore: improve code generation for bind:this in SSR mode
1 parent b5628af commit c644c24

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/brave-points-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: improve code generation for `bind:this` in SSR mode

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,9 @@ const common_visitors = {
10601060
parent.type === 'SvelteComponent' ||
10611061
parent.type === 'SvelteSelf'
10621062
) {
1063-
context.state.analysis.uses_component_bindings = true;
1063+
if (node.name !== 'this') {
1064+
context.state.analysis.uses_component_bindings = true;
1065+
}
10641066
break;
10651067
} else if (is_element_node(parent)) {
10661068
break;

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ function serialize_inline_component(node, component_name, context) {
853853

854854
const value = serialize_attribute_value(attribute.value, context, false, true);
855855
push_prop(b.prop('init', b.key(attribute.name), value));
856-
} else if (attribute.type === 'BindDirective') {
856+
} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
857857
// TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child
858858
push_prop(
859859
b.get(attribute.name, [

0 commit comments

Comments
 (0)