Skip to content

Commit

Permalink
Fix: Properly handle DOM content loaded event (#32)
Browse files Browse the repository at this point in the history
* Properly handle DOM content loaded event

* Properly handle DOM content loaded event

* Remove def

Co-authored-by: Rob Dick <r.dick@kumulos.com>
  • Loading branch information
robdick and krobd authored May 19, 2021
1 parent b575ea8 commit 03b3d0c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/worker.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kumulos/web",
"version": "1.7.1",
"version": "1.7.2",
"description": "Official SDK for integrating Kumulos services with your web projects",
"main": "dist/index.js",
"types": "types/src/index.d.ts",
Expand Down Expand Up @@ -42,4 +42,4 @@
"dependencies": {
"preact": "^10.5.13"
}
}
}
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { authedFetch, cyrb53, uuidv4 } from './utils';
import { del, get, set } from './storage';
import { Channel } from './channels';

const SDK_VERSION = '1.7.1';
const SDK_VERSION = '1.7.2';
const SDK_TYPE = 10;
const EVENTS_BASE_URL = 'https://events.kumulos.com';
export const PUSH_BASE_URL = 'https://push.kumulos.com';
Expand Down
8 changes: 8 additions & 0 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,11 @@ export function parseQueryString(

return query;
}

export function onDOMReady(fn: () => void) {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
3 changes: 2 additions & 1 deletion src/prompts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { persistPromptReminder, getPromptReminder } from '../core/storage';
import { PromptReminderDelayConfig } from '../core';
import { UIContext } from './ui-context';
import { loadConfig } from '../core/config';
import { onDOMReady } from '../core/utils';

export type PromptManagerState =
| 'loading'
Expand Down Expand Up @@ -74,7 +75,7 @@ export class PromptManager {

ctx.subscribe('eventTracked', this.onEventTracked);

document.addEventListener('DOMContentLoaded', () => {
onDOMReady(() => {
document.body.appendChild(this.uiRoot);
this.setState('loading');
});
Expand Down
1 change: 1 addition & 0 deletions types/src/core/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export declare function defer<T>(): {
export declare function parseQueryString(qs?: string, excludedQueryKeys?: string[]): {
[key: string]: string;
} | undefined;
export declare function onDOMReady(fn: () => void): void;

0 comments on commit 03b3d0c

Please sign in to comment.