@@ -47,6 +47,7 @@ type NormalisedEntity<E extends FullEntity = FullEntity> = E extends any
4747export class NodeManager {
4848 private createNode : NodePluginArgs [ 'actions' ] [ 'createNode' ] ;
4949 private deleteNode : NodePluginArgs [ 'actions' ] [ 'deleteNode' ] ;
50+ private touchNode : NodePluginArgs [ 'actions' ] [ 'touchNode' ] ;
5051 private createNodeId : NodePluginArgs [ 'createNodeId' ] ;
5152 private createContentDigest : NodePluginArgs [ 'createContentDigest' ] ;
5253 private cache : NodePluginArgs [ 'cache' ] ;
@@ -59,7 +60,7 @@ export class NodeManager {
5960 constructor ( args : NodePluginArgs ) {
6061 /* eslint-disable @typescript-eslint/unbound-method */
6162 const {
62- actions : { createNode, deleteNode } ,
63+ actions : { createNode, deleteNode, touchNode } ,
6364 cache,
6465 createContentDigest,
6566 createNodeId,
@@ -70,6 +71,7 @@ export class NodeManager {
7071 this . cache = cache ;
7172 this . createNode = createNode ;
7273 this . deleteNode = deleteNode ;
74+ this . touchNode = touchNode ;
7375 this . createNodeId = createNodeId ;
7476 this . createContentDigest = createContentDigest ;
7577 this . reporter = reporter ;
@@ -88,7 +90,7 @@ export class NodeManager {
8890
8991 // for the usage of createNode
9092 // see https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNode
91- this . addNodes ( this . findNewEntities ( oldMap , newMap ) ) ;
93+ await this . addNodes ( this . findNewEntities ( oldMap , newMap ) ) ;
9294 this . updateNodes ( this . findUpdatedEntities ( oldMap , newMap ) ) ;
9395 this . removeNodes ( this . findRemovedEntities ( oldMap , newMap ) ) ;
9496
@@ -99,9 +101,26 @@ export class NodeManager {
99101 * add new nodes
100102 * @param added new nodes to be added
101103 */
102- private addNodes ( added : NormalisedEntity [ ] ) : void {
104+ private async addNodes ( added : NormalisedEntity [ ] ) : Promise < void > {
103105 for ( const entity of added ) {
104- this . createNode ( this . nodifyEntity ( entity ) ) ;
106+ const node = this . nodifyEntity ( entity ) ;
107+
108+ // DEBT: disable a false alarm from eslint as currently Gatsby is exporting an incorrect type
109+ // this should be removed when https://github.com/gatsbyjs/gatsby/pull/32522 is merged
110+ /* eslint-disable @typescript-eslint/await-thenable */
111+ // create the node
112+ await this . createNode ( node ) ;
113+ /* eslint-enable */
114+
115+ // make sure that the node will remain in the cache
116+ this . touchNode ( {
117+ // since createNode mutates node, reconstruct the node input again here
118+ id : node . id ,
119+ internal : {
120+ type : node . internal . type ,
121+ contentDigest : node . internal . contentDigest ,
122+ } ,
123+ } ) ;
105124 }
106125
107126 // don't be noisy if there's nothing new happen
0 commit comments