mirror of https://github.com/sveltejs/svelte
fix: avoid creating unnnecessary deriveds for text nodes with call (#13206)
The build_template function was called but the result was potentially unused, causing unnecessary code output Found in https://github.com/sveltejs/svelte/pull/13171#issuecomment-2343763030pull/13217/head
parent
93f8329b1b
commit
3d5702aa8f
@ -0,0 +1,26 @@
|
||||
import "svelte/internal/disclose-version";
|
||||
import * as $ from "svelte/internal/client";
|
||||
|
||||
var root = $.template(`<p> </p>`);
|
||||
|
||||
export default function Text_nodes_deriveds($$anchor) {
|
||||
let count1 = 0;
|
||||
let count2 = 0;
|
||||
|
||||
function text1() {
|
||||
return count1;
|
||||
}
|
||||
|
||||
function text2() {
|
||||
return count2;
|
||||
}
|
||||
|
||||
var p = root();
|
||||
const stringified_text = $.derived(() => text1() ?? "");
|
||||
const stringified_text_1 = $.derived(() => text2() ?? "");
|
||||
var text = $.child(p);
|
||||
|
||||
$.template_effect(() => $.set_text(text, `${$.get(stringified_text)}${$.get(stringified_text_1)}`));
|
||||
$.reset(p);
|
||||
$.append($$anchor, p);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import * as $ from "svelte/internal/server";
|
||||
|
||||
export default function Text_nodes_deriveds($$payload) {
|
||||
let count1 = 0;
|
||||
let count2 = 0;
|
||||
|
||||
function text1() {
|
||||
return count1;
|
||||
}
|
||||
|
||||
function text2() {
|
||||
return count2;
|
||||
}
|
||||
|
||||
$$payload.out += `<p>${$.escape(text1())}${$.escape(text2())}</p>`;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
let count1=$state(0);
|
||||
let count2=$state(0);
|
||||
|
||||
function text1(){
|
||||
return count1;
|
||||
}
|
||||
|
||||
function text2(){
|
||||
return count2;
|
||||
}
|
||||
</script>
|
||||
|
||||
<p>{text1()}{text2()}</p>
|
Loading…
Reference in new issue