From 66577725ccec825eae9bcdfbf388de341ac4eb0e Mon Sep 17 00:00:00 2001 From: Eleonora Guidi Date: Wed, 22 May 2019 11:07:17 +0200 Subject: [PATCH 1/4] Fix issue #64: Print dialogue only open once in safari on Mac Removed removeWindow method. Tested on example and custom app, seems to work fine on Chrome, Firefox and Safari. Updated version on package.json and Changelog file. --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/index.tsx | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a3b5e..f798cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 2.1.3 (May 22nd, 2019) + +- FIX [64](https://github.com/gregnb/react-to-print/issues/64): Print dialogue only open once in safari on Mac + ## 2.1.2 (May 3rd, 2019) - FIX [118](https://github.com/gregnb/react-to-print/issues/118): Ensure fonts have time to load before printing, thanks [aviklai](https://github.com/aviklai) diff --git a/package.json b/package.json index 4a012eb..483b8a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-to-print", - "version": "2.1.2", + "version": "2.1.3", "description": "Print React components in the browser", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/index.tsx b/src/index.tsx index 75ca23a..d491e10 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -29,12 +29,6 @@ export default class ReactToPrint extends React.Component { linksLoaded: Element[]; linksErrored: Element[]; - removeWindow = (target) => { - setTimeout(() => { - target.parentNode.removeChild(target); - }, 500); - }; - triggerPrint = (target) => { const { onBeforePrint, onAfterPrint } = this.props; @@ -45,7 +39,6 @@ export default class ReactToPrint extends React.Component { setTimeout(() => { target.contentWindow.focus(); target.contentWindow.print(); - this.removeWindow(target); if (onAfterPrint) { onAfterPrint(); From 4a03924d723178772d20239754520a9b07443b78 Mon Sep 17 00:00:00 2001 From: Eleonora Guidi Date: Thu, 30 May 2019 12:07:04 +0200 Subject: [PATCH 2/4] Fix issue #64: Print dialogue only open once in safari on Mac Added a class to the printing iframe. Always remove the oldest iframe the second time user tries to print (and then append the new one). Tested on example. --- package-lock.json | 2 +- src/index.tsx | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 77a88bc..ddeb10a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-to-print", - "version": "2.0.0-alpha.7", + "version": "2.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/index.tsx b/src/index.tsx index d491e10..738ac3f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,6 +30,9 @@ export default class ReactToPrint extends React.Component { linksErrored: Element[]; triggerPrint = (target) => { + const i = target.parentNode.childNodes.length; + console.log(target, target.parentNode, target.parentNode.childNodes, target.parentNode.childNodes[i-1] ) + const { onBeforePrint, onAfterPrint } = this.props; if (onBeforePrint) { @@ -39,7 +42,7 @@ export default class ReactToPrint extends React.Component { setTimeout(() => { target.contentWindow.focus(); target.contentWindow.print(); - + if (onAfterPrint) { onAfterPrint(); } @@ -65,6 +68,7 @@ export default class ReactToPrint extends React.Component { printWindow.style.position = "absolute"; printWindow.style.top = "-1000px"; printWindow.style.left = "-1000px"; + printWindow.id = "printWindow"; const contentNodes = findDOMNode(contentEl); const linkNodes = document.querySelectorAll("link[rel='stylesheet']"); @@ -171,6 +175,12 @@ export default class ReactToPrint extends React.Component { } }; + + if (document.getElementById("printWindow")) { + console.log("INCLUDED") + document.body.removeChild(document.getElementById("printWindow")); + } + console.log( document.body.lastChild) document.body.appendChild(printWindow); }; From f0a6cd510de7b112f2ca0946ecb52f986fc212af Mon Sep 17 00:00:00 2001 From: Eleonora Guidi Date: Thu, 30 May 2019 12:08:23 +0200 Subject: [PATCH 3/4] Fix issue #64: Print dialogue only open once in safari on Mac Removed console.log --- src/index.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 738ac3f..60449f4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,9 +30,6 @@ export default class ReactToPrint extends React.Component { linksErrored: Element[]; triggerPrint = (target) => { - const i = target.parentNode.childNodes.length; - console.log(target, target.parentNode, target.parentNode.childNodes, target.parentNode.childNodes[i-1] ) - const { onBeforePrint, onAfterPrint } = this.props; if (onBeforePrint) { @@ -177,10 +174,8 @@ export default class ReactToPrint extends React.Component { if (document.getElementById("printWindow")) { - console.log("INCLUDED") document.body.removeChild(document.getElementById("printWindow")); } - console.log( document.body.lastChild) document.body.appendChild(printWindow); }; From 519265aa5153815b83db7ec1d1529635052b2886 Mon Sep 17 00:00:00 2001 From: Eleonora Guidi Date: Fri, 31 May 2019 21:36:32 +0200 Subject: [PATCH 4/4] Fix issue #64: Print dialogue only open once in safari on Mac Revert changes on changelog and package.json --- CHANGELOG.md | 4 ---- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f798cf1..19a3b5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ # CHANGELOG -## 2.1.3 (May 22nd, 2019) - -- FIX [64](https://github.com/gregnb/react-to-print/issues/64): Print dialogue only open once in safari on Mac - ## 2.1.2 (May 3rd, 2019) - FIX [118](https://github.com/gregnb/react-to-print/issues/118): Ensure fonts have time to load before printing, thanks [aviklai](https://github.com/aviklai) diff --git a/package-lock.json b/package-lock.json index ddeb10a..105ee1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-to-print", - "version": "2.1.3", + "version": "2.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 483b8a7..4a012eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-to-print", - "version": "2.1.3", + "version": "2.1.2", "description": "Print React components in the browser", "main": "lib/index.js", "types": "lib/index.d.ts",