Skip to content

Commit

Permalink
dont rerender on hydrate
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored and jahilldev committed Oct 23, 2024
1 parent 96d2659 commit a069c90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/preactement/src/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function onConnected(this: CustomElement) {
this.__children = children || [];

this.removeAttribute('server');
this.innerHTML = '';
//this.innerHTML = '';

const response = this.__component();
const renderer = (result: ComponentFactory) => finaliseComponent.call(this, result);
Expand Down
21 changes: 21 additions & 0 deletions packages/preactement/tests/define.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,27 @@ describe('define()', () => {

expect(root.innerHTML).toContain(`<h2>${customTitle}</h2><em></em><p>${customText}</p>`);
});

it('hydrates server rendered markup corretly without re-rendering child elements', () => {
const customTitle = 'customTitle';
const props = { value: 'attrProps' };
const json = `<script type="application/json">${JSON.stringify(props)}</script>`;
const html = `<h2>${customTitle}</h2><em>${props.value}</em>`;

define('message-fourteen', () => Message, { attributes: ['custom-title'] });

const element = document.createElement('message-fourteen');

element.setAttribute('custom-title', customTitle);
element.setAttribute('server', '');
element.innerHTML = json + html;
const originalH2 = element.querySelector('h2');

root.appendChild(element);

expect(element.innerHTML).toEqual(html);
expect(element.querySelector('h2')).toBe(originalH2);
});
});

describe('when run in the browser (no "Reflect.construct")', () => {
Expand Down

0 comments on commit a069c90

Please sign in to comment.