fix(iframe): use filtered.length for style loading completion check#1514
Open
allandelmare wants to merge 2 commits intopuckeditor:mainfrom
Open
fix(iframe): use filtered.length for style loading completion check#1514allandelmare wants to merge 2 commits intopuckeditor:mainfrom
allandelmare wants to merge 2 commits intopuckeditor:mainfrom
Conversation
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
|
@allandelmare is attempting to deploy a commit to the Puck Team on Vercel. A member of the Team first needs to authorize it. |
|
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.
Author
|
Good catch, thanks! Pushed a fix in 7f300f5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix style loading validation to compare against
filtered.lengthinstead ofelements.length.Problem
When stylesheets are dynamically added to the DOM (e.g., Monaco editor CSS), the
elementsarray grows butfilteredremains the same size. This causes the completion checkstylesLoaded >= elements.lengthto never trigger, leaving the iframe in a loading state.Solution
Change the comparison from
elements.lengthtofiltered.lengthsincefilteredrepresents the actual stylesheets that need to load.Changes
packages/core/components/AutoFrame/index.tsx: 2 lines changedCloses #1324