gatsby icon indicating copy to clipboard operation
gatsby copied to clipboard

perf(gatsby): add a way to skip tracking inline objects

Open axe312ger opened this issue 1 year ago • 1 comments

Description

While upgrading gatsby-source-contentful to its new version, we figured out that Gatsby is parsing JSON and Rich Text fields for references, while the plugin does handle these on its own.

In discussion with @pieh, we decided to implement a flag into Gatsby, which prevents nodes from being parsed for trackable inline objects. This is a huge performance improvement for the new gatsby-source-contentful version, while potentially providing a performance improvement to all other plugins that implement external data and/or handle references on their own.

Documentation

Nodes will get an additional, optional internal boolean property: node.internal.dontTrackInlineObjects.

By default, none of Gatsbys behavior will change. Plugin developers and users implementing their own node types have to opt into this features manually.

Tests

@todo this PR still lacks tests

Related Issues

#30855

axe312ger avatar Jan 10 '24 10:01 axe312ger

Minor NIT is we probably shouldn't use dontX in internal field names - it made some sense in our initial conversation when we considered graphql directive (@dontX similar to @dontInfer), but when talking about raw nodes - we probably should just say trackInlineObjects: false and do explicit checks (if (node.internal.trackInlineObjects === false)) (as it would be falsy by default)

EDIT: this can stay as-is for now, while I gather feedback from other folks (just to avoid busy work with unnecessary renames in case we would have to drop this idea alltogether) - so this can wait before being addressed (and just in case I can do that as well later on)

pieh avatar Jan 10 '24 14:01 pieh