Skip to content

Commit

Permalink
fix: more sturdy mount initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Erslev Milfred committed Oct 17, 2023
1 parent 3235751 commit 1fe1999
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions components/CustomScrollbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,19 @@ watch(
{ immediate: true }
);
onMounted(()=>{
nextTick(initialize);
const mountInitialization = (count = 0) => {
// Already initialized
if (target.value) return;
// Try initialize the component 5 times before giving up
if (props.ariaControls && document.getElementById(props.ariaControls)) {
initialize();
} else if (count < 5) {
setTimeout(() => mountInitialization(count + 1), 50);
}
};
onMounted(() => {
mountInitialization();
});
onUnmounted(() => (target.value = null));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@limbo-works/custom-scrollbar",
"type": "module",
"version": "0.0.8",
"version": "0.0.9",
"main": "./nuxt.config.js",
"scripts": {
"dev": "nuxi dev .playground",
Expand Down

0 comments on commit 1fe1999

Please sign in to comment.