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

Initial data seems to be not affecting the window scroll binding #938

Closed
emirotin opened this issue Nov 22, 2017 · 8 comments · Fixed by #1382
Closed

Initial data seems to be not affecting the window scroll binding #938

emirotin opened this issue Nov 22, 2017 · 8 comments · Fixed by #1382
Labels
Projects

Comments

@emirotin
Copy link

I should mentions it's by no means a problem for my real project but I decided it might be worth sharing.
It looks like if we bind a value to window's scrollY the components' initial data (both default or passed to the constructor) is thrown away and replaced with the actual scroll position which is usually 0;

Repro: https://svelte.technology/repl?version=1.42.0&gist=2afe785004bcdc4c1bcca6f03f2ed7f9

@esarbanis
Copy link
Contributor

The REPL you provided is broken cause the state is not in proper json format. You need to put quotes on y and everything works as expected REPL

@emirotin
Copy link
Author

emirotin commented Nov 22, 2017 via email

@esarbanis
Copy link
Contributor

It is true that REPL is poorly documented, but if you check out the examples you can kind of understand its usage. I agree that it needs proper documentation.

Another thing is that REPL is compiled on load and I believe it is not recompiled after the changes. That is why when you remove the field the state does not change. See this REPL which uses an empty object.

@Rich-Harris
Copy link
Member

The REPL is supposed to show an error if the data is invalid JSON. Will raise an issue about that.

It's weird that it doesn't respect the data provided by the component itself — definitely a bug.

@emirotin
Copy link
Author

emirotin commented Nov 22, 2017 via email

@esarbanis
Copy link
Contributor

@Rich-Harris the original REPL of this issue does prompt you with (2:1) Unexpected token y, so I guess there is no bug there.

On the other hand, how would a component know if a data field was deleted? If you try to change the value, then it works OK, but if you remove the data.y, I guess the component needs to be re-compiled. Am I wrong?

A cool feature in REPL though, would be to have a re-compile button.

@emirotin
Copy link
Author

emirotin commented Nov 22, 2017

Indeed my original repl does show the error, I didn't notice it (which is bad for me, but also fro the UX:)
I confirm that both fixing it to be valid JSON works, and changing the state to empty but setting y in the default data doesn't have effect which looks like a bug (https://svelte.technology/repl?version=1.42.0&gist=513b0e3994295119a4d7476b547f4893).

@arxpoetica arxpoetica added this to Triage in Roadmap Jan 10, 2018
@arxpoetica arxpoetica moved this from Triage to Medium term in Roadmap Jan 10, 2018
Rich-Harris added a commit that referenced this issue Oct 28, 2018
Rich-Harris added a commit that referenced this issue Oct 28, 2018
Rich-Harris added a commit that referenced this issue Oct 28, 2018
set window scroll from bindings on initialisation
@Rich-Harris
Copy link
Member

Fixed in 2.15, finally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
  
Medium term
Development

Successfully merging a pull request may close this issue.

3 participants