hyperstack-org / hyperstack-org/hyperstack

Client/server versioning for safe updates?

Đang mở
#249 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## 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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.