Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles are not properly rendered in iframe because of missing DOCTYPE #459

Closed
mukul-rawat opened this issue Jan 19, 2022 · 4 comments
Closed

Comments

@mukul-rawat
Copy link

mukul-rawat commented Jan 19, 2022

This is the alignment that is being rendered on the UI.

150278059-bf5c539a-2131-41ba-907a-4d6d87834c25

This is the alignment that is being rendered in the print

150278059-bf5c539a-2131-41ba-907a-4d6d87834c25 (2)

Probable cause is that the iframe is missing the <!DOCTYPE html>

Browser: Latest version of Chrome

@MatthewHerbst
Copy link
Owner

Hello. Could you please share code to reproduce the print output? A working codesandbox would be ideal. I'm not aware of a missing DOCTYPE being able to impact styles, and if it did then this package would be breaking for everyone that uses it. I'm guessing there is a CSS issue in your code.

@MatthewHerbst
Copy link
Owner

The fix for this will be in the next patch release, which will be released this week, possibly even today.

Lots of learning from looking into this, thanks for the report.

Some references for anyone else reading this:
https://developer.mozilla.org/en-US/docs/Glossary/Doctype
https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode
https://hsivonen.fi/doctype/
https://quirks.spec.whatwg.org/#css

There must be something unique in the styles that is causing the browser to do strange things in quirks mode, since otherwise I would have expected this to have been reported a long time ago. I wasn't able to see anything obvious with a semi-thorough read through the code so it must be some pretty arcane rule in the CSS quirks mode being triggered. Regardless, you are correct that we should be setting the DOCTYPE so that we always are rendered in standards mode.

MatthewHerbst added a commit that referenced this issue Jan 24, 2022
…dates (#461)

* Read from `clonedContentNodes` instead of `contentNodes`, fix type

* README updates

* Electron references added to README

* Update dependencies

* Ensure a `DOCTYPE` is set on the print `iframe`

#459
https://stackoverflow.com/questions/14186070/javascript-create-an-iframe-with-strict-doctype

* Fix `canvas` elements not printing properly

* Remove some debugging statements

* Update `devDependencies` to make `npm audit` happy

* Properly bind video error handlers
@MatthewHerbst
Copy link
Owner

Fix published in v2.14.4, thanks!

@mukul-rawat
Copy link
Author

@MatthewHerbst Thanks for the quick replies and the fix.

geektalent1010 added a commit to geektalent1010/reactjs-print that referenced this issue Oct 26, 2022
…dates (#461)

* Read from `clonedContentNodes` instead of `contentNodes`, fix type

* README updates

* Electron references added to README

* Update dependencies

* Ensure a `DOCTYPE` is set on the print `iframe`

MatthewHerbst/react-to-print#459
https://stackoverflow.com/questions/14186070/javascript-create-an-iframe-with-strict-doctype

* Fix `canvas` elements not printing properly

* Remove some debugging statements

* Update `devDependencies` to make `npm audit` happy

* Properly bind video error handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants