Open uisam00 opened 1 year ago
Hi!
Thanks for being part of the Font Awesome Community and for this excellent bug report.
I should start by clarifying that Firefox 47 is not supported, as per https://fontawesome.com/v6/docs/web/dig-deeper/browser-support
However, if this is the only issue and that is the solution, I hope that this can be considered.
Question:
_hooks[hook]
is not an array, what it is?in this logic if (!_hooks[hook])
1.1. _hooks[hook] in firefox 47 return undefined. So this logic them we have ìf(!undefined)
, theoretically (!false) should enter, but in firefox 47 not enter in this logic. So when trying _hooks[hook].push(hooks[hook]) broken. Because in firefox 47 _hooks[hook] not is array, he is a function.
By switching to Array.isArray(_hooks[hook]), it worked both in firefox 47 and in more modern browsers. Thus doing a functional validation for older browsers
Hello, sorry for the delay. here are the answers to the questions presented:
_hooks[hook]
is function when the error occurs.as @danielrosendos answered, changing from if (!_hooks[hook])
toif(!Array.isArray(_hooks[hook]))
will solve this problem in legacy browsers and will continue to work in most current browsers
I accidentally closed the issue then reopened it
Here is a screenshot of the error that appears in the console when I try to access _hooks[hook].push
, first i check _hooks[hook]
with console.log( _hooks[hook])
and it returns function watch()
. Note that the error occurs because this is trying to access .push()
from a function object.
Bug description
I'm trying to implement a React application for legacy browsers using the @fortawesome/fontawesome-svg-core and @fortawesome/react-fontawesome libraries. However, I came across the following error: 'Unhandled promise rejection TypeError: _hooks[hook].push is not a function'.
While debugging the issue, I traced it back to an attempt to use Array.push() without validating if the object is actually an array. This issue is causing my application to break when I try to run it in older browsers.
The problematic code block is as follows:
The solution could be to add a validation:
It is present in the following files:
Example of error reproduction:
Reproducible test case
https://github.com/uisam00/vite-react-legacy
Screenshots
This is the error:
when i put the validation in the builded file
The error disappears:
Font Awesome version
6.3.0
Serving
Self-hosted
Implementation
SVG+JS
Browser and Operating System
Web bug report checklist