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

The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. #6998

Closed
ringodotnl opened this issue Jun 6, 2019 · 74 comments

Comments

@ringodotnl
Copy link

ringodotnl commented Jun 6, 2019

Describe the bug
At the console: The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".

To Reproduce
Run the angular demo in this repo and check the console.

Expected behavior
No error log

System:

  • OS: [Windows10,]
  • Device: [Desktop]
  • Browser: [Chrome]
  • Framework: [angular]
  • Addons: [all]
  • Version: [5.1.1 and 5.2.0-alpha.21]
@NickSofology
Copy link

I have also got this error since upgrading.

@magicspon
Copy link

I'm also seeing this... except with React.

@javidhsueh
Copy link

same here with React
Version: SB@v5.1.3

@Nightbr
Copy link

Nightbr commented Jun 11, 2019

Same here after upgrading:

    "@storybook/addon-actions": "^5.1.3",
    "@storybook/addon-backgrounds": "^5.1.3",
    "@storybook/addon-knobs": "^5.1.3",
    "@storybook/addon-notes": "^5.1.3",
    "@storybook/html": "^5.1.3",
    "@storybook/theming": "^5.1.3",

@B3Kay
Copy link

B3Kay commented Jun 12, 2019

Im also seeing this error with React:

"react": "^16.4.0",
"react-dom": "^16.4.0"
 "@storybook/addon-links": "^5.0.11",
 "@storybook/addon-notes": "^5.0.11",
 "@storybook/addon-storyshots": "^5.0.11",
 "@storybook/addon-storyshots-puppeteer": "^5.0.11",
 "@storybook/addon-storysource": "^5.0.11",
 "@storybook/addons": "^5.0.11",

@nmorris2
Copy link

Also seeing the same error with Storybook and Vue after upgrading to 5.1.3.

@6thpath
Copy link

6thpath commented Jun 14, 2019

"@storybook/react" "^5.1.7"

The error still there

@HiHiPoBang
Copy link

"vue": "^2.6.10"
"@storybook/addon-actions": "^5.1.7",
"@storybook/addon-links": "^5.1.7",
"@storybook/addons": "^5.1.7",
"@storybook/vue": "^5.1.7"

The error is still there after upgrading (v5.1.3 -> v5.1.7)
repo: https://github.com/HiHiPoBang/storybook-demo

@shilman
Copy link
Member

shilman commented Jun 14, 2019

@HiHiPoBang we'll comment here when the issue is fixed. Or feel free to issue a PR to fix it if you're in a rush! 👍

@gms1
Copy link

gms1 commented Jun 15, 2019

the upstream bug:
emotion-js/emotion#1105

@kon-rad
Copy link

kon-rad commented Jun 17, 2019

same here - react 16.6.3

@gabimoncha
Copy link

Same here!

 "@storybook/addon-actions": "^5.1.9",
 "@storybook/react": "^5.1.9",

@VladimirHumeniuk
Copy link

Any updates about this? 🤔

@ashnamuh
Copy link

ashnamuh commented Jul 8, 2019

I have a same issue on

    "@storybook/addon-actions": "^5.1.9",
    "@storybook/vue": "^5.1.9",

@rajkeshwar
Copy link

I have same issue on

    "@storybook/addon-actions": "^5.1.9",
    "@storybook/addon-links": "^5.1.9",
    "@storybook/addons": "^5.1.9",
    "@storybook/react": "^5.1.9",

@Travilioni
Copy link

Only deactivating these addons, resolves issue.
unfortunately we need them.
"@storybook/addon-a11y": "5.1.9", "@storybook/addon-actions": "5.1.9", "@storybook/addon-knobs": "5.1.9",

@omrilotan
Copy link

omrilotan commented Jul 16, 2019

The reason for this error has to do with <style> elements being added inline in the DOM when doing SSR.
It seems to me that the recommendation is a good one. Using :first-of-type will resolve this.

Other, more generic alternative may be:

& > :first-child:not(style), & > style:first-child + * {

@leetercola
Copy link

& > :first-child:not(style), & > style:first-child + * {

@omrilotan
Can you explain how this is any better and would stop the warning as it still uses first-child?

@omrilotan
Copy link

omrilotan commented Jul 18, 2019

@leetercola :

& > :first-child:not(style), & > style:first-child + * {

Can you explain how this is any better and would stop the warning as it still uses first-child?

Of course. This selector is made up of two parts:

  1. & > :first-child:not(style) The first child unless it is a style tag
  2. & > style:first-child + * The adjacent sibling immediate following a first element which is a style tag

Thus covering both options.

<parent>
	<style/>
	<child/> <!-- this one -->
	<other-child/>
</parent>

<parent>
	<child/> <!-- this one -->
	<other-child/>
</parent>

@Haroenv
Copy link
Contributor

Haroenv commented Jul 23, 2019

IIRC the css to change is here:

'& > *:first-child': {

@lsebastiankellner
Copy link

Same here after upgrading to 6.5.4 :(

@jeripeierSBB
Copy link

See #18103

@vdh
Copy link
Contributor

vdh commented May 25, 2022

For anyone else wanting to hack this annoyance away with a yarn patch, I found it hiding away inside @storybook/theming.

@antsukanova
Copy link

Same here at 6.5.6 as well

@rv7918
Copy link

rv7918 commented Jun 3, 2022

6.5.6 also.

@fivaz
Copy link

fivaz commented Jun 4, 2022

the same with storybook/react 6.5.5

@lukePeavey
Copy link

@vdh could you explain what you mean by this?

For anyone else wanting to hack this annoyance away with a yarn patch, I found it hiding away inside @storybook/theming

@euaaaio
Copy link

euaaaio commented Jun 5, 2022

The same

@xxxKOTxxx
Copy link

6.5.7 - same problem
Anybody cares?

@calidan-x
Copy link

6.5.7 - same problem

@vdh
Copy link
Contributor

vdh commented Jun 10, 2022

@lukePeavey

@vdh could you explain what you mean by this?

For anyone else wanting to hack this annoyance away with a yarn patch, I found it hiding away inside @storybook/theming

createUnsafeSelectorsAlarm inside @storybook/theming is what is generating this log spam. It can be patched away via Yarn (yarn patch @storybook/theming) and this patch:

diff --git a/dist/cjs/index.js b/dist/cjs/index.js
index 1b8b61eac2d191f1a8e1421a57d2738b37d06937..9137b52c3b624ccc3ac980799785da12f1c93ff9 100644
--- a/dist/cjs/index.js
+++ b/dist/cjs/index.js
@@ -1396,15 +1396,6 @@ var createCache = function createCache(options) {
 
   var omnipresentPlugins = [compat, removeLabel];
 
-  if (process.env.NODE_ENV !== 'production') {
-    omnipresentPlugins.push(createUnsafeSelectorsAlarm({
-      get compat() {
-        return cache.compat;
-      }
-
-    }), incorrectImportAlarm);
-  }
-
   if (isBrowser$6) {
     var currentSheet;
     var finalizingPlugins = [stringify, process.env.NODE_ENV !== 'production' ? function (element) {
diff --git a/dist/esm/index.js b/dist/esm/index.js
index e7b796a97d657ea711285724a54b40d4c4e06ccf..f65669abd258db602d3d9e32e9b70d7f9002ebda 100644
--- a/dist/esm/index.js
+++ b/dist/esm/index.js
@@ -1445,15 +1445,6 @@ var createCache = function createCache(options) {
 
   var omnipresentPlugins = [compat, removeLabel];
 
-  if (process.env.NODE_ENV !== 'production') {
-    omnipresentPlugins.push(createUnsafeSelectorsAlarm({
-      get compat() {
-        return cache.compat;
-      }
-
-    }), incorrectImportAlarm);
-  }
-
   if (isBrowser$6) {
     var currentSheet;
     var finalizingPlugins = [stringify, process.env.NODE_ENV !== 'production' ? function (element) {
diff --git a/dist/modern/index.js b/dist/modern/index.js
index 4006f0846b2711d82fef0cad026814307192ba98..f6b2b560e3a708a18830bd2c9139b7f4a622cf33 100644
--- a/dist/modern/index.js
+++ b/dist/modern/index.js
@@ -1366,15 +1366,6 @@ var createCache = function createCache(options) {
 
   var omnipresentPlugins = [compat, removeLabel];
 
-  if (process.env.NODE_ENV !== 'production') {
-    omnipresentPlugins.push(createUnsafeSelectorsAlarm({
-      get compat() {
-        return cache.compat;
-      }
-
-    }), incorrectImportAlarm);
-  }
-
   if (isBrowser$6) {
     var currentSheet;
     var finalizingPlugins = [stringify, process.env.NODE_ENV !== 'production' ? function (element) {

@shilman
Copy link
Member

shilman commented Jun 10, 2022

Please try upgrading to the latest release https://github.com/storybookjs/storybook/releases/tag/v6.5.8

npx storybook upgrade

Does that fix it?

@xxxKOTxxx
Copy link

xxxKOTxxx commented Jun 10, 2022

Does that fix it?

For me - yes!
Thank You!

@rv7918
Copy link

rv7918 commented Jun 10, 2022

The console error has gone after upgrading to 6.5.8 for me. also.

@BiancaArtola
Copy link

BiancaArtola commented Jun 10, 2022

That works for me! Thanks

@shilman
Copy link
Member

shilman commented Jun 10, 2022

Huge props to @Andarist 🙌

@lukePeavey
Copy link

@vdh thank you for the explanation!

Upgrading to v6.5.8 resolved the issue for me.

lukePeavey added a commit to lukePeavey/SplitType that referenced this issue Jun 11, 2022
Fixes several annoying console errors in storybook.
storybookjs/storybook#6998
@katsenkatorz
Copy link

Upgrading to v6.5.9 it's work for me thanks @shilman

@antsukanova
Copy link

Upgrading to v6.5.9 doesn't work for me

still, there is a message in the browser console

The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".

@charleshimmer
Copy link

Upgrading to v6.5.9 does not work for me as well.

@antsukanova
Copy link

Upgrading to v6.5.10 doesn't work for me

@scrptd95
Copy link

Also comes up in v6.5.14. Any solutions for the issue ?

@ScorpAL
Copy link

ScorpAL commented Dec 21, 2022

Also comes up in v6.5.15

@RobineSavert
Copy link

Any updates on this? We have the same error...

@krakadet
Copy link

The same error at storybook 7

@idMolotov
Copy link

Also appears in v6.5.16

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

No branches or pull requests