refactor(pwa): remove reloadPopup option in favor of swizzling#7422
Conversation
622b9d4 to
1cdf582
Compare
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: -98 B (0%) Total Size: 796 kB
ℹ️ View Unchanged
|
1cdf582 to
b9b991d
Compare
There was a problem hiding this comment.
That looks fine 👍
However we also used dynamic imports so that the reload popup does not need to be loaded eagerly. Implemented initially in #2205
Afaik we had 2 dynamic imports
const renderReloadPopup = (await import('./renderReloadPopup')).default; const {default: ReloadPopup} = await import(process.env.PWA_RELOAD_POPUP!);The dynamic import used to import the reload popup component has caused problems with server-side rendering due to how Babel/SWC compiles it. See #3742 and #7329 for some struggles. I propose to simply remove this option, because we can leverage swizzling to achieve the same effect.
It's still not clear to me why this is a problem, and which one is the actual problem (both?). The issues didn't really help me. Can you explain? If this is a Babel problem, how does it compile it exactly and how should it compile it?
Can we keep the lazy behavior and still fix the issue?
I'm ok to simplify if it fixes things, but I also like to understand the issue if possible 🤪
| swRegister: Joi.alternatives() | ||
| .try(Joi.string(), Joi.bool().valid(false)) | ||
| .default(DEFAULT_OPTIONS.swRegister), | ||
| reloadPopup: Joi.alternatives() |
There was a problem hiding this comment.
we'd rather add a forbidden message here otherwise users with custom popups may miss this
|
Yes yes, we can lazy load it. The only problem is we can't use a dynamic string. I think a static one will be fine (that's how registry.js looks like) On my phone rn, I can write a more detailed explanation when I get to my keyboard |
|
Here's how babel-plugin-dynamic-import-node is working. // 2.3.0
- const a = await Promise.resolve().then(() => _interopRequireWildcard(require(`${process.env.FOO}`)));
// 2.3.3
+ const a = await Promise.resolve(`${process.env.FOO}`).then(s => _interopRequireWildcard(require(s)));So the solution is we should not use const a = await Promise.resolve().then(() =>
_interopRequireWildcard(require("foo"))
);Because it doesn't need to evaluate anything. The behavior that the path string is evaluated synchronously instead of in the |
Pre-flight checklist
Breaking change
The
reloadPopupoption of the PWA plugin is removed. If you are using a custom component, consider swizzling@theme/PwaReloadPopupinstead. If you set it tofalse, consider returningnullfrom your component.Motivation
The dynamic import used to import the reload popup component has caused problems with server-side rendering due to how Babel/SWC compiles it. See #3742 and #7329 for some struggles. I propose to simply remove this option, because we can leverage swizzling to achieve the same effect.
Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs