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

feat(core): Add support to shadow DOM for QwikLoader. #6547

Merged
merged 1 commit into from
Jun 19, 2024
Merged

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Jun 15, 2024

feat(core): Add support to shadow DOM for QwikLoader.

Shadow DOM can be used to isolate an application. The isolation also
includes:

  • Events don't bubble across shadow boundaries.
  • QuerySelector doesn't cross shadow boundaries.

QwikLoader relies on both event bubbling and querySelector to process
events such as on:click and dispatch such as on-window:resize.

To enable QwikLoader to work with shadow DOM, it is necessary to tell
qwikloader that when it is registering an event listener, as well as
performing querySelector, it should do so not just on document but also
inside the shadow DOM. To do that it is the responsibility of the
developer to tell qwikloader about the shadow DOM roots.

CONSTRAINTS:
The qwikloader applications q:container must be fully inside the
shadow root. (i.e. the application itself must not cross the shadow DOM
boundaries.)

Developer responsibility: (choose one)

  • Have qwik loader find the roots by annotate the elements which have
    shadow DOM with q:shadowRoot attribute.
  • Manually insert a <script> tag into HTML which will add the shadow DOM
    root into the qwikloader's qwikevents array.

Example:
Possible implementation

<div id="my-child" q:shadowRoot>
  <template shadowrootmode="open">
     <div q:container="..." q:base="..."...>qwik-container here</div>
  </template>
</div>

Fixes: #6546

@mhevery mhevery requested a review from a team as a code owner June 15, 2024 02:07
Copy link

netlify bot commented Jun 15, 2024

Deploy Preview for qwik-insights ready!

Name Link
🔨 Latest commit b2fc362
🔍 Latest deploy log https://app.netlify.com/sites/qwik-insights/deploys/66722d69ac5b9b000708b2ce
😎 Deploy Preview https://deploy-preview-6547--qwik-insights.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Jun 15, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: b2fc362

@builder.io/qwik

npm i https://pkg.pr.new/@builder.io/qwik@6547

@builder.io/qwik-city

npm i https://pkg.pr.new/@builder.io/qwik-city@6547

eslint-plugin-qwik

npm i https://pkg.pr.new/eslint-plugin-qwik@6547

create-qwik

npm i https://pkg.pr.new/create-qwik@6547

Copy link

cloudflare-pages bot commented Jun 15, 2024

Deploying qwik-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b2fc362
Status:🚫  Build failed.

View logs

@mhevery
Copy link
Contributor Author

mhevery commented Jun 15, 2024

So turns out that you can't use documen.currentScript inside the shadow root 🤦‍♂️ . So we will need to do this differently. 🤔

I think a better way to do it is for the QwikLoader to query q:shadow and for each one recursively descend into the shadow root and if it can find q:container attribute, than it should automatically add the shadow-fragment into the tracking set of roots. I will do that change.

Shadow DOM can be used to isolate an application. The isolation also
includes:
- Events don't bubble across shadow boundaries.
- QuerySelector doesn't cross shadow boundaries.

QwikLoader relies on both event bubbling and querySelector to process
events such as `on:click` and dispatch such as `on-window:resize`.

To enable QwikLoader to work with shadow DOM, it is necessary to tell
qwikloader that when it is registering an event listener, as well as
performing querySelector, it should do so not just on document but also
inside the shadow DOM. To do that it is the responsibility of the
developer to tell qwikloader about the shadow DOM roots.

CONSTRAINTS:
The qwikloader applications `q:container` must be fully inside the
shadow root. (i.e. the application itself must not cross the shadow DOM
boundaries.)

Developer responsibility: (choose one)

- Have qwik loader find the roots by annotate the elements which have
  shadow DOM with `q:shadowRoot` attribute.
- Manually insert a `<script>` tag into HTML which will add the shadow DOM
  root into the qwikloader's `qwikevents` array.

Example:
Possible implementation
```html
<div id="my-child" q:shadowRoot>
  <template shadowrootmode="open">
     <div q:container="..." q:base="..."...>qwik-container here</div>
  </template>
</div>
```

Fixes: #6546
@mhevery mhevery merged commit 2284b1a into main Jun 19, 2024
28 of 29 checks passed
@mhevery mhevery deleted the feat-shadow-dom branch June 19, 2024 01:14
gioboa added a commit to gioboa/qwik that referenced this pull request Jun 20, 2024
genki pushed a commit to genki/qwik that referenced this pull request Jun 28, 2024
Shadow DOM can be used to isolate an application. The isolation also
includes:
- Events don't bubble across shadow boundaries.
- QuerySelector doesn't cross shadow boundaries.

QwikLoader relies on both event bubbling and querySelector to process
events such as `on:click` and dispatch such as `on-window:resize`.

To enable QwikLoader to work with shadow DOM, it is necessary to tell
qwikloader that when it is registering an event listener, as well as
performing querySelector, it should do so not just on document but also
inside the shadow DOM. To do that it is the responsibility of the
developer to tell qwikloader about the shadow DOM roots.

CONSTRAINTS:
The qwikloader applications `q:container` must be fully inside the
shadow root. (i.e. the application itself must not cross the shadow DOM
boundaries.)

Developer responsibility: (choose one)

- Have qwik loader find the roots by annotate the elements which have
  shadow DOM with `q:shadowRoot` attribute.
- Manually insert a `<script>` tag into HTML which will add the shadow DOM
  root into the qwikloader's `qwikevents` array.

Example:
Possible implementation
```html
<div id="my-child" q:shadowRoot>
  <template shadowrootmode="open">
     <div q:container="..." q:base="..."...>qwik-container here</div>
  </template>
</div>
```

Fixes: QwikDev#6546
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.

[✨] Enable resuming within Shadow DOM
2 participants