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

bug: hydrate crashes if component uses @Listen #5869

Closed
3 tasks done
mayerraphael opened this issue Jun 28, 2024 · 3 comments · Fixed by #5877, #5878 or ionic-team/ionic-framework#29685
Closed
3 tasks done

bug: hydrate crashes if component uses @Listen #5869

mayerraphael opened this issue Jun 28, 2024 · 3 comments · Fixed by #5877, #5878 or ionic-team/ionic-framework#29685
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@mayerraphael
Copy link

mayerraphael commented Jun 28, 2024

Prerequisites

Stencil Version

4.19.0

Current Behavior

If a component has a @Listen() function (tested with keydown) Stencil hydrate crashes and does not serialize the component.

image

Culprit is the hydrateComponent method:

async function hydrateComponent(win2, results, tagName, elm, waitingElements) {
  tagName = tagName.toLowerCase();
  const Cstr = loadModule(
    {
      $tagName$: tagName,
      $flags$: null
    });
  if (Cstr != null) {
    const cmpMeta = Cstr.cmpMeta;
    if (cmpMeta != null) {
      waitingElements.add(elm);
      const hostRef = getHostRef(this);
      addHostEventListeners(this, hostRef, cmpMeta.$listeners$); // --------------------------------- "this" is undefined

Expected Behavior

For components to correctly serialize with @Listen() methods.

System Info

No response

Steps to Reproduce

See repository.

Code Reproduction URL

https://github.com/mayerraphael/stencil-dsd-ssr-playground

Additional Information

The my-whatever-component has an @Listen() method.

Affects both serializeShadowRoot true and false.

@christian-bromann
Copy link
Member

@mayerraphael thanks for raising this issue and helping us make Stencil better.

tested with keydown

Can you please describe how you did trigger the event? If I change the eventName to click , everything works fine when clicking on it.

@christian-bromann christian-bromann added the Awaiting Reply This PR or Issue needs a reply from the original reporter. label Jul 1, 2024
@christian-bromann
Copy link
Member

Actually after some more testing, I am able to reproduce this issue and can investigate/work on a solution.

@ionitron-bot ionitron-bot bot removed the Awaiting Reply This PR or Issue needs a reply from the original reporter. label Jul 1, 2024
@christian-bromann
Copy link
Member

A bug fix has been proposed in #5877 and a dev release (4.19.1-dev.1719875079.a06f64c) confirmed that it fixes the double rendering in the provided reproduction case.

github-merge-queue bot pushed a commit to ionic-team/ionic-framework that referenced this issue Jul 2, 2024
Issue number: resolves #29681

---------

### Release Notes

<details>
<summary>ionic-team/stencil (@&#8203;stencil/core)</summary>

###
[`v4.19.2`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4192-2024-07-02)

[Compare
Source](https://togithub.com/ionic-team/stencil/compare/v4.19.1...v4.19.2)

### Bug Fixes

* **hydrate:** partially revert
[#5838](ionic-team/stencil#5838)
([#5876](ionic-team/stencil#5876))
([dfbc340](ionic-team/stencil@dfbc340))
* **hydrate:** support server side rendering of components with listener
([#5877](ionic-team/stencil#5877))
([2c5b7f8](ionic-team/stencil@2c5b7f8)),
fixes [#5869](ionic-team/stencil#5869)
* **testing:** add testing sub module to export map
([#5873](ionic-team/stencil#5873))
([bb2e04f](ionic-team/stencil@bb2e04f)),
fixes [#5871](ionic-team/stencil#5871) and
[#5868](ionic-team/stencil#5868)

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
2 participants