-
Notifications
You must be signed in to change notification settings - Fork 9
SSR support #8
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
SSR support #8
Conversation
There are some little problems with this feature: I noticed that I could not use the You can see that state serializing is hard - user should get state, then remove router state and serialize. Full state serialization is much easier for user, but we can't, because Can we remove the use of |
Removal is undesirable. The presence of a symbol separates the user namespace and the service. |
I understand. But there are many problems with Symbol and not all of them related to ssr (TypeScript limitations, problem with storeon/devtools and redux-devtools). |
Documentation recommends avoid |
@sivakov512 why do we want to save and restore state in the task of router SSR? Router during rehydrating will look at |
@sivakov512 my question is why you need a serialization at all |
@ai only because it simpler for usage. But this is not critical, yes. |
We already added a custom event and a lot of code for serialization, it is not easy to use. Let’s remove it until we will have a real use case. |
I'am not understand you. |
I am talking why we need to pass the store’s state from the server to the client at all? |
User may need to do some logic on request (auth, data prefetch for rendering, etc). All this data should be passed to client for correct hydration. |
|
BTW, “auth, data prefetch for rendering” is calling “initial state” and it is not part of SSR. You need an initial state without SSR as well. This is why we have |
Yes, my message was only to show how the user can solve problems when using SSR. |
Yeap, I think in this case we should too much project’s specific details which will be hard to move to another project. How to load initial state properly should be in special article (and use |
Okay, thanks But what about the other two problems? |
You do not need this example if you do not need to restore the state during rehydration.
Why you can’t use |
this:
But I need =) How to get all state, except of some parts in TypeScript? |
I removed "docs" |
How what use case?
SHow me full stack trace ( |
When I talking about auth and data prefetching it was my use case. In my case "get all state except router" is simpler than "get only needed parts".
I get it on every click on the link |
Pass this data in
It is not a Symbol problem. It is a problem of router logic. Some event was triggered before the event listener was subscribed. |
Looks like there is no |
index.js
Outdated
@@ -34,14 +32,10 @@ function createRouter (routes) { | |||
|
|||
return function (store) { | |||
store.on('@init', function () { | |||
store.dispatch(change, parse(loc.pathname, routes)) | |||
store.dispatch(change, parse('/', routes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use /
here. How is the initial state tracked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is no way to determine what url is requested from the server, but store should be initialized ith initial state.
User should dispatch store manually with current request url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same component will be always rendered. Then what profit will we get with this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think that there is no need to initialize state on the server by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How Storeon will render requested page (if users asked for /posts/1
we need to route this URL to render this page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне кажется вполне ок вариант с моками, потому что это будет спрятано в библиотеке. Меня смущает только код в @init - совсем-совсем не хочется в коде сервера работать с window. В качестве решения можно location делать с "/" по умолчанию.
Ещё я переживаю, что какая-то библиотека может по наличию window определять, на сервере она или нет - тогда мы можем сломать работу совсем другого кода. Или мы можем как-то изолировать моки внутри библиотеки?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Впрочем, у меня есть идеи как решить последнее.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В качестве решения можно location делать с "/" по умолчанию.
Ну мы как раз обсуждали, что это не круто, так как из-за /
могут запуститься каакие-то модули
Ещё я переживаю, что какая-то библиотека может по наличию window определять, на сервере она или нет - тогда мы можем сломать работу совсем другого кода.
Такие библиотеки не будут работать с большинством SSR решений. Тот же Preact делает SSR вообще через Puppeter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну мы как раз обсуждали, что это не круто, так как из-за / могут запуститься каакие-то модули
Если так не делать, то придется в коде сервера приложения и правда обращаться к `windowё. Чувство прекрасного мне не позволит так делать и я не стану этим пользоваться.
Если других вариантов решений нет (у меня - нет), то можем закрывать этот PR. Возможно, однажды кто-то придет и придумает как это сделать лучше.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Попробуй https://github.com/majo44/storeon-async-router — там и фич больше и мейнтейнер может пойдёт на другой компромисс между чувством прекрасного и реальных проблем.
index.js
Outdated
@@ -34,14 +32,10 @@ function createRouter (routes) { | |||
|
|||
return function (store) { | |||
store.on('@init', function () { | |||
store.dispatch(change, parse(loc.pathname, routes)) | |||
store.dispatch(change, parse('/', routes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How Storeon will render requested page (if users asked for /posts/1
we need to route this URL to render this page)
beforeEach(() => { | ||
history.pushState(null, null, '/') | ||
}) | ||
|
||
it('init state', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help me, please - why this test pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s first discuss this question #8 (comment)
Maybe with new API this error will be fixed automatically
Right now I see 2 problems with this PR:
It is not the big problems but we have another option—just add docs on how to mock |
It may be hard - for example, now |
If we will create |
fixes #7