react-component / react-component/util

getScrollBarSize.tsx 中的方法getTargetScrollBarSize在Firefox 52.9及其以前版本中报错“NS_ERROR_NOT_AVAILABLE”

Open
#261 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
670
Forks
205
Avg merge
11d 17h
Merged PRs (30d)
4

Description

2021.5.20的更新中加入的片段

环境:
windows xp 32位
firefox 52.9 esr 32位

Ref: https://github.com/react-component/util/blob/88be0cbf06d5190d5baa21fcfa9b36977a3796fd/src/getScrollBarSize.tsx#L57

function ensureSize(str: string) {
  const match = str.match(/^(.*)px$/);
  const value = Number(match?.[1]);
  return Number.isNaN(value) ? getScrollBarSize() : value;
}

export function getTargetScrollBarSize(target: HTMLElement) {
  if (typeof document === 'undefined' || !target) {
    return { width: 0, height: 0 };
  }

  const { width, height } = getComputedStyle(target, '::-webkit-scrollbar');  // 此行在Firefox中提示错误
  return {
    width: ensureSize(width),
    height: ensureSize(height),
  };
}

在firefox52.9(32位)及其以前版本(测试了51\47\46)会提示**"NS_ERROR_NOT_AVAILABLE"**的错误。
我想应该是getComputedStyle返回的CSSStyleDeclaration对象(浏览器中显示CSS2Properties)不可访问导致的。
如何修正这个问题?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/getScrollBarSize.tsx at getTargetScrollBarSize, especially the getComputedStyle call using the ::-webkit-scrollbar pseudo-element. Reproduce the issue in Firefox 52.9 ESR or earlier and inspect the existing ensureSize path. Done means the legacy Firefox error no longer occurs while scrollbar width and height remain available to callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.