Migrate Bento components to V1#32974
Conversation
2dbe91a to
b3e78e5
Compare
edba209 to
fa7832d
Compare
02c7185 to
5377823
Compare
| useLayoutEffect(() => { | ||
| if (!load) { | ||
| setLoaded(false); | ||
| } | ||
| }, [load, setLoaded]); |
There was a problem hiding this comment.
This loaded code is really difficult for me to grok. I think what's happening is we want to call onReadyStateChange when unloaded->loaded and loaded->unloaded. I don't understand why it can't simply be written like:
const lastLoadedRef = useRef(false);
const [loaded, setLoaded] = useState(false);
if (loaded && !load) {
onReadyState?.(ReadyState.LOADING);
lastLoadedRef.current = false;
setLoaded(false);
} else if (loaded !== lastLoadedRef.current) {
onReadyState?.(loaded ? ReadyState.COMPLETE : ReadyState.LOADING);
lastLoadedRef.current = loaded;
}There was a problem hiding this comment.
I renamed things a bit here to make it simpler. LMK if that helps. I renamed load variable to mount - it basically decides whether or not to actually render/mount the iframe.
The goal of this code specifically is to reset loaded to false because if the iframe is no longer in DOM, it's not loaded either. And when it's added back, it will restart the whole chain of states again.
Your code might be close, but (a) we can't send events from the component's render function and we don't want to send them on each render. So an effect is better for this.
277ed9f to
e542720
Compare
|
Congrats on merging this! Gargantuan effort |
* 'master' of github.com:ampproject/amphtml: (536 commits) ✨ Send extension versions from AMPHTML ads to FIE (ampproject#33190) Update amp-autocomplete test output file (ampproject#33216) ✨ Changing Inline Page Attachment Button UI (ampproject#33142) ✨Launch no-signing (ampproject#33229) ♻️ Add logic for story ad page manager. (ampproject#33201) Migrate Bento components to V1 (ampproject#32974) 📦 Update dependency mocha to v8.3.2 (ampproject#33234) 📦 Update build system devDependencies (ampproject#33178) 🧪 [amp-consent] Turn on TCF PostMessage Proxy API Experiment (ampproject#33196) Fix amp-video amp_video_quality parameter name. (ampproject#33227) 🏗 Guard access to `BASH_ENV` during CircleCI push builds (ampproject#33231) 🏗 Clean up CircleCI merge SHA logic (ampproject#33215) 📦 Update dependency karma to v6.1.2 (ampproject#33151) 🏗 Ensure up-to-date and clean `package-lock.json` before running any CI job (ampproject#33223) Ensure that pre-stubbing always happens before the first element is upgraded (ampproject#33212) 🏗 Restore `package-lock.json` to `lockfileVersion = 1` (ampproject#33222) Fixed text align of buttons (ampproject#33217) [amp-story] ♿ Add label for next story and add i18n for pagination buttons (ampproject#33205) [amp-story-player] 📖 Rename skip-next control to skip-to-next (ampproject#33164) 🚀 Report cls-fcp and cls-vis to compare with cls (ampproject#33207) ...
* Migrate Bento components to V1 * V1 tests * fixed types * fix types * Make readyState/loaded as refs, not state * only send state event when it changes * Async pause API applied via ResizeObserver * review fixes * Redo unloadOnPause * review fixes * more comments on unloadOnPause * fix bad merge
Partial for #30283.
The main general changes are in the
src/preact/base-element.jsand they are simple:layoutCallbackis gone.ensureLoadedis added. Works vialoading=eagerRef<Api>andonReadyStateevent.Other changes include:
unloadOnPauseis changed to allow reloading.VideoWrapperandInstagramcomponents have been updated to V1 protocol.