@@ -47,6 +47,7 @@ type NormalisedEntity<E extends FullEntity = FullEntity> = E extends any
47
47
export class NodeManager {
48
48
private createNode : NodePluginArgs [ 'actions' ] [ 'createNode' ] ;
49
49
private deleteNode : NodePluginArgs [ 'actions' ] [ 'deleteNode' ] ;
50
+ private touchNode : NodePluginArgs [ 'actions' ] [ 'touchNode' ] ;
50
51
private createNodeId : NodePluginArgs [ 'createNodeId' ] ;
51
52
private createContentDigest : NodePluginArgs [ 'createContentDigest' ] ;
52
53
private cache : NodePluginArgs [ 'cache' ] ;
@@ -59,7 +60,7 @@ export class NodeManager {
59
60
constructor ( args : NodePluginArgs ) {
60
61
/* eslint-disable @typescript-eslint/unbound-method */
61
62
const {
62
- actions : { createNode, deleteNode } ,
63
+ actions : { createNode, deleteNode, touchNode } ,
63
64
cache,
64
65
createContentDigest,
65
66
createNodeId,
@@ -70,6 +71,7 @@ export class NodeManager {
70
71
this . cache = cache ;
71
72
this . createNode = createNode ;
72
73
this . deleteNode = deleteNode ;
74
+ this . touchNode = touchNode ;
73
75
this . createNodeId = createNodeId ;
74
76
this . createContentDigest = createContentDigest ;
75
77
this . reporter = reporter ;
@@ -88,7 +90,7 @@ export class NodeManager {
88
90
89
91
// for the usage of createNode
90
92
// 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 ) ) ;
92
94
this . updateNodes ( this . findUpdatedEntities ( oldMap , newMap ) ) ;
93
95
this . removeNodes ( this . findRemovedEntities ( oldMap , newMap ) ) ;
94
96
@@ -99,9 +101,26 @@ export class NodeManager {
99
101
* add new nodes
100
102
* @param added new nodes to be added
101
103
*/
102
- private addNodes ( added : NormalisedEntity [ ] ) : void {
104
+ private async addNodes ( added : NormalisedEntity [ ] ) : Promise < void > {
103
105
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
+ } ) ;
105
124
}
106
125
107
126
// don't be noisy if there's nothing new happen
0 commit comments