Skip to content

Conversation

@chris-doucette-stack
Copy link
Collaborator

I encountered a bug where snippets wouldn't get re-rendered when clicking the run snippets button and was always one change behind. I could only force the snippet to update by swapping between editor views.

video_1280.mp4

I found that this was caused due to how we decided to update the results in snippet-view.ts within the update function.
Here's the flow:

  1. User updates their snippet and saves it to the editor
  2. We run through the update function, on this run SnippetMetadata is updated
  3. We get down to this conditional if (content && (metaChanged || this.resultContainer.innerHTML === ""))
    and because the snippet meta data has updated we reinitialize the Iframe for the snippets result but reinject our contentNode html into the iframe. The content node is what we get back from the renderer and only gets set on button click, we therefore are not updating the actual contents of what is displayed to the user.
  4. The user could then hit the run snippets button and we dispatch an event to run through the update function again.
  5. At this point we have already seen the updated snippet meta data, so once we get down to the conditional to update the iframes content we skip over it.

Describe your changes
I address this issue by instead of comparing if the snippet meta data has changed I compare the contentNode's innerHtml to a snapshots. This makes it so that the snippet results are only updated on run button click.

@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2025

⚠️ No Changeset found

Latest commit: 1a3d7f7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jul 23, 2025

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit a1d09cb
🔍 Latest deploy log https://app.netlify.com/projects/stacks-editor/deploys/688143b407983c00085a5e23
😎 Deploy Preview https://deploy-preview-466--stacks-editor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chris-doucette-stack chris-doucette-stack marked this pull request as ready for review July 23, 2025 20:00
Copy link
Collaborator

@troygould-stack troygould-stack left a comment

Choose a reason for hiding this comment

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

tested via localhost. Changes look right. Walked through with Chris.

@troygould-stack troygould-stack merged commit 4802674 into main Aug 13, 2025
5 checks passed
@troygould-stack troygould-stack deleted the cdoucette/snippets-not-rerendering branch August 13, 2025 18:52
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.

3 participants