Skip to content

Conversation

@wyMinLwin
Copy link
Contributor

The problem is for Svelte code block which used TypeScript selecting the element which doesn't exist.

Code block selection improvements:

  • Enhanced the query logic to check the code block's language and use pre:last-of-type code for Svelte samples when the TypeScript toggle is enabled, ensuring the correct code is copied for Svelte examples.
  • Retained the original query for TypeScript and default cases, preserving expected behavior for other languages.

@vercel
Copy link

vercel bot commented Oct 30, 2025

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

A member of the Team first needs to authorize it.

@7nik
Copy link
Contributor

7nik commented Oct 30, 2025

I wonder if we can go with more simple

const code = parent.querySelectorAll("code")[ts ? 1 : 0];

@wyMinLwin
Copy link
Contributor Author

I wonder if we can go with more simple

const code = parent.querySelectorAll("code")[ts ? 1 : 0];

No it's because if you do like that it would lead back to issue #1406
which is copying wrong TypeScript code.

For current issue your solution will be fine but we need to think about what happened in issue #1406 as well

@7nik
Copy link
Contributor

7nik commented Oct 31, 2025

pre:last-of-type code has the same problem, right? (any single pre is :last and :last-of-type)

We should just select only "top-level" code blocks:

const code = parent.querySelectorAll(":scope > pre > code")[ts ? 1 : 0];

@wyMinLwin
Copy link
Contributor Author

pre:last-of-type code has the same problem, right? (any single pre is :last and :last-of-type)

We should just select only "top-level" code blocks:

const code = parent.querySelectorAll(":scope > pre > code")[ts ? 1 : 0];

This work Great!
I updated the code. Thanks.

@7nik 7nik merged commit 726a778 into sveltejs:main Oct 31, 2025
1 of 2 checks passed
@wyMinLwin wyMinLwin deleted the fix/copy-a-specific-code-block branch October 31, 2025 17:34
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.

2 participants