From b06401eb34d1d8837e2725c3ac2ca436a04dc19a Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 15 Aug 2019 11:33:47 +0200 Subject: [PATCH] SONAR-12368 Fix documentation in IE11 --- server/sonar-docs/gatsby-config.js | 6 ++++++ server/sonar-docs/package.json | 1 + .../src/components/PluginMetaData.tsx | 19 ++++++++++++++++--- server/sonar-docs/yarn.lock | 7 +++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/sonar-docs/gatsby-config.js b/server/sonar-docs/gatsby-config.js index 33d891cdb5c..17b858049ac 100644 --- a/server/sonar-docs/gatsby-config.js +++ b/server/sonar-docs/gatsby-config.js @@ -28,6 +28,12 @@ module.exports = { `gatsby-plugin-typescript`, `gatsby-plugin-layout`, 'gatsby-plugin-react-helmet', + { + resolve: `gatsby-plugin-polyfill-io`, + options: { + features: [`Promise`, `fetch`, `Object.assign`, `Symbol`, `Array.from`] + } + }, { resolve: `sonarsource-source-filesystem`, options: { name: 'src', path: `${__dirname}/src/` } diff --git a/server/sonar-docs/package.json b/server/sonar-docs/package.json index 9b36e9600b8..84dddb16986 100644 --- a/server/sonar-docs/package.json +++ b/server/sonar-docs/package.json @@ -8,6 +8,7 @@ "classnames": "2.2.6", "gatsby": "2.2.8", "gatsby-plugin-layout": "1.0.13", + "gatsby-plugin-polyfill-io": "1.1.0", "gatsby-plugin-react-helmet": "3.0.10", "gatsby-plugin-typescript": "2.0.11", "gatsby-plugin-typography": "2.2.10", diff --git a/server/sonar-docs/src/components/PluginMetaData.tsx b/server/sonar-docs/src/components/PluginMetaData.tsx index 80fd7234413..d0260bc2861 100644 --- a/server/sonar-docs/src/components/PluginMetaData.tsx +++ b/server/sonar-docs/src/components/PluginMetaData.tsx @@ -82,9 +82,22 @@ export default class PluginMetaData extends React.Component { const pageContainer = document.querySelector('.page-container'); if (pageContainer) { - const iterator = document.createNodeIterator(pageContainer, NodeFilter.SHOW_COMMENT, { - acceptNode: (_: Node) => NodeFilter.FILTER_ACCEPT - }); + // The following uses an older syntax for createNodeIterator() in order + // to support IE11 + // - IE doesn't support the new { acceptNode: (node: Node) => number } + // format for the 3rd parameter, and instead expects to get it passed + // the function directly. Modern browsers support both paradigms as a + // fallback, so we fallback to the old one. + // - IE11 requires the 4th argument. + // @ts-ignore: tsc requires an additional comment at the function call. + const iterator = document.createNodeIterator( + pageContainer, + NodeFilter.SHOW_COMMENT, + // @ts-ignore: IE11 doesn't support the { acceptNode: () => number } format. + (_: Node) => NodeFilter.FILTER_ACCEPT, + // @ts-ignore: IE11 requires the 4th argument. + false + ); let node; const wrappers: Dict = {}; diff --git a/server/sonar-docs/yarn.lock b/server/sonar-docs/yarn.lock index 3719f7e3de6..7862252cb08 100644 --- a/server/sonar-docs/yarn.lock +++ b/server/sonar-docs/yarn.lock @@ -4826,6 +4826,13 @@ gatsby-plugin-page-creator@^2.0.11: parse-filepath "^1.0.1" slash "^1.0.0" +gatsby-plugin-polyfill-io@^1.1.0: + version "1.1.0" + resolved "https://repox.jfrog.io/repox/api/npm/npm/gatsby-plugin-polyfill-io/-/gatsby-plugin-polyfill-io-1.1.0.tgz#61424c773ae123680e50b9a6692a4b939a1e6e13" + integrity sha1-YUJMdzrhI2gOULmmaSpLk5oebhM= + dependencies: + babel-runtime "^6.26.0" + gatsby-plugin-react-helmet@3.0.10: version "3.0.10" resolved "https://registry.yarnpkg.com/gatsby-plugin-react-helmet/-/gatsby-plugin-react-helmet-3.0.10.tgz#08a4f3f7d6ffd020d78817679535fb6548602302" -- 2.39.5