Skip to content
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: infer svg namespace correctly #10027

Merged
merged 11 commits into from
Jan 9, 2024
Merged

Conversation

navorite
Copy link
Contributor

@navorite navorite commented Dec 29, 2023

[WIP]: closes #10025, the following cases where it would infer the namespace as html are now fixed:

  • Having a comment inside the markup
  • Having a {@const} tag inside the markup
  • Having blocks inside the markup

Edit: I think there might be a better approach to this, as this wouldn't solve a case like this:

<text x=1 y=50>test</text>

<!-- the if/each block would make the component infer HTML namespace 
thus elements outside the if/each block are part of the HTML namespace
-->
{#if x} 
<text x=1 y=50>true</text>
{:else}
<text x=1 y=50>false</text>
{/if}

Svelte 5 rewrite

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Dec 29, 2023

🦋 Changeset detected

Latest commit: eb8475f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Copy link

vercel bot commented Dec 29, 2023

@navorite is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines 212 to 215
parent_node.type === 'SnippetBlock' ||
parent_node.type === 'IfBlock' ||
parent_node.type === 'EachBlock' ||
parent_node.type === 'AwaitBlock')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
parent_node.type === 'SnippetBlock' ||
parent_node.type === 'IfBlock' ||
parent_node.type === 'EachBlock' ||
parent_node.type === 'AwaitBlock')
parent_node.type === 'SnippetBlock')

@@ -222,7 +225,7 @@ export function infer_namespace(namespace, parent, nodes, path) {
only_svg = false;
break;
}
} else if (node.type !== 'Text' || node.data.trim() !== '') {
} else if (node.type !== 'ConstTag' && (node.type !== 'Text' || node.data.trim() !== '')) {
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for tackling this, but this is not quite right. We need to keep the check above as-is, and instead need to check that if we discover if/await/each blocks while traversing the nodes here, that the top level children of those are all svg elements (basically this loop needs to become recursive). Also, could you add a test case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I realized that is the correct approach while trying to fix it, that's why I kept it a draft. I will add a test case shortly and maybe implement this.

@dummdidumm dummdidumm marked this pull request as ready for review January 9, 2024 10:48
@dummdidumm dummdidumm merged commit cd2263f into sveltejs:main Jan 9, 2024
6 of 8 checks passed
@navorite navorite deleted the svg-template branch February 15, 2024 11:35
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.

Svelte 5: top level logic blocks ({#if}, {#each}) are not properly rendered inside <svg>
2 participants