Skip to content

context doesn't work with shadow: false #122

Description

@smeijer

Forking off from #65; context doesn't work when creating elements without { shadow: true }.

The cause is that the event listener is attached to a slot in shadow mode, and to a Fragment in light DOM mode. Fragments don't handle the events.

I've confirmed that replacing the Fragment with a real element fixes the issue, by applying the change below. I'm opening this issue instead of creating a pull-request, as wrapping elements in another custom element, might be undesired.

Potential fix, replace these lines:

const { useFragment, ...rest } = props;
return h(useFragment ? Fragment : 'slot', { ...rest, ref });

With:

	const { useFragment, ...rest } = props;
	let tag = 'slot';
	if (useFragment) {
		tag = 'preact-context-bridge';
		rest.style = 'display: contents;';
	}
	return h(tag, { ...rest, ref });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions