Web-components: Fix source decorator to handle document fragments #22513
+42
−3
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.
What I did
I'm migrating our company's setup from Storybook 6 to Storybook 7 and ran into the issue with one of our decorators. Let me explain what it does first.
We have a custom decorator to allow rendering stories explicitly with Lit 1 and Lit 2 to help in migration for Lit 1 -> 2.
Then you can configure what lit version you want your stories to be rendered with, e.g.:
Storybook 7 changed the order of decorators, so the
sourceDecorator
is executed after our custom decorators, which results in the following bug:withLitCompat
tosourceDecorator
sourceDecorator
by Lit which moves its child nodes to the new div, leaving it emptyrenderToCanvas
which renders empty document fragmentThis fix makes sure to clone the document fragment to prevent moving of the child nodes which fixes this bug.
How to test
Unit test is provided to verify correct document fragment handling.
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]