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

Revert "Use ownerDocument instead of global document (#2726)" #2818

Merged
merged 1 commit into from Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions CHANGELOG.md
Expand Up @@ -8,8 +8,6 @@ _The format is based on [Keep a Changelog](http://keepachangelog.com/) and this

- Remove deprecated functionality (object-form `.attrs({})`)

- Fix to use `ownerDocument` instead of global `document`, by [@yamachig](https://github.com/yamachig) (see [#2721](https://github.com/styled-components/styled-components/pull/2721))

- Fix attrs not taking precedence over props when overriding a given prop

## [v4.3.2] - 2019-06-19
Expand Down
4 changes: 1 addition & 3 deletions packages/styled-components/src/sheet/Rehydration.js
Expand Up @@ -88,9 +88,7 @@ const rehydrateSheetFromTag = (sheet: Sheet, style: HTMLStyleElement) => {
};

export const rehydrateSheet = (sheet: Sheet) => {
let targetDocument = document;
if(sheet.options.target) targetDocument = sheet.options.target.ownerDocument;
const nodes = targetDocument.querySelectorAll(SELECTOR);
const nodes = document.querySelectorAll(SELECTOR);

for (let i = 0, l = nodes.length; i < l; i++) {
const node = ((nodes[i]: any): HTMLStyleElement);
Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/sheet/Tag.js
Expand Up @@ -26,7 +26,7 @@ export class CSSOMTag implements Tag {
const element = (this.element = makeStyleTag(target));

// Avoid Edge bug where empty style elements don't create sheets
element.appendChild(element.ownerDocument.createTextNode(''));
element.appendChild(document.createTextNode(''));

this.sheet = getSheet(element);
this.length = 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ export class TextTag implements Tag {

insertRule(index: number, rule: string): boolean {
if (index <= this.length && index >= 0) {
const node = this.element.ownerDocument.createTextNode(rule);
const node = document.createTextNode(rule);
const refNode = this.nodes[index];
this.element.insertBefore(node, refNode || null);
this.length++;
Expand Down
6 changes: 2 additions & 4 deletions packages/styled-components/src/sheet/dom.js
Expand Up @@ -21,11 +21,9 @@ const findLastStyleTag = (target: HTMLElement): void | HTMLStyleElement => {

/** Create a style element inside `target` or <head> after the last */
export const makeStyleTag = (target?: HTMLElement): HTMLStyleElement => {
let targetDocument = document;
if(target) targetDocument = target.ownerDocument;
const head = ((targetDocument.head: any): HTMLElement);
const head = ((document.head: any): HTMLElement);
const parent = target || head;
const style = targetDocument.createElement('style');
const style = document.createElement('style');
const prevStyle = findLastStyleTag(parent);
const nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;

Expand Down