Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Trouble with order of styles in output file #59

Closed
JerryCauser opened this issue Feb 16, 2018 · 2 comments
Closed

Trouble with order of styles in output file #59

JerryCauser opened this issue Feb 16, 2018 · 2 comments

Comments

@JerryCauser
Copy link

JerryCauser commented Feb 16, 2018

I'm not sure should that trouble be here or in nextjs rep, but lets start from here and if will be need ed - move this.

Let's start:
In simple way we have file like that:

import React, {Component} from 'react'
import '/styles/base.scss'
import css from './Wrapper.scss'
import Head from 'next/head'

export function withWrapper(Child) {
  class Wrapper extends Component {
    static async getInitialProps(...args){
      if (typeof Child.getInitialProps !== 'function') {
        return {}
      }
      let initialProps = Child.getInitialProps(...args)
      if (initialProps instanceof Promise) {
        initialProps = await initialProps
      }
      return initialProps
    }
    
    render() {
      return <div className={css.main}>
        <Head>
          <link rel="stylesheet" href="/_next/static/style.css"/>
        </Head>
        <Header/>
        <div className={css.container}>
          <Child {...this.props}/>
        </div>
      </div>
    }
  }
  return Wrapper
}

export default withWrapper

I expect styles in file styles/base.css will be at the top of style.css. Bcs it's my vendor.
But now styles of Wrapper.scss are at the top of the file style.css. Even more, all the styles that are in the Child component will get to the top of the file.

Looks like calling of components starts from the deepest one and all of styles adds with a push, so in the end we got: styles of deepest child will be at top of styles.css and style, what we expect to see at the top (vendor, normalize, etc...) appears at the bottom of file....

image

For myself I hacked it with spliting code in two files: vendor and app, but I think it is not the good way to solve that trouble.

@timneutkens
Copy link
Member

@JerryCauser
Copy link
Author

Yeah, it is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants