Skip to content

Props don't get applied on some divs when using gatsby-plugin-offline #6059

@Maistho

Description

@Maistho

Description

Props don't get applied to top level divs when using gatsby-plugin-offline and gatsby-plugin-react-next

The bug manifests on top level divs or divs that are top level inside a Fragment. No props seem to be applied. Other types of elements get props applied as usual.

Steps to reproduce

This repo is based on gatsby-starter-blog:
https://github.com/Maistho/gatsby-offline-react-next-issue/commit/a9e6bbc7d0df4de28707a5a2ca0e0eae2a1785ae

Download the repo and run

gatsby build
gatsby serve

Then open up the browser on a blog post and reload the page. Make sure that service workers are not deactivated.

Expected result

Props should be applied

Actual result

Props are not applied

Environment

Not sure why, but I get some TypeErros when running gatsby info

File contents (if changed)

diff --git a/gatsby-config.js b/gatsby-config.js
index 43a2167..d89ea61 100644
--- a/gatsby-config.js
+++ b/gatsby-config.js
@@ -45,6 +45,7 @@ module.exports = {
       },
     },
     `gatsby-plugin-feed`,
+    `gatsby-plugin-react-next`,
     `gatsby-plugin-offline`,
     `gatsby-plugin-react-helmet`,
     {
diff --git a/package.json b/package.json
index 0a31236..836490d 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,9 @@
     "gatsby-link": "^1.6.39",
     "gatsby-plugin-feed": "^1.3.20",
     "gatsby-plugin-google-analytics": "^1.0.29",
-    "gatsby-plugin-offline": "^1.0.15",
+    "gatsby-plugin-offline": "^1.0.18",
     "gatsby-plugin-react-helmet": "^1.0.8",
+    "gatsby-plugin-react-next": "^1.0.11",
     "gatsby-plugin-sharp": "^1.6.42",
     "gatsby-plugin-typography": "^1.7.18",
     "gatsby-remark-copy-linked-files": "^1.5.31",
diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js
index 1231b3d..c0e0f36 100644
--- a/src/templates/blog-post.js
+++ b/src/templates/blog-post.js
@@ -3,6 +3,7 @@ import Helmet from 'react-helmet'
 import Link from 'gatsby-link'
 import get from 'lodash/get'
 
+import styles from './blog-post.module.css'
 import Bio from '../components/Bio'
 import { rhythm, scale } from '../utils/typography'
 
@@ -13,9 +14,22 @@ class BlogPostTemplate extends React.Component {
     const { previous, next } = this.props.pathContext
 
     return (
-      <div>
+      <React.Fragment>
         <Helmet title={`${post.frontmatter.title} | ${siteTitle}`} />
-        <h1>{post.frontmatter.title}</h1>
+        <h1 className={styles.test}>this h1 will get the green class</h1>
+        <div
+          id="test"
+          style={{ background: 'green' }}
+          className={`test ${styles.test}`}
+        >
+          this div will not get any props
+          <div className={styles.test}>But nested divs get props</div>
+          It's a bit weird
+        </div>
+        <section className={styles.test}>
+          But it seems like other tags will get props. This section for example.
+        </section>
+        <h1 className={styles.test}>this h1 will also get the class</h1>
         <p
           style={{
             ...scale(-1 / 5),
@@ -59,7 +73,7 @@ class BlogPostTemplate extends React.Component {
             </li>
           )}
         </ul>
-      </div>
+      </React.Fragment>
     )
   }
 }
diff --git a/src/templates/blog-post.module.css b/src/templates/blog-post.module.css
new file mode 100644
index 0000000..5f18c30
--- /dev/null
+++ b/src/templates/blog-post.module.css
@@ -0,0 +1,3 @@
+.test {
+  background: green;
+}

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssue with a clear description that the community can help with.type: question or discussionIssue discussing or asking a question about Gatsby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions