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

fix set store value ssr #5419

Merged
merged 8 commits into from Jan 4, 2021

Conversation

tanhauhau
Copy link
Member

@tanhauhau tanhauhau commented Sep 17, 2020

Closes #3375

Have to instrument setting store variable, store to sync up the dollar-prefixed variable, $store to simulate the same behavior in DOM.

An alternative would be to subscribe to store at the early of the component, and make sure to unsubscribe them right before rendering them.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@tanhauhau tanhauhau mentioned this pull request Sep 17, 2020
4 tasks
@Conduitry
Copy link
Member

Conduitry commented Sep 18, 2020

Should the description here say 'fixes #3375 and closes #4195'?

@Conduitry
Copy link
Member

Does this seem like a good base to start from when fixing #3582 / #3636? And/or does it make sense to also fix those in this PR?

@tanhauhau
Copy link
Member Author

wow, the 2 issues seems hard, especially, it is modifying the store directly via store.set() for example.

1 alternative i can think of it is to subscribe to the store early on, which the listener can keep updating $-prefixed variable, and unsubscribe right before returning the rendered result.

what do you think?

@Conduitry
Copy link
Member

I think having a subscription to the store throughout the SSR'd component that gets unsubscribed at the end makes sense. It does sound like that would help with those other issues - and if we can align what the SSR component does more closely with what the browser component does, that sounds like a good idea.

@Conduitry
Copy link
Member

I saw you mention this PR in #5452 ... Is this PR fixing an observable bug? #3375 just sounded like some suboptimal code getting generated. How does what this is fixing compare to #3582 and #3636?

@tanhauhau
Copy link
Member Author

probably im gonna change the implementation of this PR / start a new PR that does "having a subscription to the store throughout the SSR'd component that gets unsubscribed at the end"

that would theoratically solve most of the ssr + svelte store issues.

#3375's suboptimal code is because, svelte store value can be changed throughout the main code, via store.set() or store.update(). so a safe way to make sure that the $store values is up to date, we read from the store once last time before returning.

again, if we change the store mechanism in ssr, having a subscription, we can probably remove that part of the code too.

@Conduitry Conduitry marked this pull request as draft September 29, 2020 15:20
@Conduitry
Copy link
Member

I'm marking this as draft. If you'd prefer to rework SSR store subscription in a separate PR, this can be closed.

@@ -0,0 +1,3 @@
export default {
html: `{"answer":4}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rebase against master and make sure npm run lint passes? we just updated our eslint config to allow only single quotes

@arackaf
Copy link
Contributor

arackaf commented Nov 18, 2020

@Conduitry @antony

Other than the linting problems described above, is there anything else preventing this PR from being merged? I'd be happy to rebase and fix the lint errors if it'll help get this merged.

@tanhauhau
Copy link
Member Author

@arackaf there's some edge cases that this MR didn't manage to fix as mentioned in #5419 (comment), I'll probably relook again soon

@arackaf
Copy link
Contributor

arackaf commented Nov 18, 2020

@tanhauhau if you're still planning on taking a closer look to solve those other edge cases then cool, I'll leave you to it.

But if you decide to move on, I'd be more than happy to help get this incomplete solution in, since, iiuc, it does solve some problems.

@cortopy
Copy link

cortopy commented Dec 7, 2020

any change this could be merged?

My use case would be fixed with this and I suspect many other people would benefit from this early implementation

If there are any edge cases not covered, could they not be treated as an improvement to work on in a different PR?

@tanhauhau tanhauhau marked this pull request as ready for review December 30, 2020 09:56
@Conduitry Conduitry merged commit 82fcdfc into sveltejs:master Jan 4, 2021
@tanhauhau tanhauhau deleted the tanhauhau/fix-store-value branch February 11, 2021 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_store_value() called twice in SSR mode
5 participants