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: mark custom element with virtual class attribute as dynamic #13435

Merged
merged 6 commits into from
Oct 8, 2024

Conversation

paoloricciuti
Copy link
Member

Svelte 5 rewrite

Closes #13426

Initially i just marked every custom element as dynamic but that would've been a lot more code generated if there was a custom element that was actually skipped (this was problematic only because that custom element ends up having an attribute (the virtual class file). Since i needed the path to mark the tree as dynamic i've added it to the metadata because i didn't find a way to get the path from the element itself but if there's a better approach i can change it obviously.

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 Sep 29, 2024

🦋 Changeset detected

Latest commit: d4e6e64

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

@dummdidumm
Copy link
Member

I briefly tried moving the "add the scoping classes" logic into the prune function, so that the attributes would be set by the time the "mark as dynamic" logic runs. It turned out to be tricky though because of how and when elements are marked as scoped, e.g. a parent element might only get marked as scoped once a child element is marked as such, etc etc, and just iterating over the elements once the pruning is done on each element is more straightforward.

That said, each element has a parent property, and we could use that inside mark_subtree_as_dynamic instead, removing the need to pass in path. I'm not 100% certain whether or not we wanna keep that property in the long run though.

Either way, the whole CSS part is very complicated and intertwined with the rest of the things, so I think there's no solution without drawbacks.

@paoloricciuti
Copy link
Member Author

I briefly tried moving the "add the scoping classes" logic into the prune function, so that the attributes would be set by the time the "mark as dynamic" logic runs. It turned out to be tricky though because of how and when elements are marked as scoped, e.g. a parent element might only get marked as scoped once a child element is marked as such, etc etc, and just iterating over the elements once the pruning is done on each element is more straightforward.

That said, each element has a parent property, and we could use that inside mark_subtree_as_dynamic instead, removing the need to pass in path. I'm not 100% certain whether or not we wanna keep that property in the long run though.

Either way, the whole CSS part is very complicated and intertwined with the rest of the things, so I think there's no solution without drawbacks.

Yeah to be fair I think this is a niche enough case tat is fine to have a one off check after adding the class. WDYT?

@dummdidumm
Copy link
Member

fine to have a one off check after adding the class

Are you relating to the current logic? Yes, there's no other good (and more important immediate) way I see here. So it comes down to either adding the path to the metadata, or to use .parent on the node passed to mark_subtree_as_dynamic.

@paoloricciuti
Copy link
Member Author

or to use .parent on the node passed to mark_subtree_as_dynamic

Oh that's interesting as well but how much refactor would require at every usage site? I'll take a look later and eventually change the implementation

@paoloricciuti
Copy link
Member Author

fine to have a one off check after adding the class

Are you relating to the current logic? Yes, there's no other good (and more important immediate) way I see here. So it comes down to either adding the path to the metadata, or to use .parent on the node passed to mark_subtree_as_dynamic.

Is the parent not in the types of SvelteNode? Maybe it's only on some types of nodes?

@paoloricciuti
Copy link
Member Author

@dummdidumm i'm trying to change the mehavior of mark_subtree_dynamic but it seems to be more problematic that just adding the path to the metadata of the element. It would require more changes and it will probably be a bit more brittle. I would go with this solution.

@paoloricciuti
Copy link
Member Author

@dummdidumm i think this is ready?

@dummdidumm dummdidumm merged commit 3d30067 into main Oct 8, 2024
9 checks passed
@dummdidumm dummdidumm deleted the fix-svelte-class-on-nested-custom-elements branch October 8, 2024 20:38
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.

Custom HTML tag not picking up css
2 participants