ui: Don't cache event sources following a 401 (#11681)

This commit is contained in:
John Cowen 2021-12-01 13:24:52 +00:00 committed by GitHub
parent c6dd21f4dd
commit 33a405ae8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

4
.changelog/11681.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
ui: Fixes an issue where under some circumstances after logging we present the
data loaded previous to you logging in.
```

View File

@ -96,13 +96,15 @@ export default class DataSourceService extends Service {
if (!(uri instanceof URI) && typeof uri !== 'string') {
return this.unwrap(uri, ref);
}
runInDebug(
_ => {
if(!(uri instanceof URI)) {
console.error(new Error(`DataSource '${uri}' does not use the uri helper. Please ensure you use the uri helper to ensure correct encoding`))
}
runInDebug(_ => {
if (!(uri instanceof URI)) {
console.error(
new Error(
`DataSource '${uri}' does not use the uri helper. Please ensure you use the uri helper to ensure correct encoding`
)
);
}
);
});
uri = uri.toString();
let source;
// Check the cache for an EventSource that is already being used
@ -130,7 +132,11 @@ export default class DataSourceService extends Service {
const event = source.getCurrentEvent();
const cursor = source.configuration.cursor;
// only cache data if we have any
if (typeof event !== 'undefined' && typeof cursor !== 'undefined') {
if (
typeof event !== 'undefined' &&
typeof cursor !== 'undefined' &&
e.errors && e.errors[0].status !== '401'
) {
cache.set(uri, {
currentEvent: event,
cursor: cursor,

View File

@ -57,7 +57,7 @@ export default function(
// close after the dispatch so we can tell if it was an error whilst closed or not
// but make sure its before the promise tick
this.readyState = 2; // CLOSE
this.dispatchEvent({ type: 'close' });
this.dispatchEvent({ type: 'close', error: e });
})
.then(() => {
// This only gets called when the promise chain completely finishes