Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props in svelte:component are not properly updated when there are spread props #10602

Closed
konstantinov90 opened this issue Feb 22, 2024 · 4 comments
Labels

Comments

@konstantinov90
Copy link

konstantinov90 commented Feb 22, 2024

Describe the bug

A bug was introduced In #9006

in svelte:component when there are spread props, other non spread props are lost altogether after single update

Reproduction

see
https://svelte.dev/repl/23ef1cbbb7c4485fabdba130ee49e08a?version=4.1.0 - here spread props are not updated
https://svelte.dev/repl/23ef1cbbb7c4485fabdba130ee49e08a?version=4.1.1 - here spread props ARE updated, but other non-spread props are lost altogether
https://svelte.dev/repl/23ef1cbbb7c4485fabdba130ee49e08a?version=4.2.11 - bug still reproduces

Logs

No response

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1
    Memory: 102.66 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.4.1 - /opt/homebrew/bin/npm
    pnpm: 7.9.5 - /opt/homebrew/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 121.1.62.165
    Chrome: 113.0.5672.92
    Safari: 17.2.1

Severity

blocking an upgrade

@konstantinov90
Copy link
Author

konstantinov90 commented Feb 22, 2024

possible fix

diff --git a/node_modules/svelte/src/compiler/compile/render_dom/wrappers/InlineComponent/index.js b/node_modules/svelte/src/compiler/compile/render_dom/wrappers/InlineComponent/index.js
index d5cf834..e29050b 100644
--- a/node_modules/svelte/src/compiler/compile/render_dom/wrappers/InlineComponent/index.js
+++ b/node_modules/svelte/src/compiler/compile/render_dom/wrappers/InlineComponent/index.js
@@ -277,14 +277,13 @@ export default class InlineComponentWrapper extends Wrapper {
 						// statements will become switch_props function body
 						// rewrite last statement, add props update logic
 						statements[statements.length - 1] = b`
+							for (let #i = 0; #i < ${levels}.length; #i += 1) {
+								${props} = @assign(${props}, ${levels}[#i]);
+							}
 							if (#dirty !== undefined && ${condition}) {
-								${props} = @get_spread_update(${levels}, [
+								${props} = @assign(${props}, @get_spread_update(${levels}, [
 									${changes}
-								]);
-							} else {
-								for (let #i = 0; #i < ${levels}.length; #i += 1) {
-									${props} = @assign(${props}, ${levels}[#i]);
-								}
+								]));
 							}
 						`;
 					}

@dummdidumm dummdidumm added the bug label Feb 22, 2024
@dummdidumm
Copy link
Member

PR welcome!

@konstantinov90
Copy link
Author

PR #10604

@konstantinov90
Copy link
Author

how do i do a svelte-4 fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants