Skip to content

Conversation

@shoplando
Copy link
Contributor

@shoplando shoplando commented Oct 9, 2025

What are you adding in this PR?

Disabled the "Undefined Object" theme check for the new snippet tag to prevent false positives.
This change also includes making the check scope-aware based on inline snippets' doc tag parameters.

Behaviour before change:

image.png

image.png

Behaviour after change:

image.png

image.png

Before you deploy

  • I included a minor bump changeset
  • My feature is backward compatible

Copy link
Contributor Author

shoplando commented Oct 9, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shoplando shoplando marked this pull request as ready for review October 9, 2025 15:59
@shoplando shoplando requested a review from a team as a code owner October 9, 2025 15:59
@shoplando shoplando changed the base branch from include-snippet-in-ohm to graphite-base/1071 October 14, 2025 13:53
@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from dc2709d to 59d92da Compare October 14, 2025 13:53
@graphite-app graphite-app bot changed the base branch from graphite-base/1071 to main October 14, 2025 13:53
@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from 59d92da to 6189068 Compare October 14, 2025 13:53

if (parent?.type === NodeTypes.RenderMarkup && parent.snippet === node) return;

if (isLiquidTag(parent) && parent.name === 'snippet' && parent.markup === node) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be a temporary fix or something instead of just adding it our list of valid liquid tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already added snippet to our list of valid liquid tags (in packages/liquid-html-parser/src/types.ts) but it still warns me 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because we load the tags from a different repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that repo is used for the documentation, autocomplete and validation of the tag itself. And also the capture tag is using a similar approach by skipping over the newly defined object in the capture tag so that the theme check won't warn you about it (I might just use the same format as the capture case)

@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from 29f7468 to a2a2a95 Compare October 16, 2025 17:53
@shoplando shoplando requested a review from a team October 16, 2025 17:55
@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from a2a2a95 to d859b07 Compare October 16, 2025 18:42
Comment on lines +75 to +92
indexVariableScope(paramName, {
start: snippetAncestor.blockStartPosition.end,
end: snippetAncestor.blockEndPosition?.start,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL Cool didn't even know we had a variable scope like this

@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from d859b07 to fa207a1 Compare October 21, 2025 20:24
const parent = last(ancestors);
if (isLiquidTag(parent) && isLiquidTagCapture(parent)) return;

if (isLiquidTag(parent) && isLiquidTagSnippet(parent) && parent.markup === node) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the parent.markup === node part supposed to catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an oversight on my part. I think I added that before creating the isLiquidTagSnippet() function and forgot to remove it. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i think you have the right logic, but i think you need to modify the logic on line 48:

if (relativePath.startsWith('snippets/') && !hasLiquidDoc(ast)) return {};

This might not make too much sense, but here is the logic:

  • There exists real world snippets (especially old ones) that DONT have doc tag
  • The code above ensures that we only have UndefinedObject errors on snippets IF they have doc tag because technically, you can pass ANYTHING into snippets, and without a doc tag we don't really know which one is Defined, and which one isn't
  • But by introducing inline snippets, we have a slight problem: having a doc tag inside the inline snippets don't mean the top-level snippet file has one too...

So we need a robust solution that works for the following situations:

  • What happens when you have no doc tags in the parent snippet AND the inline snippets
  • What happens when you have doc tag in the parent, but not in the inline snippets
  • What happens when you have doc tag in the inline snippets, but not in the parent
  • What happens when you have doc tag in both

I think we need to layout each situation before full implementation of this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so basically we would want:

  • no checks at all if both the snippet file and inline snippet don't have any doc tags
  • yes checks when there is a doc tag at its respective scope, for example when there is a doc tag in the main snippet file and none inside the inline snippet:
{%- comment -%} snippets/my-snippet.liquid {%- endcomment -%}

{% doc %}
  @param {string} parent_param
{% enddoc %}

{{ parent_param }}         <- ✅ Should NOT warn
{{ undefined_in_parent }}  <- ❓ Should this warn? YES

{% snippet inline_one %}
  {{ undefined_in_inline }} <- ❓ Should this warn? NO
{% endsnippet %}

And when the doc tag is inside the inline snippet, the check will be activated only on the inside of the inline snippet, and not outside of it.
I'll implement this right now.

@shoplando shoplando force-pushed the update-undefined-object-for-inline-snippets branch from fa207a1 to 3274d57 Compare October 22, 2025 16:34
@shoplando shoplando added the #gsd: 48097 Inline Snippets label Oct 29, 2025 — with Graphite App
@shoplando shoplando marked this pull request as draft November 6, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#gsd: 48097 Inline Snippets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants