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

StyleSheetRegistry errors #319

Closed
slaskis opened this issue Oct 17, 2017 · 16 comments
Closed

StyleSheetRegistry errors #319

slaskis opened this issue Oct 17, 2017 · 16 comments

Comments

@slaskis
Copy link

slaskis commented Oct 17, 2017

I believe we found a regression in 2.0 which only shows up in production.

It seems to be some kind of cleanup done by styled-jsx 2.0. Where empty <style jsx>{``}</style>-tags are used sometimes but removed when navigating away which causes this error:

Error: StyleSheetRegistry: styleId: `jsx-2085888330` not found.

I've added a commit to my sample repo which shows the issue when you navigate back and forth between the "pages".

@pramjeet
Copy link

I am also facing this issue in production, does anybody know a quick fix for now please?

@giuseppeg
Copy link
Collaborator

The quick fix is to not use the optimzeForSpeed mode (or rather set it to false).

@slaskis why would you use an empty style tag?

@pramjeet
Copy link

I found some empty <style jsx>{``}</style> and just removed them. It fixed the problem for me.

@giuseppeg Thanks anyway.

@slaskis
Copy link
Author

slaskis commented Oct 17, 2017

I just updated next to 4 and this started to happen in production.

I don't know why but a colleague of mine does it kind of like a template for new components which will get styles later.

I would understand if it's not supported but a better and maybe more consistent error would be nice. Now it's a pretty aggressive regression which occur when you upgrade.

@giuseppeg
Copy link
Collaborator

yup we could filter out empty rules of course :) PR are welcome!

@giuseppeg giuseppeg changed the title Error: StyleSheetRegistry: styleId: jsx-2085888330 not found. Filter out empty rules to avoid StyleSheetRegistry errors Oct 17, 2017
@rockchalkwushock
Copy link

FYI beginning work on this, wish me luck 😂 🎃 💩

@williamkunz
Copy link

@slaskis Could this be your issue? #327 (comment)

@slaskis
Copy link
Author

slaskis commented Oct 20, 2017

Looks very interesting!

@bathos
Copy link

bathos commented Nov 27, 2017

I’m seeing this error on navigation in IE11 sometimes even though I have no empty Styled JSX elements. It leads to a white screen of death — perhaps this shouldn’t be thrown, or should be thrown asynchronously so as not to prevent render altogether?

@giuseppeg
Copy link
Collaborator

As I said to @williamkunz

yeah whenever there is a parse error the rule is ignored. This happens only when optimizeForSpeed is enabled (usually automatically for production builds). To prevent surprises in prod you may want to enable optimizeForSpeed manually (via babel plugin options) while you are developing. When optimizeForSpeed is enabled and process.env.NODE_ENV !== 'production' you should get a warning.

Ideas to improve this are welcome.

@bathos
Copy link

bathos commented Nov 27, 2017

Maybe what I’m seeing is a different issue that has the same end result — it’s (a) only in prod and (b) only in IE11, and (c) erratic.

@giuseppeg
Copy link
Collaborator

@bathos you may want to enable optimizeForSpeed and debug a bit. Chances are that you have some property or rule that is not valid in IE11 and therefore the whole block is ignored.

@bathos
Copy link

bathos commented Nov 27, 2017

Thanks for the guidance, I’ll try that (I misunderstood earlier, thinking that you meant the rule had to be one which was seen as junk by Styled JSX, rather at runtime by the browser).

@zoecarver
Copy link

@giuseppeg Is this still an issue? If so, in order to fix the issue would I just need to make it ignore all empty elements (in production/optimizeForSpeed)?

Thanks

@giuseppeg
Copy link
Collaborator

@pudility to be honest I wouldn't fix this since empty rules is just one of the many reasons why this could fail. When in dev mode with optimizeForSpeed set to true people should get a warning already.

The action item could be to always set optimizeForSpeed to true and in development add a warning to inform the users that this mode is on and they should turn it off manually if they need source maps or want to edit styles with the dev tools.

This would be a breaking change though so we should reconsider when we will do the next major release.

@giuseppeg
Copy link
Collaborator

giuseppeg commented Dec 5, 2017

Gonna lock this conversation.

If anybody is experiencing similar issues, my advice is to set optimizeForSpeed to true in development so that you can catch these issues before your site makes it to prod.

Generally with optimizeForSpeed a ruleset is skipped when it contains invalid (or empty) CSS for the current browser (so it might work on IE but not in Firefox for instance). The solution here is to move browser specific rules to separate rulesets.

If you don't have a lot of dynamic styles (e.g. you don't use props in your styles) another option is to disable optimizeForSpeed in prod i.e. always.

In Next.js you can configure optimizeForSpeed via .babelrc (maybe also using next.config.js but I haven't tried that):

{
  "presets": [
    [
      "next/babel",
      {
        "styled-jsx": { "optimizeForSpeed": true }
      }
    ]
  ]
}

For regular styled-jsx users please read the README.md. optimizeForSpeed is a regular Babel plugin option.

@pudility if you want to help out maybe we can start a FAQ section in the README.md and add the info from this comment.

@vercel vercel locked and limited conversation to collaborators Dec 5, 2017
@giuseppeg giuseppeg changed the title Filter out empty rules to avoid StyleSheetRegistry errors StyleSheetRegistry errors Dec 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants