Skip to content

Commit

Permalink
fix(Core): Fix plugin event ready triggering before its HTML finish…
Browse files Browse the repository at this point in the history
…es rendering. (issue #591)
  • Loading branch information
Maizify committed May 24, 2023
1 parent 2e4feb3 commit 0d5d149
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
English | [简体中文](./CHANGELOG_CN.md)

## 3.16.0 (2023-05-??)
## 3.15.1 (2023-05-??)

- `Feat(Netwrk)` Add new option `network.ignoreUrlRegExp` to skip some requests. (PR #623)
- `Fix(Core)` Fix prototype pollution in `vConsole.setOption()`. (issue #616 #621)
- `Fix(Core)` Fix plugin event `ready` triggering before its HTML finishes rendering. (issue #591)
- `Fix(Log)` Reset group state when `console.clear()` is called. (issue #611)
- `Fix(Log)` Fix fatal error caused by iOS (less than 13.4) which is not support `ResizeObserver` interface. (issue #610)
- `Fix(Network)` Fix possible "Cannot read property" error by `sendBeacon`. (issue #615)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `Feat(Netwrk)` 新增配置项 `network.ignoreUrlRegExp` 以跳过一些请求。 (PR #623)
- `Fix(Core)` 修复 `vConsole.setOption()` 中可能存在的原型污染问题。 (issue #616 #621)
- `Fix(Core)` 修复插件事件 `ready` 在插件完成渲染前就被触发的问题。 (issue #591)
- `Fix(Log)` 修复调用 `console.clear()` 时没有重置 group 层级的问题。 (issue #611)
- `Fix(Log)` 修复因 iOS(小于 13.4)不支持 `ResizeObserver` 接口导致的致命错误 (issue #610)
- `Fix(Network)` 修复可能由 `sendBeacon` 引发的 "Cannot read property" 错误。 (issue #615)
Expand Down
4 changes: 2 additions & 2 deletions dev/plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
.on('init', function() { console.log(this.id, 'init'); })
.on('renderTab', function(cb) {
console.log(this.id, 'renderTab');
cb('<div>I am ' + this.id+'</div>');
cb('<div id="tab1">I am ' + this.id+'</div>');
})
.on('ready', function() { console.log(this.id, 'ready'); })
.on('ready', function() { console.log(this.id, 'ready', document.querySelector('#tab1')); })
.on('show', function() { console.log(this.id, 'show'); })
.on('hide', function() { console.log(this.id, 'hide'); })
.on('showConsole', function() { console.log(this.id, 'showConsole'); })
Expand Down
15 changes: 9 additions & 6 deletions src/core/core.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import * as tool from '../lib/tool';
import { default as SwitchButton } from './switchButton.svelte';
import { default as PluginContent } from '../lib/pluginContent.svelte';
import { contentStore } from './core.model';
import Style from './core.less';
import type { IVConsoleTopbarOptions, IVConsoleToolbarOptions, IVConsoleTabOptions } from '../lib/plugin';
Expand All @@ -17,6 +18,7 @@
tabOptions?: IVConsoleTabOptions;
topbarList?: IVConsoleTopbarOptions[];
toolbarList?: IVConsoleToolbarOptions[];
content?: HTMLElement;
}
export let theme = '';
Expand Down Expand Up @@ -368,12 +370,13 @@
on:scroll={onContentScroll}
>
{#each Object.entries(pluginList) as [pluginId, plugin]}
<div
id="__vc_plug_{plugin.id}"
class="vc-plugin-box"
class:vc-fixed-height="{plugin.tabOptions?.fixedHeight}"
class:vc-actived="{plugin.id === activedPluginId}"
></div>
<svelte:component
this={PluginContent}
pluginId={plugin.id}
fixedHeight={plugin.tabOptions?.fixedHeight}
actived={plugin.id === activedPluginId}
content={plugin.content}
/>
{/each}
</div>

Expand Down
17 changes: 3 additions & 14 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export class VConsole {
tabOptions: undefined,
topbarList: [],
toolbarList: [],
content: undefined,
contentContainer: undefined,
};
this.compInstance.pluginList = this._reorderPluginList(this.compInstance.pluginList);
// start init
Expand All @@ -305,20 +307,7 @@ export class VConsole {
pluginInfo.tabOptions = options;
// render tabbox
if (!!tabboxHTML) {
// when built-in plugins are initializing in the same time,
// plugin's `.vc-plugin-box` element will be re-order by `pluginOrder` option,
// so the innerHTML should be inserted with a delay
// to make sure getting the right `.vc-plugin-box`. (issue #559)
setTimeout(() => {
const divContentInner = document.querySelector('#__vc_plug_' + plugin.id);
if (tool.isString(tabboxHTML)) {
divContentInner.innerHTML += tabboxHTML;
} else if (tool.isFunction(tabboxHTML.appendTo)) {
tabboxHTML.appendTo(divContentInner);
} else if (tool.isElement(tabboxHTML)) {
divContentInner.insertAdjacentElement('beforeend', tabboxHTML);
}
}, 0);
this.compInstance.pluginList[plugin.id].content = tabboxHTML;
}
this.compInstance.pluginList = this.compInstance.pluginList;
});
Expand Down
51 changes: 51 additions & 0 deletions src/lib/pluginContent.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import { onMount } from 'svelte';
import { isElement, isString } from './tool';
/*************************************
* Public properties
*************************************/
export let pluginId = '';
export let fixedHeight = false;
export let actived = false;
export let content: HTMLElement | string = undefined;
/*************************************
* Inner properties
*************************************/
let container: HTMLElement = undefined;
let previousId = undefined;
$: {
if (previousId !== pluginId && content && container) {
// console.log('pluginContent onChange', pluginId, previousId)
previousId = pluginId;
container.innerHTML = '';
if (isString(content)) {
container.innerHTML = <string>content;
} else if (isElement(content)) {
container.appendChild(<HTMLElement>content);
}
}
}
/*************************************
* Lifecycle
*************************************/
// onMount(() => {
// console.log('pluginContent onMount', pluginId)
// });
</script>

<div
bind:this={container}
id="__vc_plug_{pluginId}"
class="vc-plugin-box"
class:vc-fixed-height="{fixedHeight}"
class:vc-actived="{actived}"
>
</div>

0 comments on commit 0d5d149

Please sign in to comment.