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

Fixes sheet ordering #819

Merged
merged 4 commits into from
Aug 12, 2018
Merged

Fixes sheet ordering #819

merged 4 commits into from
Aug 12, 2018

Conversation

HenriBeck
Copy link
Member

@HenriBeck HenriBeck commented Aug 9, 2018

Fixes the sheet ordering as described in #816

  • Fix is implemented
  • Updated a test case which failed before

prevNode returns now an object because nextSibling may return null when it's the last element which results in not being able to get the parent for the insertion.

const {registry} = sheets

if (registry.length > 0) {
// Try to insert before the next higher sheet.
let sheet = findHigherSheet(registry, options)
if (sheet) return sheet.renderer.element
if (sheet) {
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like calling parentNode in advance doesn't bring much value other than makes findPrevNode semantics wrong. Mb I oversee something but to me it looks like we could keep the return value as it was.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is when returning nextSibling and when it returns null we can't get the parentNode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arent you appending in the end of the head when nextSibling is null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily, it was supposed to work with appending it at the end of the parent of the stylesheet

@@ -268,7 +289,7 @@ function insertStyle(style: HTMLElement, options: PriorityOptions) {
return
}

getHead().insertBefore(style, prevNode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it worked basically before same way, because the insertBefore api allows to pass prevNode === null and it will be inserted in the end of the parent, so the same as appendChild

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a bit simpler to me

Copy link
Member

@kof kof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I haven't found a better way. The logic there is still too complex, we might want to simplify it at some point, but I am fine with merging it now.

@kof
Copy link
Member

kof commented Aug 11, 2018

We should have supported an insertion point as node as the only argument, I think this would simplify it.

@HenriBeck
Copy link
Member Author

I don't think it would simplify much because the only code which could be removed is: https://github.com/cssinjs/jss/blob/master/packages/jss/src/renderers/DomRenderer.js#L235-L243

@HenriBeck HenriBeck merged commit bfbb47c into master Aug 12, 2018
@HenriBeck HenriBeck deleted the fix-sheet-ordering branch August 12, 2018 20:46
bhupinderbola pushed a commit to bhupinderbola/jss that referenced this pull request Sep 17, 2019
* Added failing test for the ordering issue

* Added fix for the issue

* Update size-snapshots

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants