{"action":"created","comment":{"url":"https://api.github.com/repos/Popmotion/popmotion/pulls/comments/243734783","pull_request_review_id":187590110,"id":243734783,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzczNDc4Mw==","diff_hunk":"@@ -0,0 +1,36 @@\n+import { Dimensions } from './types';\n+\n+/**\n+ * Feature detection for getBBox call on an unrendered SVG Element.\n+ * Firefox will throw \"NS_ERROR_FAILURE\" error.\n+ * We want to detect this upfront so we do not crash in any future measurement.\n+ */\n+export const CAN_MEASURE_NOT_RENDERED_SVG_ELEMENTS = (() => {\n+  try {\n+    document.createElementNS('http://www.w3.org/2000/svg', 'rect').getBBox();\n+  } catch (e) {\n+    return false;\n+  }\n+  return true;\n+})();\n+\n+export const getDimensions = (\n+  element: SVGElement | SVGPathElement\n+): Dimensions =>\n+  typeof (element as SVGGraphicsElement).getBBox === 'function'\n+    ? (element as SVGGraphicsElement).getBBox()\n+    : (element.getBoundingClientRect() as DOMRect);\n+\n+export const getSVGElementDimensionsSafely = (\n+  element: SVGElement | SVGPathElement\n+): Dimensions => {\n+  if (CAN_MEASURE_NOT_RENDERED_SVG_ELEMENTS) {\n+    return getDimensions(element);\n+  }\n+  try {","path":"packages/stylefire/src/svg/utils.ts","position":30,"original_position":30,"commit_id":"6ceba026a21f1284bcff511259a838477a0499f8","original_commit_id":"edbd3f15992da060991b056443dcdec1a2c5a015","user":{"login":"InventingWithMonster","id":7850794,"node_id":"MDQ6VXNlcjc4NTA3OTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/7850794?v=4","gravatar_id":"","url":"https://api.github.com/users/InventingWithMonster","html_url":"https://github.com/InventingWithMonster","followers_url":"https://api.github.com/users/InventingWithMonster/followers","following_url":"https://api.github.com/users/InventingWithMonster/following{/other_user}","gists_url":"https://api.github.com/users/InventingWithMonster/gists{/gist_id}","starred_url":"https://api.github.com/users/InventingWithMonster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/InventingWithMonster/subscriptions","organizations_url":"https://api.github.com/users/InventingWithMonster/orgs","repos_url":"https://api.github.com/users/InventingWithMonster/repos","events_url":"https://api.github.com/users/InventingWithMonster/events{/privacy}","received_events_url":"https://api.github.com/users/InventingWithMonster/received_events","type":"User","site_admin":false},"body":"@niieani Yeah simplification is preferred, fewer potential sources of bugs.","created_at":"2018-12-22T12:02:39Z","updated_at":"2018-12-22T12:02:39Z","html_url":"https://github.com/Popmotion/popmotion/pull/670#discussion_r243734783","pull_request_url":"https://api.github.com/repos/Popmotion/popmotion/pulls/670","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/comments/243734783"},"html":{"href":"https://github.com/Popmotion/popmotion/pull/670#discussion_r243734783"},"pull_request":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/670"}},"in_reply_to_id":243639155},"pull_request":{"url":"https://api.github.com/repos/Popmotion/popmotion/pulls/670","id":238988756,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM4OTg4NzU2","html_url":"https://github.com/Popmotion/popmotion/pull/670","diff_url":"https://github.com/Popmotion/popmotion/pull/670.diff","patch_url":"https://github.com/Popmotion/popmotion/pull/670.patch","issue_url":"https://api.github.com/repos/Popmotion/popmotion/issues/670","number":670,"state":"open","locked":false,"title":"Stylefire: Add graceful degradation for NS_ERROR_FAILURE errors in Firefox","user":{"login":"niieani","id":563469,"node_id":"MDQ6VXNlcjU2MzQ2OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/563469?v=4","gravatar_id":"","url":"https://api.github.com/users/niieani","html_url":"https://github.com/niieani","followers_url":"https://api.github.com/users/niieani/followers","following_url":"https://api.github.com/users/niieani/following{/other_user}","gists_url":"https://api.github.com/users/niieani/gists{/gist_id}","starred_url":"https://api.github.com/users/niieani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niieani/subscriptions","organizations_url":"https://api.github.com/users/niieani/orgs","repos_url":"https://api.github.com/users/niieani/repos","events_url":"https://api.github.com/users/niieani/events{/privacy}","received_events_url":"https://api.github.com/users/niieani/received_events","type":"User","site_admin":false},"body":"Trying to create a `Styler` on a not rendered SVG Element under Firefox currently results in a hard failure:\r\n\r\n```\r\n[Exception... \"Failure\"  nsresult: \"0x80004005 (NS_ERROR_FAILURE)\"]\r\n```\r\n\r\nThe affected `Element`s may be nested under `mask`s, `clipPaths` or ones with effective `display: none` style.\r\n\r\nSince there's no reliable way to determine if an element is currently rendered (or not), I've opted for feature detection. If we detect that we cannot measure a not rendered SVG Element (`getBBox()`), we wrap that call in a try/catch (i.e. only in Firefox, so we do not cause a performance regression in other browsers).\r\n\r\nAn alternative solution to the try/catch is to check if the SVG Element is a (grand)child of an unsupported Element, like this (only `clipPath` below):\r\n\r\n```js\r\n/**\r\n * in Firefox, when element is inside a <clipPath> Element\r\n * running element.getBBox() will throw an \"NS_ERROR_FAILURE\" error\r\n */\r\nexport const isInsideClipPath = (element: SVGElement | SVGPathElement) => {\r\n  const { ownerSVGElement } = element;\r\n  if (!ownerSVGElement) return false;\r\n  let parentElement: SVGElement | HTMLElement | null = element;\r\n  while (parentElement && parentElement !== ownerSVGElement) {\r\n    if (parentElement.tagName === 'clipPath') return true;\r\n    parentElement = (element.parentElement as SVGElement | HTMLElement | null);\r\n  }\r\n  return false;\r\n}\r\n```\r\n\r\nBut I think this adds complexity and won't work in all cases anyway (detecting `display: none` is very hard). `try/catch` shouldn't be too expensive in modern browsers anyway.\r\n\r\nThis mostly fixes the issue, however in some cases it might work differently across browsers, since we do not get the actual `x`/`y` values.\r\n\r\nI didn't add tests since there's actually no way to meaningfully test this without running Firefox.\r\n\r\nSolves: #174, #179.","created_at":"2018-12-16T20:38:03Z","updated_at":"2018-12-22T12:02:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ee5cc895bd8a03170f40d67faa8a674264908b2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Popmotion/popmotion/pulls/670/commits","review_comments_url":"https://api.github.com/repos/Popmotion/popmotion/pulls/670/comments","review_comment_url":"https://api.github.com/repos/Popmotion/popmotion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Popmotion/popmotion/issues/670/comments","statuses_url":"https://api.github.com/repos/Popmotion/popmotion/statuses/6ceba026a21f1284bcff511259a838477a0499f8","head":{"label":"niieani:firefox-rect","ref":"firefox-rect","sha":"6ceba026a21f1284bcff511259a838477a0499f8","user":{"login":"niieani","id":563469,"node_id":"MDQ6VXNlcjU2MzQ2OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/563469?v=4","gravatar_id":"","url":"https://api.github.com/users/niieani","html_url":"https://github.com/niieani","followers_url":"https://api.github.com/users/niieani/followers","following_url":"https://api.github.com/users/niieani/following{/other_user}","gists_url":"https://api.github.com/users/niieani/gists{/gist_id}","starred_url":"https://api.github.com/users/niieani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niieani/subscriptions","organizations_url":"https://api.github.com/users/niieani/orgs","repos_url":"https://api.github.com/users/niieani/repos","events_url":"https://api.github.com/users/niieani/events{/privacy}","received_events_url":"https://api.github.com/users/niieani/received_events","type":"User","site_admin":false},"repo":{"id":162033075,"node_id":"MDEwOlJlcG9zaXRvcnkxNjIwMzMwNzU=","name":"popmotion","full_name":"niieani/popmotion","private":false,"owner":{"login":"niieani","id":563469,"node_id":"MDQ6VXNlcjU2MzQ2OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/563469?v=4","gravatar_id":"","url":"https://api.github.com/users/niieani","html_url":"https://github.com/niieani","followers_url":"https://api.github.com/users/niieani/followers","following_url":"https://api.github.com/users/niieani/following{/other_user}","gists_url":"https://api.github.com/users/niieani/gists{/gist_id}","starred_url":"https://api.github.com/users/niieani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niieani/subscriptions","organizations_url":"https://api.github.com/users/niieani/orgs","repos_url":"https://api.github.com/users/niieani/repos","events_url":"https://api.github.com/users/niieani/events{/privacy}","received_events_url":"https://api.github.com/users/niieani/received_events","type":"User","site_admin":false},"html_url":"https://github.com/niieani/popmotion","description":"Simple animation libraries for delightful user interfaces","fork":true,"url":"https://api.github.com/repos/niieani/popmotion","forks_url":"https://api.github.com/repos/niieani/popmotion/forks","keys_url":"https://api.github.com/repos/niieani/popmotion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/niieani/popmotion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/niieani/popmotion/teams","hooks_url":"https://api.github.com/repos/niieani/popmotion/hooks","issue_events_url":"https://api.github.com/repos/niieani/popmotion/issues/events{/number}","events_url":"https://api.github.com/repos/niieani/popmotion/events","assignees_url":"https://api.github.com/repos/niieani/popmotion/assignees{/user}","branches_url":"https://api.github.com/repos/niieani/popmotion/branches{/branch}","tags_url":"https://api.github.com/repos/niieani/popmotion/tags","blobs_url":"https://api.github.com/repos/niieani/popmotion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/niieani/popmotion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/niieani/popmotion/git/refs{/sha}","trees_url":"https://api.github.com/repos/niieani/popmotion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/niieani/popmotion/statuses/{sha}","languages_url":"https://api.github.com/repos/niieani/popmotion/languages","stargazers_url":"https://api.github.com/repos/niieani/popmotion/stargazers","contributors_url":"https://api.github.com/repos/niieani/popmotion/contributors","subscribers_url":"https://api.github.com/repos/niieani/popmotion/subscribers","subscription_url":"https://api.github.com/repos/niieani/popmotion/subscription","commits_url":"https://api.github.com/repos/niieani/popmotion/commits{/sha}","git_commits_url":"https://api.github.com/repos/niieani/popmotion/git/commits{/sha}","comments_url":"https://api.github.com/repos/niieani/popmotion/comments{/number}","issue_comment_url":"https://api.github.com/repos/niieani/popmotion/issues/comments{/number}","contents_url":"https://api.github.com/repos/niieani/popmotion/contents/{+path}","compare_url":"https://api.github.com/repos/niieani/popmotion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/niieani/popmotion/merges","archive_url":"https://api.github.com/repos/niieani/popmotion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/niieani/popmotion/downloads","issues_url":"https://api.github.com/repos/niieani/popmotion/issues{/number}","pulls_url":"https://api.github.com/repos/niieani/popmotion/pulls{/number}","milestones_url":"https://api.github.com/repos/niieani/popmotion/milestones{/number}","notifications_url":"https://api.github.com/repos/niieani/popmotion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/niieani/popmotion/labels{/name}","releases_url":"https://api.github.com/repos/niieani/popmotion/releases{/id}","deployments_url":"https://api.github.com/repos/niieani/popmotion/deployments","created_at":"2018-12-16T19:19:55Z","updated_at":"2018-12-16T19:19:59Z","pushed_at":"2018-12-21T21:18:11Z","git_url":"git://github.com/niieani/popmotion.git","ssh_url":"git@github.com:niieani/popmotion.git","clone_url":"https://github.com/niieani/popmotion.git","svn_url":"https://github.com/niieani/popmotion","homepage":"https://popmotion.io","size":44927,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Popmotion:master","ref":"master","sha":"cfc98853723de4cf4bee43820404e575ddb8f7f9","user":{"login":"Popmotion","id":14272617,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MjcyNjE3","avatar_url":"https://avatars3.githubusercontent.com/u/14272617?v=4","gravatar_id":"","url":"https://api.github.com/users/Popmotion","html_url":"https://github.com/Popmotion","followers_url":"https://api.github.com/users/Popmotion/followers","following_url":"https://api.github.com/users/Popmotion/following{/other_user}","gists_url":"https://api.github.com/users/Popmotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Popmotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Popmotion/subscriptions","organizations_url":"https://api.github.com/users/Popmotion/orgs","repos_url":"https://api.github.com/users/Popmotion/repos","events_url":"https://api.github.com/users/Popmotion/events{/privacy}","received_events_url":"https://api.github.com/users/Popmotion/received_events","type":"Organization","site_admin":false},"repo":{"id":23044617,"node_id":"MDEwOlJlcG9zaXRvcnkyMzA0NDYxNw==","name":"popmotion","full_name":"Popmotion/popmotion","private":false,"owner":{"login":"Popmotion","id":14272617,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MjcyNjE3","avatar_url":"https://avatars3.githubusercontent.com/u/14272617?v=4","gravatar_id":"","url":"https://api.github.com/users/Popmotion","html_url":"https://github.com/Popmotion","followers_url":"https://api.github.com/users/Popmotion/followers","following_url":"https://api.github.com/users/Popmotion/following{/other_user}","gists_url":"https://api.github.com/users/Popmotion/gists{/gist_id}","starred_url":"https://api.github.com/users/Popmotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Popmotion/subscriptions","organizations_url":"https://api.github.com/users/Popmotion/orgs","repos_url":"https://api.github.com/users/Popmotion/repos","events_url":"https://api.github.com/users/Popmotion/events{/privacy}","received_events_url":"https://api.github.com/users/Popmotion/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Popmotion/popmotion","description":"Simple animation libraries for delightful user interfaces","fork":false,"url":"https://api.github.com/repos/Popmotion/popmotion","forks_url":"https://api.github.com/repos/Popmotion/popmotion/forks","keys_url":"https://api.github.com/repos/Popmotion/popmotion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Popmotion/popmotion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Popmotion/popmotion/teams","hooks_url":"https://api.github.com/repos/Popmotion/popmotion/hooks","issue_events_url":"https://api.github.com/repos/Popmotion/popmotion/issues/events{/number}","events_url":"https://api.github.com/repos/Popmotion/popmotion/events","assignees_url":"https://api.github.com/repos/Popmotion/popmotion/assignees{/user}","branches_url":"https://api.github.com/repos/Popmotion/popmotion/branches{/branch}","tags_url":"https://api.github.com/repos/Popmotion/popmotion/tags","blobs_url":"https://api.github.com/repos/Popmotion/popmotion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Popmotion/popmotion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Popmotion/popmotion/git/refs{/sha}","trees_url":"https://api.github.com/repos/Popmotion/popmotion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Popmotion/popmotion/statuses/{sha}","languages_url":"https://api.github.com/repos/Popmotion/popmotion/languages","stargazers_url":"https://api.github.com/repos/Popmotion/popmotion/stargazers","contributors_url":"https://api.github.com/repos/Popmotion/popmotion/contributors","subscribers_url":"https://api.github.com/repos/Popmotion/popmotion/subscribers","subscription_url":"https://api.github.com/repos/Popmotion/popmotion/subscription","commits_url":"https://api.github.com/repos/Popmotion/popmotion/commits{/sha}","git_commits_url":"https://api.github.com/repos/Popmotion/popmotion/git/commits{/sha}","comments_url":"https://api.github.com/repos/Popmotion/popmotion/comments{/number}","issue_comment_url":"https://api.github.com/repos/Popmotion/popmotion/issues/comments{/number}","contents_url":"https://api.github.com/repos/Popmotion/popmotion/contents/{+path}","compare_url":"https://api.github.com/repos/Popmotion/popmotion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Popmotion/popmotion/merges","archive_url":"https://api.github.com/repos/Popmotion/popmotion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Popmotion/popmotion/downloads","issues_url":"https://api.github.com/repos/Popmotion/popmotion/issues{/number}","pulls_url":"https://api.github.com/repos/Popmotion/popmotion/pulls{/number}","milestones_url":"https://api.github.com/repos/Popmotion/popmotion/milestones{/number}","notifications_url":"https://api.github.com/repos/Popmotion/popmotion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Popmotion/popmotion/labels{/name}","releases_url":"https://api.github.com/repos/Popmotion/popmotion/releases{/id}","deployments_url":"https://api.github.com/repos/Popmotion/popmotion/deployments","created_at":"2014-08-17T16:23:07Z","updated_at":"2018-12-22T09:58:15Z","pushed_at":"2018-12-21T21:18:13Z","git_url":"git://github.com/Popmotion/popmotion.git","ssh_url":"git@github.com:Popmotion/popmotion.git","clone_url":"https://github.com/Popmotion/popmotion.git","svn_url":"https://github.com/Popmotion/popmotion","homepage":"https://popmotion.io","size":45235,"stargazers_count":15752,"watchers_count":15752,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":558,"mirror_url":null,"archived":false,"open_issues_count":89,"license":null,"forks":558,"open_issues":89,"watchers":15752,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/670"},"html":{"href":"https://github.com/Popmotion/popmotion/pull/670"},"issue":{"href":"https://api.github.com/repos/Popmotion/popmotion/issues/670"},"comments":{"href":"https://api.github.com/repos/Popmotion/popmotion/issues/670/comments"},"review_comments":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/670/comments"},"review_comment":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Popmotion/popmotion/pulls/670/commits"},"statuses":{"href":"https://api.github.com/repos/Popmotion/popmotion/statuses/6ceba026a21f1284bcff511259a838477a0499f8"}},"author_association":"NONE"}}
{"actor":{"display_login":"InventingWithMonster"}}