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

Placeholder <style> tag ignored by rehydration logic #1845

Closed
dylmye opened this issue Jul 13, 2018 · 19 comments
Closed

Placeholder <style> tag ignored by rehydration logic #1845

dylmye opened this issue Jul 13, 2018 · 19 comments

Comments

@dylmye
Copy link

dylmye commented Jul 13, 2018

(I haven't provided a failing test PR because I'm unsure how to use Jest, apologies)

Environment

npx envinfo --system --binaries --npmPackages styled-components,babel-plugin-styled-components --markdown --clipboard breaks, here's what it looks like:

npx: installed 1 in 1.783s
Path must be a string. Received undefined
npx: installed 1 in 1.849s
C:\Users\dylan\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js

## System:
 - OS: Windows 10
 - CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
 - Memory: 6.35 GB / 15.89 GB
## Binaries:
 - Yarn: 1.6.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
 - npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD

(node:4172) UnhandledPromiseRejectionWarning: Error: The system cannot find the path specified.

    at Function.e.exports.sync (C:\Users\[...]\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js:2:7690)
    at Object.copySync (C:\Users\[...]\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js:2:104342)
    at Object.t.writeSync.e [as writeSync] (C:\Users\[...]\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js:2:122592)
    at C:\Users\[...]\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js:2:123354
    at Promise.all.then.e (C:\Users\[...]\AppData\Roaming\npm-cache\_npx\4172\node_modules\envinfo\dist\cli.js:2:123369)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:4172) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4172) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I'm using styled-components@^3.3.3

Reproduction

https://codesandbox.io/s/oq1j5q52n9

Please inspect the head of the document in the iframe. It should look like this:
Rendered output

and the template document, you should be able to observe the following:
head snippet

Steps to reproduce

  1. Include styled-components in your react project (non-SSR), add a styled component
  2. Add the following tag to the head of the template React is putting <App /> into: <style data-styled-components="true"></style> (Documentation Source)

Expected Behavior

Actual Behavior

  • styled-components creates another css element at the bottom of <head>
@dylmye dylmye changed the title Placeholder <style> tag ignored by rehydration logic Bug Report: Placeholder <style> tag ignored by rehydration logic Jul 13, 2018
@dylmye
Copy link
Author

dylmye commented Jul 16, 2018

Could any contributors confirm that this logic is indeed still intended to work? Or can anyone provide a working example of this logic?

@quantizor
Copy link
Contributor

This does appear to be a bug I think @kitten

@dylmye
Copy link
Author

dylmye commented Jul 20, 2018

Tried downgrading to 3.2.3 (as per here) and still getting issues... any ideas? Again we're not using SSR. I also see that there's a test for this logic, injectGlobal.

@quantizor
Copy link
Contributor

I’m looking into this as I have bandwidth, fyi.

@dylmye dylmye changed the title Bug Report: Placeholder <style> tag ignored by rehydration logic Placeholder <style> tag ignored by rehydration logic Aug 14, 2018
@dylmye
Copy link
Author

dylmye commented Aug 28, 2018

Any chance of getting support for this in 5.0? Thanks

@quantizor
Copy link
Contributor

I can't make any promises. Getting this to work requires a major refactoring to the way our Stylesheet works. I tried to fix it for 4.0 and couldn't make any useful progress.

@dylmye
Copy link
Author

dylmye commented Aug 28, 2018

Thanks for the update. Internally we've switched to emotion but it would be great to switch back as s-c can be a joy to work with :)

Is it ok for me to make a PR against the documentation repo?

@huchenme
Copy link

I thought this was already implemented and just checked that this feature have been removed from the documentation :(

@quantizor
Copy link
Contributor

quantizor commented Sep 17, 2018 via email

@huchenme
Copy link

I think it was removed 16 days ago: styled-components/styled-components-website@c3fe582#diff-badb5964ab969ebb5836d448e2d4c3b8

  Alternatively, if you want to keep using single classname selectors in your stylesheet and make	
  them win over rules generated by styled-components, you can change the relative order of the	
  competing tags. That means either moving your stylesheet \`<link>\` tags down into the \`<body>\`,	
  or moving the styled-components \`<style>\` tag(s) up. You can control where styled-components	
  renders its styles by creating a placeholder tag with the \`data-styled-components\` attribute:	
   \`\`\`html	
  <head>	
    <style data-styled-components="true"></style>	
    <link rel="stylesheet" href="my-component.css"/>	
  </head>	
  \`\`\`

@ramiel
Copy link

ramiel commented Oct 10, 2018

Any news on this? Any chance to have this supported?

@quantizor
Copy link
Contributor

quantizor commented Oct 10, 2018 via email

@blakek
Copy link

blakek commented Feb 14, 2019

We were moving a site with existing external styles and styled-components v2.x to the latest v4 and ran across this issue. The external styles require the global style be loaded after the <style /> tag generated by styled-components. For now, we've worked around the issue by moving the external style links into the body tag.

Is there any method that exists to specify the location of the style tag in the head?

Thanks!

@ramiel
Copy link

ramiel commented Mar 3, 2019

Nope. We’ll look at it after v4 is out

Now that version 4 is out, has this issue been resolved?

@cpmsmith
Copy link

I've taken a crack at this in #2463 😄

@myronliu347
Copy link

When will this problem be fixed?

@dylmye
Copy link
Author

dylmye commented Apr 26, 2019

Just bumping for a review of #2463 :)

@brendonco
Copy link

any plan to merge this on future release? #2463

@kitten
Copy link
Member

kitten commented Aug 9, 2021

Closing due to age, inactivity, missing reproduction, or lack of details.

@kitten kitten closed this as completed Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants