hyperstack-org / hyperstack-org/hyperstack

Client/server versioning for safe updates?

未关闭
#249 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
538
派生
41
PR 合并指标
30 天内没有已合并 PR

描述

## Client/server versioning

I think we need a way for the client (browser) and server to
recognize when they are running different code-versions.

@catmando describes the problem [here](https://github.com/hyperstack-org/hyperstack/issues/235#issuecomment-526885469) in the context of mobile apps.

This ticket is meant to describe the same problem for the case of a plain browser/server app
because I believe the two cases (mobile vs browser/server) will need two slightly different
solutions.

### Scenario

* Browser loads the app
* User clicks buttons, submits forms etc.
* Server is updated _while client app instances are still open_. For example a model-attribute is changed from String to integer

### Problems

* Messages from the outdated clients will no longer be understood by the Server
* Messages from the modified server will no longer be understood by the client
* ⚠️Messages from before the update may still be enqueued in either direction.

### Proposed Solution

Gladly I think/hope the solution can be relatively simple:

* Add a version-attribute to all messages that are exchanged
* Before processing a message either on the server- or client-side, compare the version to the locally running code-version and if they don't match:
* Discard the message
* Invoke an "Outdated Client"-handler on the client

#### The handler

By default the handler could do something simple like:

```
def outdated_client_handler
if ENV == 'production'
alert 'Your client is outdated, will refresh'
browser.location.reload()
else
# Do nothing by default in development, as to
# not interfere with hot-reloading
end
end
```

It should be overridable by the developer, as most people
will want to customise the behaviour - adjust the message that is displayed, etc.

#### The version string

By default I would suggest to auto-generate this String at
compile-time as a hash over all files in `app/*`.

This should result in the _outdated_client-handler_ to fire
whenever anything is modified.

This behaviour needs to be overridable, too, as most people
likely don't want to force their users to reload for _every_ change.
In a production context it will often be desirable to use a manually
maintained version number instead, or to limit the hashing to
a subset of the codebase (e.g. `app/model/*`).

## Final remarks

Thanks for reading! :)
The above is based on my (still limited) understanding of the
hyperstack-internals. I hope it can help towards a good solution
for the problem but there may be things I'm missing or better
alternative approaches. All comments & discussion welcome!

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。