Skip to content

Commit 7a82dc2

Browse files
johnosidharthachatterjee
authored andcommitted
fix(themes): Handle shared parent theme with component shadowing (#12883)
If gatsby-theme-a and gatsby-theme-b both install and use gatsby-theme-c (as a parent theme) this would cause an error to be raised when either sibling theme shadowed a component from gatsby-theme-c when it should be ignored.
1 parent 7ddb332 commit 7a82dc2

File tree

1 file changed

+8
-2
lines changed
  • packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing

1 file changed

+8
-2
lines changed

packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require(`path`)
22
const debug = require(`debug`)(`gatsby:component-shadowing`)
33
const fs = require(`fs`)
4+
const _ = require(`lodash`)
45

56
module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
67
cache = {}
@@ -14,10 +15,15 @@ module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
1415
apply(resolver) {
1516
resolver.plugin(`relative`, (request, callback) => {
1617
// find out which theme's src/components dir we're requiring from
17-
const matchingThemes = this.themes.filter(name =>
18+
const allMatchingThemes = this.themes.filter(name =>
1819
request.path.includes(path.join(name, `src`))
1920
)
20-
// 0 matching themes happens a lot fo rpaths we don't want to handle
21+
22+
// The same theme can be included twice in the themes list causing multiple
23+
// matches. This case should only be counted as a single match for that theme.
24+
const matchingThemes = _.uniq(allMatchingThemes)
25+
26+
// 0 matching themes happens a lot for paths we don't want to handle
2127
// > 1 matching theme means we have a path like
2228
// `gatsby-theme-blog/src/components/gatsby-theme-something/src/components`
2329
if (matchingThemes.length > 1) {

0 commit comments

Comments
 (0)