( domElement: Instance, type: string, newProps: Props, internalInstanceHandle: Object, )
| 806 | export const supportsMutation = true; |
| 807 | |
| 808 | export function commitMount( |
| 809 | domElement: Instance, |
| 810 | type: string, |
| 811 | newProps: Props, |
| 812 | internalInstanceHandle: Object, |
| 813 | ): void { |
| 814 | class="cm">// Despite the naming that might imply otherwise, this method only |
| 815 | class="cm">// fires if there is an `Update` effect scheduled during mounting. |
| 816 | class="cm">// This happens if `finalizeInitialChildren` returns `true` (which it |
| 817 | class="cm">// does to implement the `autoFocus` attribute on the client). But |
| 818 | class="cm">// there are also other cases when this might happen (such as patching |
| 819 | class="cm">// up text content during hydration mismatch). So we'll check this again. |
| 820 | switch (type) { |
| 821 | case class="st">'button': |
| 822 | case class="st">'input': |
| 823 | case class="st">'select': |
| 824 | case class="st">'textarea': |
| 825 | if (newProps.autoFocus) { |
| 826 | ((domElement: any): |
| 827 | | HTMLButtonElement |
| 828 | | HTMLInputElement |
| 829 | | HTMLSelectElement |
| 830 | | HTMLTextAreaElement).focus(); |
| 831 | } |
| 832 | return; |
| 833 | case class="st">'img': { |
| 834 | class="cm">// The technique here is to assign the src or srcSet property to cause the browser |
| 835 | class="cm">// to issue a new load event. If it hasnclass="st">'t loaded yet it'll fire whenever the load actually completes. |
| 836 | class="cm">// If it has already loaded we missed it so the second load will still be the first one that executes |
| 837 | class="cm">// any associated onLoad props. |
| 838 | class="cm">// Even if we have srcSet we prefer to reassign src. The reason is that Firefox does not trigger a new |
| 839 | class="cm">// load event when only srcSet is assigned. Chrome will trigger a load event if either is assigned so we |
| 840 | class="cm">// only need to assign one. And Safari just never triggers a new load event which means this technique |
| 841 | class="cm">// is already a noop regardless of which properties are assigned. We should revisit if browsers update |
| 842 | class="cm">// this heuristic in the future. |
| 843 | if (newProps.src) { |
| 844 | const src = (newProps: any).src; |
| 845 | if (enableSrcObject && typeof src === class="st">'object') { |
| 846 | class="cm">// For object src, we can't just set the src again to the same blob URL because it might have |
| 847 | class="cm">// already revoked if it loaded before this. However, we can create a new blob URL and set that. |
| 848 | class="cm">// This is relatively cheap since the blob is already in memory but this might cause some |
| 849 | class="cm">// duplicated work. |
| 850 | class="cm">// TODO: We could maybe detect if load hasn't fired yet and if so reuse the URL. |
| 851 | try { |
| 852 | setSrcObject(domElement, type, src); |
| 853 | return; |
| 854 | } catch (x) { |
| 855 | class="cm">// If URL.createObjectURL() errors, it was probably some other object type |
| 856 | class="cm">// that should be toString:ed instead, so we just fall-through to the normal |
| 857 | class="cm">// path. |
| 858 | } |
| 859 | } |
| 860 | ((domElement: any): HTMLImageElement).src = src; |
| 861 | } else if (newProps.srcSet) { |
| 862 | ((domElement: any): HTMLImageElement).srcset = (newProps: any).srcSet; |
| 863 | } |
| 864 | return; |
| 865 | } |
nothing calls this directly
no test coverage detected