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

duplicate loads of the DOM shim leads to an infinite rendering issue #147

Closed
thescientist13 opened this issue Feb 19, 2024 · 0 comments · Fixed by #148
Closed

duplicate loads of the DOM shim leads to an infinite rendering issue #147

thescientist13 opened this issue Feb 19, 2024 · 0 comments · Fixed by #148
Assignees
Labels
0.12.0 bug Something isn't working
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Feb 19, 2024

Summary

Not sure the exact cause why, but very similar to #144 , as part of refactoring down Greenwood towards Single File Executables noticed in this demo PR that given a very specific set of steps

  1. Load products page (SSR page)
  2. Load home page and click load products (API route)
  3. Load search page and search, e.g. phone (API route)
  4. Load products page
  • Expected: page would load like in step 1
  • Actual: custom element initialization keeps happening until eventually the API we're calling gives up and stops return data
greenwood-sfe-ssr-infinite-loop.mov

Details

As you can see above, renderToString gets called and then initializeCustomElement happens almost 100 times and finally the upsteam API just gives up

Screenshot 2024-02-19 at 1 15 48 PM

We should probably include this as part of #145.

I also wonder wonder why over multiple loads this would be an issue, but not presumably defining something like HTMLElement wouldn't error out? Node should cache modules, which would explain the HTMLElement behavior at least but not the observed behavior seen here. 🤷‍♂️


Spoiler alert, a solution was found that involved making the DOM Shim a bit more idempotent which seemed to make the issue go away

// before
globalThis.addEventListener = noop;
globalThis.document = new Document();
globalThis.customElements = new CustomElementsRegistry();
globalThis.HTMLElement = HTMLElement;

// after
globalThis.addEventListener = globalThis.addEventListener ?? noop;
globalThis.document = globalThis.document ?? new Document();
globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry();
globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
@thescientist13 thescientist13 added the bug Something isn't working label Feb 19, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Feb 19, 2024
@thescientist13 thescientist13 self-assigned this Feb 19, 2024
@thescientist13 thescientist13 changed the title reloading DOM shim leads to infinite rendering issue duplicate loads of the DOM shim leads to infinite rendering issue Feb 19, 2024
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Feb 19, 2024
@thescientist13 thescientist13 changed the title duplicate loads of the DOM shim leads to infinite rendering issue duplicate loads of the DOM shim leads to an infinite rendering issue Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.12.0 bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant