Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swaathee committed Jan 29, 2021
1 parent 362103b commit 2381778
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/clarity-js/src/data/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,23 @@ function send(payload: string, sequence: number, last: boolean): void {
}

function check(xhr: XMLHttpRequest, sequence: number, last: boolean): void {
if (xhr && xhr.readyState === XMLHttpRequest.DONE && sequence in transit) {
var transitData = transit[sequence];
if (xhr && xhr.readyState === XMLHttpRequest.DONE && transitData) {
// Attempt send payload again (as configured in settings) if we do not receive a success (2XX) response code back from the server
if ((xhr.status < 200 || xhr.status > 208) && transit[sequence].attempts <= Setting.RetryLimit) {
if ((xhr.status < 200 || xhr.status > 208) && transitData.attempts <= Setting.RetryLimit) {
// The only exception is if we receive 400 error code,
// which indicates the server has rejected the response for bad payload and we should terminate the session.
if (xhr.status === 400) {
limit.trigger(Check.Server);
} else { send(transit[sequence].data, sequence, last); }
} else { send(transitData.data, sequence, last); }
} else {
track = { sequence, attempts: transit[sequence].attempts, status: xhr.status };
track = { sequence, attempts: transitData.attempts, status: xhr.status };
// Send back an event only if we were not successful in our first attempt
if (transit[sequence].attempts > 1) { encode(Event.Upload); }
if (transitData.attempts > 1) { encode(Event.Upload); }
// Handle response if it was a 200 response with a valid body
if (xhr.status === 200 && xhr.responseText) { response(xhr.responseText); }
// If we exhausted our retries the trigger Clarity shutdown for this page
if (transit[sequence].attempts > Setting.RetryLimit) { limit.trigger(Check.Retry); }
if (transitData.attempts > Setting.RetryLimit) { limit.trigger(Check.Retry); }
// Stop tracking this payload now that it's all done
delete transit[sequence];
}
Expand Down
4 changes: 3 additions & 1 deletion packages/clarity-visualize/src/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export function scroll(event: Interaction.ScrollEvent): void {
let doc = state.player.contentDocument;
let de = doc.documentElement;
let scrollTarget = element(data.target as number) as HTMLElement || doc.body;
if (scrollTarget) { scrollTarget.scrollTo(data.x, data.y); }
let scrollable = scrollTarget.scrollHeight > scrollTarget.clientHeight;
if (scrollTarget && scrollable) { scrollTarget.scrollTo(data.x, data.y); }

// Position canvas relative to scroll events on the parent page
if (scrollTarget === de || scrollTarget === doc.body) {
if (!scrollable) {window.scrollTo(data.x, data.y);}
let canvas = overlay();
if (canvas) {
canvas.style.left = data.x + Constant.Pixel;
Expand Down

0 comments on commit 2381778

Please sign in to comment.