Skip to content

fix(iframe): use filtered.length for style loading completion check#1514

Open
allandelmare wants to merge 2 commits intopuckeditor:mainfrom
allandelmare:fix/iframe-style-loading
Open

fix(iframe): use filtered.length for style loading completion check#1514
allandelmare wants to merge 2 commits intopuckeditor:mainfrom
allandelmare:fix/iframe-style-loading

Conversation

@allandelmare
Copy link

Summary

Fix style loading validation to compare against filtered.length instead of elements.length.

Problem

When stylesheets are dynamically added to the DOM (e.g., Monaco editor CSS), the elements array grows but filtered remains the same size. This causes the completion check stylesLoaded >= elements.length to never trigger, leaving the iframe in a loading state.

Solution

Change the comparison from elements.length to filtered.length since filtered represents the actual stylesheets that need to load.

Changes

  • packages/core/components/AutoFrame/index.tsx: 2 lines changed

Closes #1324

The style loading validation was comparing against elements.length
instead of filtered.length. When stylesheets are dynamically added
(e.g., Monaco editor CSS), the elements array grows but filtered
remains the same, causing the completion check to never trigger.

Closes puckeditor#1324
@vercel
Copy link

vercel bot commented Jan 19, 2026

@allandelmare is attempting to deploy a commit to the Puck Team on Vercel.

A member of the Team first needs to authorize it.

@kernel-io
Copy link

kernel-io commented Feb 6, 2026

This patch requires more changes to fully solve the issue

After appending styles to doc.head - count how many <style> elements are loaded as they don't fire onload events, after this check if stylesLoaded >= filtered.length - this also handles an edge case where filtered.length == 0

i.e on line 292.

doc.head.append(...filtered)

// Count <style> elements as immediately loaded (they don't fire onload)
filtered.forEach((mirror) => {
  if (mirror.nodeName === "STYLE") {
    stylesLoaded = stylesLoaded + 1;
  }
});

if (stylesLoaded >= filtered.length) {
  onStylesLoaded();
}
<style> elements don't fire onload events, so count them after
appending to doc.head. Also handles the edge case where
filtered.length is 0.
@allandelmare
Copy link
Author

Good catch, thanks! Pushed a fix in 7f300f5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants