Skip to content

[lit-html - SSR] missing parent check for defer-hydration? #2946

@daKmoR

Description

@daKmoR

Description

I am not sure why but I currently have a situation where marker.parentElement in experimental-hydrate.ts is null.

https://github.com/lit/lit/blob/main/packages/lit-html/src/experimental-hydrate.ts#L161-L164

when I check the code I see this

const parent = marker.parentElement!;
if (parent.hasAttribute('defer-hydration')) {
  parent.removeAttribute('defer-hydration');
}

adding check so that parent can not be null seems to make it work.

e.g.

   const parent = marker.parentElement!;
-  if (parent.hasAttribute('defer-hydration')) {
+  if (parent && parent.hasAttribute('defer-hydration')) {
     parent.removeAttribute('defer-hydration');
   }

Is that just a missing check? or is there a 0 chance that parentElement is ever null? If so I need to check why it's null in my case...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions