chore: Make editor version comparison more lenient to reduce forced reloads
This commit is contained in:
parent
64c3ff8d6b
commit
2a3b9e2104
|
@ -142,6 +142,7 @@
|
|||
"react-router-dom": "^5.1.2",
|
||||
"react-waypoint": "^9.0.2",
|
||||
"rich-markdown-editor": "^10.1.2",
|
||||
"semver": "^7.3.2",
|
||||
"sequelize": "^5.21.1",
|
||||
"sequelize-cli": "^5.5.0",
|
||||
"sequelize-encrypted": "^0.1.0",
|
||||
|
@ -191,4 +192,4 @@
|
|||
"js-yaml": "^3.13.1"
|
||||
},
|
||||
"version": "0.43.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
// @flow
|
||||
import semver from 'semver';
|
||||
import { type Context } from 'koa';
|
||||
import pkg from 'rich-markdown-editor/package.json';
|
||||
import { EditorUpdateError } from '../../errors';
|
||||
|
||||
export default function editor() {
|
||||
return async function editorMiddleware(ctx: Context, next: () => Promise<*>) {
|
||||
const editorVersion = ctx.headers['x-editor-version'];
|
||||
const clientVersion = ctx.headers['x-editor-version'];
|
||||
|
||||
// As the client can only ever be behind the server there's no need for a
|
||||
// more strict check of version infront/behind here
|
||||
if (editorVersion && editorVersion !== pkg.version) {
|
||||
throw new EditorUpdateError();
|
||||
// If the editor version on the client is behind the current version being
|
||||
// served in production by either a minor (new features), or major (breaking
|
||||
// changes) then force a client reload.
|
||||
if (clientVersion) {
|
||||
const parsedClientVersion = semver.parse(clientVersion);
|
||||
const parsedCurrentVersion = semver.parse(pkg.version);
|
||||
|
||||
if (
|
||||
parsedClientVersion.major < parsedCurrentVersion.major ||
|
||||
parsedClientVersion.minor < parsedCurrentVersion.minor
|
||||
) {
|
||||
throw new EditorUpdateError();
|
||||
}
|
||||
}
|
||||
return next();
|
||||
};
|
||||
|
|
|
@ -8826,6 +8826,11 @@ semver@^6.3.0:
|
|||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
||||
|
||||
semver@^7.3.2:
|
||||
version "7.3.2"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
|
||||
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
|
||||
|
||||
sequelize-cli@^5.5.0:
|
||||
version "5.5.1"
|
||||
resolved "https://registry.yarnpkg.com/sequelize-cli/-/sequelize-cli-5.5.1.tgz#0b9c2fc04d082cc8ae0a8fe270b96bb606152bab"
|
||||
|
|
Reference in New Issue