Skip to content

Injecting styles into new windows opened via window.open #1229

@TejasQ

Description

@TejasQ
  • emotion version: 9.2.5
  • react version: 16.8.2

Relevant code:

const popupWindow = window.open("", target, openOptionsToString(options));
popupWindowRef.current = popupWindow;

// I need to do this because my styles aren't injected into `popupWindow`.
popupWindow.document.head.innerHTML = window.document.head.innerHTML;

React.createPortal(props.children, popupWindowRef.current.document.body)

What you did:
Given a component and the snippet above,

<ShowInNewWindow>
  hello world
</ShowInNewWindow

The "hello world" rendered in the new window is rendered without any styling whatsoever, even though the page that triggered the new window has styles added to its <head>.

Reproduction:
Edit 24p0lk4oyj

Full reproduction on CodeSandbox

Expected
The contents of the new window receive the same styling as the source window.

What I find particularly interesting is that the components on the new window have computed classNames – so that part works. It's just that there are no styles injected into <head> that is throwing me off.

cc @stereobooster who showed me this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions