Skip to content

fix: 🐛 support Shadow DOM#75

Merged
huntabyte merged 8 commits intosvecosystem:nextfrom
songpola:refactor-attachRef
Jun 18, 2025
Merged

fix: 🐛 support Shadow DOM#75
huntabyte merged 8 commits intosvecosystem:nextfrom
songpola:refactor-attachRef

Conversation

@songpola
Copy link
Contributor

@songpola songpola commented Jun 17, 2025

See #31 (comment)

Fixes #31

@changeset-bot
Copy link

changeset-bot bot commented Jun 17, 2025

🦋 Changeset detected

Latest commit: 53a3158

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

This PR includes changesets to release 1 package
Name Type
paneforge 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

@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
paneforge ✅ Ready (View Log) Visit Preview 53a3158

@huntabyte huntabyte added the publish:preview Publishes a preview release label Jun 18, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/paneforge@75

commit: 53a3158

@huntabyte
Copy link
Member

Hey @songpola thanks for getting this kicked off. Would you mind testing out npm i https://pkg.pr.new/paneforge@b1e9405 to see if it meets your shadow DOM requirements?

@github-actions github-actions bot requested a deployment to Preview June 18, 2025 15:41 Abandoned
@songpola songpola changed the title build: 📦 update Svelte to support Attachments fix: 🐛 support Shadow DOM Jun 18, 2025
@songpola
Copy link
Contributor Author

@huntabyte Thanks for the update. It turns out I'm doing the same changes as you! Testing now...

@songpola
Copy link
Contributor Author

Context
I use Svelte 5 Custom Element and put the panes inside (Horizontal Groups).

Expected
The handle should be draggable.

Actual
Assertion Error:

Reasons

The handleElement is null because getResizeHandleElement couldn't find the handle using doc.querySelector.

image

This is because doc returned from this.domContext.getDocument() is actually the Document of the page, not the Shadow DOM.

image

In svelte-toolbelt, I'm looking at the getDocument and its implementation. It only returns Document.

But there are also other methods in the DOMContext, e.g. getElementById, querySelector, querySelectorAll.

Solution
So, my suggestion is to pass the DOMContext itself and use those methods instead of querying from the Document directly.


P.S. Don't worry, this is not from AI. It's just my style of writing 😅

@songpola
Copy link
Contributor Author

I've done the refactoring, and I can confirm the handle is working in Shadow DOM now!

Copy link
Contributor Author

@songpola songpola left a comment

Choose a reason for hiding this comment

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

Maybe adding generics to these methods in the svelte-toolbelt?
So, we don't have to do the type assertions.

doc.querySelectorAll(`[data-pane-resizer-id][data-pane-group-id="${groupId}"]`)
domContext.querySelectorAll(
`[data-pane-resizer-id][data-pane-group-id="${groupId}"]`
) as NodeListOf<HTMLElement>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one...

const element = doc.querySelector<HTMLElement>(`[data-pane-group][data-pane-group-id="${id}"]`);
const element = domContext.querySelector(
`[data-pane-group][data-pane-group-id="${id}"]`
) as HTMLElement;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This...

export function getResizeHandleElement(id: string, domContext: DOMContext): HTMLElement | null {
if (!isBrowser) return null;
const element = doc.querySelector<HTMLElement>(`[data-pane-resizer-id="${id}"]`);
const element = domContext.querySelector(`[data-pane-resizer-id="${id}"]`) as HTMLElement;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this.

@huntabyte
Copy link
Member

Awesome, will do!

@huntabyte huntabyte merged commit 0b02284 into svecosystem:next Jun 18, 2025
5 checks passed
This was referenced Jun 18, 2025
@songpola songpola deleted the refactor-attachRef branch June 19, 2025 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish:preview Publishes a preview release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants