feat: inject source location data to Slice usage and show errors in places where user renders them and not in gatsby internals #36849
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
React component stack trace is not always showing source code location (see https://github.com/facebook/react/blob/2cf4352e1c81a5b8c3528519a128c20e8e65531d/packages/shared/ReactComponentStackFrame.js#L135-L137 ).
This makes it hard to show a relevant codeframe from the user when we are throwing validation errors inside gatsby / slice placeholder component internals as we would point to gatsby internals which is irrelevant to users.
This PR:
__renderedBylocation
prop to all stages aside frombuild-javascript
error.forcedLocation
on slice validation errorserror.forcedLocation
if provided (and fallback to inspecting stack trace if not) - this also needed dev server adjustments to handle cases where location is already one from source code and not the compiled code.createErrorFromString
function to be able to receive entireerror
object and not justerror.stack
(it's backward compatible, it still handles passing stack in) to make use oferror.forcedLocation
if availableResults:
gatsby develop
(regular, client-only rendering):gatsby develop
(withDEV_SSR
enabled)Same overlay as in develop + following in terminal:
gatsby build
:[ch56637]