-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: suppress inner content warning when children prop is forwarded #15269
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
fix: suppress inner content warning when children prop is forwarded #15269
Conversation
When a +layout.svelte passes children to a child component via
shorthand ({children}) or explicit prop (children={children}),
the "inner content will not be rendered" warning no longer fires.
Closes sveltejs#13504
🦋 Changeset detectedLatest commit: acb0b5a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| // Recreate the markup children detection logic for testing (mirrors warning_preprocessor in vite/index.js) | ||
| /** | ||
| * @param {string} content | ||
| * @returns {boolean} | ||
| */ | ||
| function has_children(content) { | ||
| return ( | ||
| content.includes('<slot') || | ||
| content.includes('{@render') || | ||
| content.includes('{children}') || | ||
| content.includes('children={') | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is a very bad idea, this will drift. If we want tests for this then the logic in vite/index.js should be extracted out into a function in utils.js and be imported/tested here
FrankFMY
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done — extracted has_children into utils.js and imported it in both index.js and the test file.
Summary
Fixes #13504
When a
+layout.svelteforwardschildrento a child component instead of rendering it directly with{@render children()}, the warning "<slot />or{@render ...}tag missing — inner content will not be rendered`" fires as a false positive.This PR suppresses the warning when
childrenis passed to a child component via:<Layout {children} /><Layout children={children} />As suggested by @elliott-with-the-longest-name-on-github in the issue discussion.
Changes
packages/kit/src/exports/vite/index.js— Extendhas_childrencheck to detect{children}andchildren={patterns in markuppackages/kit/src/exports/vite/static_analysis/utils.spec.js— Add unit tests for children forwarding detectionTest plan
pnpm -F @sveltejs/kit test:unit— 424 tests passedpnpm run format— clean