Skip to content

Commit

Permalink
fix(Log): Fix fatal error caused by iOS (less than 13.4) which is not…
Browse files Browse the repository at this point in the history
… support `ResizeObserver` interface. (issue #610)
  • Loading branch information
Maizify committed May 23, 2023
1 parent 21fb678 commit 2e4feb3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ English | [简体中文](./CHANGELOG_CN.md)
- `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(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 @@ -5,6 +5,7 @@
- `Feat(Netwrk)` 新增配置项 `network.ignoreUrlRegExp` 以跳过一些请求。 (PR #623)
- `Fix(Core)` 修复 `vConsole.setOption()` 中可能存在的原型污染问题。 (issue #616 #621)
- `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
3 changes: 2 additions & 1 deletion src/component/recycleScroller/recycleItem.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { ResizeObserverPolyfill } from './resizeObserver';
export let show: boolean;
export let top: boolean;
Expand All @@ -14,7 +15,7 @@
if (show) {
onResize(item.getBoundingClientRect().height);
}
observer = new ResizeObserver((entries) => {
observer = new ResizeObserverPolyfill((entries) => {
const entry = entries[0];
if (show) onResize(entry.contentRect.height)
});
Expand Down
3 changes: 2 additions & 1 deletion src/component/recycleScroller/recycleScroller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ScrollHandler from './scroll/scrollHandler';
import TouchTracker from './scroll/touchTracker';
import Style from './recycleScroller.less';
import { ResizeObserverPolyfill } from './resizeObserver';
import createRecycleManager from './recycleManager';
// props
Expand Down Expand Up @@ -177,7 +178,7 @@
if (elem) {
heightUpdater(elem.getBoundingClientRect().height);
if (observer) observer.disconnect();
observer = new ResizeObserver((entries) => {
observer = new ResizeObserverPolyfill((entries) => {
const entry = entries[0];
heightUpdater(entry.contentRect.height);
});
Expand Down
23 changes: 23 additions & 0 deletions src/component/recycleScroller/resizeObserver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* A ResizeObserver polyfill.
* ResizeObserver is not support in iOS 13.3
*/
class EmptyResizeObserver {
constructor(callback: (entries: any[], observer?: EmptyResizeObserver) => void) {
// do nothing
}

public disconnect() {
// do nothing
}

public observe(target: Element | SVGElement, options?: any) {
// do nothing
}

public unobserve(target: Element | SVGElement) {
// do nothing
}
}

export const ResizeObserverPolyfill = window.ResizeObserver || EmptyResizeObserver;

0 comments on commit 2e4feb3

Please sign in to comment.