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

should critical be a the top of head? #39

Closed
sndrs opened this issue Oct 8, 2019 · 5 comments · Fixed by #40
Closed

should critical be a the top of head? #39

sndrs opened this issue Oct 8, 2019 · 5 comments · Fixed by #40
Labels
bug Something isn't working

Comments

@sndrs
Copy link

sndrs commented Oct 8, 2019

first of all, thanks for creating this plugin, i love it :)

i have a question regarding this bit:

https://github.com/silvenon/gatsby-plugin-linaria/blob/a52b2cb3a2b0e59847ef0fdb291357008e1a325c/src/gatsby-ssr.js#L35-L43

i'm adding a reset by just doing import 'reset.css' and having gatsby inject it into the head. the same with some @font-faces.

when using this plugin, the linaria's critical css is inserted before any other css i've added.

this instinctively feels the wrong way round to me – i was wondering what your reason was for choosing this order?

@silvenon silvenon added the bug Something isn't working label Oct 12, 2019
@silvenon
Copy link
Collaborator

🤔 I agree with you. @cometkim what do you think?

@cometkim
Copy link
Owner

Gatsby merges all loaded styles into common.css by default and extracts them via mini-css-extractor. This plugin increases the priority of linaria css and separates it from common.css and attached it with order according to the actual resource priorities set in webpack config.

In most cases, this is not a problem because linaria is used for scoped style. However, declaring global styles in both ways(linaria and others) can be confusing no matter how we ordered it.

@silvenon
Copy link
Collaborator

silvenon commented Oct 14, 2019

If we imagine Linaria with other styles like this:

import { styled } from 'linaria/react'
import '../styles/reset.css'

styled`
  body {
    background: purple;
    color: white;
  }
`

or if reset.css had been imported in gatsby-browser.js, whatever, I would expect the styles from reset.css to be added before Linaria's global styles. I can't think of a case where it wouldn't be obvious how we should order the styles. 🤔

@cometkim
Copy link
Owner

Oh, actually styles already ordered how you expected, because this plugin attaches the same styles in the bottom of .

We have another possible problem is: we can get blink of css problem if we use global styles with linaria.

for exam:

import { css } from 'linaria';

/**
 * in other.css
 * body { background: red; }
 */
import './other.css';

export const globalStyles = css`
  :global() {
    body { background: blue }
  }
`;

The result background color of body tag is RED in first paint, but it instantly changed into BLUE after fetching linaria's full css.

@silvenon
Copy link
Collaborator

silvenon commented Nov 16, 2019

Fix published in v2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants