opencomponents / oc

OpenComponents, serverless in the front-end world for painless micro-frontends delivery
https://opencomponents.github.io/
MIT License
1.43k stars 122 forks source link

Console is not fully defined in production #1316

Closed mungodewar closed 1 year ago

mungodewar commented 1 year ago

Who is the bug affecting?

Component authors/creators.

What is affected by this bug?

The ability to server-side render components.

When does this occur?

When trying to server render a component in production.

Where on the platform does it happen?

In the registry in production only. This issue is not present locally as the "real" console object is passed into the vm context. This makes this problem particularly dangerous.

How do we replicate the issue?

  1. Add console.warn anywhere inside server.js.
  2. Build component and run inside production (non-local) registry.
  3. Observe console.warn is not a function error when trying to fetch/get component from registry.

Expected behavior (i.e. solution)

console api should be fully stubbed inside component server execution. I've drafted a PR: https://github.com/opencomponents/oc/pull/1315 that I hope details what I think should happen.

What version of OC, Node.js and OS are you using?

oc@0.49.6 node@16.18.1

Other Comments

ricardo-devis-agullo commented 1 year ago

Why would you want to use console.warn inside server.js, anyways, since OC is going to ignore all messages?

mungodewar commented 1 year ago

Why would you want to use console.warn inside server.js, anyways, since OC is going to ignore all messages?

This is just an demo example of triggering the bug. What is really happening is a deep dependency within the react render tree is using a console.warn statement. IMO usage of console.warn shouldn't stop the component rendering within the oc-registry context.

ricardo-devis-agullo commented 1 year ago

Got it. LGTM then.

mungodewar commented 1 year ago

Got it. LGTM then.

I'll update my PR to your suggested change.