fix: respect excludeContentTypes across instances sharing a type_prefix - #279
Conversation
Gatsby's plugin cache is shared across all instances of this plugin, not namespaced per instance. When two stacks share the same type_prefix (to merge into one schema), whichever instance's createSchemaCustomization runs last overwrote the cached content-types list for both, silently dropping the other instance's excludeContentTypes. Namespace the content-types cache key by api_key everywhere it's read/written (create-schema-customization, create-resolvers, entry-data x2, source-node), and stop excluded-but-referenced content types from sneaking back in via reference-field resolution in contenttype-data's FetchUnspecifiedContentTypes. Fixes DX-9470.
…-release/npm - fast-uri -> 3.1.5 (SNYK-JS-FASTURI-18506908) - brace-expansion -> 5.0.9 (SNYK-JS-BRACEEXPANSION-18512280) - postcss -> 8.5.23 (SNYK-JS-POSTCSS-18512282) - @semantic-release/npm forced to 13.1.5 everywhere, removing the duplicate older 12.0.2 branch (and its vulnerable bundled npm/tar) that semantic-release's own dependency tree still pulled in nanoid and react-dev-utils remain unfixed: nanoid's fix is ESM-only and breaks postcss's CJS require; react-dev-utils@12.0.1 is gatsby's own dependency and the latest available stable release.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
✅ BUILD PASSED - All security checks passed |
There was a problem hiding this comment.
Pull request overview
This PR fixes a multi-instance caching collision in gatsby-source-contentstack where excludeContentTypes could be ignored when two plugin instances share the same type_prefix, by namespacing the cached content-types list with api_key. It also tightens excludeContentTypes behavior for referred content types and updates dependency overrides/lockfile accordingly.
Changes:
- Namespace the cached content-types list key as
${type_prefix}_${api_key}across all read/write sites to prevent cross-instance cache overwrites. - Ensure referred content types fetched via reference fields don’t reintroduce content types listed in
excludeContentTypes. - Add unit coverage for the cache isolation + referred-content-types filtering, and update dependency overrides / lockfile.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/create-schema-customization.js | Writes the content-types cache entry using a key that includes api_key. |
| src/create-resolvers.js | Reads content types from the namespaced cache key. |
| src/entry-data.js | Reads content types from the namespaced cache key in both entry-fetch flows. |
| src/source-node.js | Reads content types from the namespaced cache key during sourcing. |
| src/contenttype-data.js | Filters referred content types using excludeContentTypes. |
| src/tests/exclude-content-types.test.js | Adds unit tests for cache key isolation and referred-type filtering. |
| tests/exclude-content-types.test.js | Compiled/built copy of the new unit tests. |
| package.json | Bumps version and updates overrides (incl. patched dependency versions / dedupe). |
| package-lock.json | Lockfile updates reflecting the dependency/override changes. |
| .talismanrc | Adds checksum allowlists for newly changed files (flagged in review). |
Files not reviewed (1)
- tests/exclude-content-types.test.js: Generated file
Suppressed comments (1)
.talismanrc:13
- .talismanrc: Checksum allowlists for test files also bypass Talisman scanning for those files when the checksum matches. If these were added due to a false positive, it’s safer to address the triggering content or apply a narrowly-scoped ignore rather than allowlisting entire files by checksum.
- filename: src/tests/exclude-content-types.test.js
checksum: 4acbcfad3da0e20b6150ce47054668b629db9ddd8362d3a96fadb3a770a0f5a4
- filename: tests/exclude-content-types.test.js
checksum: 907f5d9ee53a42774f4ecbc361dc6b2cd6f278ed7dbf6dd6cf071d4f478a4b67
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fixes DX-9470. A customer reported that
excludeContentTypesis silently ignored when twogatsby-source-contentstackinstances share the sametype_prefix(e.g. a main stack + a shared/publisher stack merged into one schema). Customer opened PR #277 with a fix; per policy we don't merge code from an external fork directly, so this reimplements the fix ourselves after verifying the root cause and the intended behavior independently.Root cause: Gatsby's plugin cache is shared across all instances of this plugin, not namespaced per instance/options. The content-types list was cached under a bare
type_prefixkey (unlike most other cache keys in this codebase, which already suffix withapi_key). When two instances sharetype_prefix, whichever instance'screateSchemaCustomizationruns last overwrites that key for both, so the instance withexcludeContentTypesreads back the other instance's unfiltered list.Fix:
api_keyat all 5 read/write sites (create-schema-customization.js,create-resolvers.js,entry-data.jsx2,source-node.js) — this is the root-cause fix, not a re-filter patch at a couple of call sites.contenttype-data.js: excluded content types no longer sneak back in via a reference field on an included content type (FetchUnspecifiedContentTypes's referred-content-types lookup wasn't filtered byexcludeContentTypes).fast-uri,brace-expansion,postcssto their fixed versions, and deduped@semantic-release/npmto remove a duplicate older/vulnerable branch pulled in bysemantic-release's own dependency tree.Test plan
src/tests/exclude-content-types.test.js): two configs sharing atype_prefixwith differentapi_keys and differentexcludeContentTypesno longer collide; referred-content-types filter verified in isolation.npm test— full suite passes.type_prefix, each with its ownexcludeContentTypes, using the contentstack-gatsby-starter-app: