Note that this seems to be a core piece of the webform, so I'm not sure how come nobody else reports it.
Basically if you have a custom webform component (let's say a 2 level select with children choice based on parent choice), and it triggers an AJAX call, you'd expect ajax replaced element retains the values you selected.
The _webform_render_component() hook basically expects input values passed from webform_client_form() function, when the form rebuilds.
The exact value is being passed from this line: https://git.drupalcode.org/project/webform/blob/7.x-4.x/webform.module#L...
$component_value = isset($input_values[$cid]) ? $input_values[$cid] : NULL;
_webform_client_form_add_component($node, $component, $component_value, $form['submitted'], $form, $input_values, 'form', $page_num, $filter);
However, the $input_values[$cid] here is always empty. This is because $cid is the "component id", which is something numeric, like 1, 2,3. While the actual $input_values has keys from "form_key", e.g. first_name, last_name etc.
Looking up a few lines it looks like $input_values are initialized from several sources. So I'm not sure if under other situations they are actually using component's $cid instead of form_key.
But from this debug screenshot you can see clearly, in my test case it has form_keys as index.

| Comment | File | Size | Author |
|---|---|---|---|
| #2 | get_component_value_by_form_key-3102509-2.patch | 788 bytes | yang_yi_cn |
| webform_input_values.png | 713.99 KB | yang_yi_cn |
Comments
Comment #2
yang_yi_cn commentedPatch
Comment #3
liam morlandComment #4
liam morlandWhat are the steps to reproduce this problem? Maybe something about the custom component is not configured correctly.
Comment #5
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.