Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "On section rename" handling #707

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Jan 14, 2025

What are you adding in this PR?

When files within the sections/*.liquid directory are renamed, we will update all references to these files in their previous locations. This includes:

  • templates/*.json files that referenced the old file name
  • sections/*.json files that referenced the old file name
  • Static section calls formatted as {% section 'old-name' %}

NOTE: This is very similar to block renames but because types are different and things are only so slightly different, I'm not sure it's worth DRY'ing it up as it would make complicated code even more complicated

Fixes #546

on.section.rename.mp4

Before you deploy

  • I included a minor bump changeset

@charlespwd charlespwd requested a review from a team as a code owner January 14, 2025 16:56
When a `sections/*.liquid` file is renamed, we'll update automatically update references in the following locations:

- `templates/*.json` files that were using the old name
- `sections/*.json` files that were using the old name
- Static section calls of the form `{% section 'old-name' %}`

Fixes #546
@charlespwd charlespwd force-pushed the feature/546-section-rename-refactor branch from 9c93229 to 1deaf0f Compare January 14, 2025 16:56
Copy link
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

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

🎩 ✅

  • rename liquid section file -> update template json
  • rename liquid section file -> update section json
  • rename liquid section file -> update {% section %} usage

few questions/minor comments

Comment on lines +191 to +195
// Note the type assertion to the LHS of the expression.
// The type assertions above are enough for this to be true.
// But I'm making the explicit annotation here to make it clear.
const typeNode: LiquidString = node.markup;
if (typeNode.value !== oldSectionName) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to explicitly have it as LiquidString? When i removed it, it still showed up as LiquidString when i hovered over typeNode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. IIRC I felt like future proofing against node.markup being possibly something else here. It didn't feel obvious at the time that the type assertions made the typeNode a LiquidString from the code being used.

Comment on lines +10 to +12
- `templates/*.json` files that referenced the old file name
- `sections/*.json` files that referenced the old file name
- Static section calls formatted as `{% section 'old-name' %}`
Copy link
Contributor

Choose a reason for hiding this comment

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

What about config/settings_data.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can have a section in settings_data.json?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't see anything about that in the docs 🤔? What am I missing?

https://shopify.dev/docs/storefronts/themes/architecture/sections#render-a-section

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:o

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 have no idea haha. Doesn't seem documented 🤔

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 given this would require TS interfaces and probably a revisit of block renames as well, I'll log this as a different issue and merge this as is to prevent from ballooning the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good 👍

@charlespwd charlespwd merged commit c74850c into main Jan 16, 2025
6 checks passed
@charlespwd charlespwd deleted the feature/546-section-rename-refactor branch January 16, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renaming a section should update old references
2 participants