Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: usePrototypeForDefaults with repeated fix #499

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexeyten
Copy link
Contributor

Just an idea how to fix #498.

Declare repeated fields as “possibly undefined” and create them on demand. So “hazzle check” would still work, but callers will have to create array manually.

@stephenh stephenh force-pushed the main branch 4 times, most recently from cdf2835 to 7017d4c Compare May 28, 2022 17:39
Copy link

@pbhuynh pbhuynh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also running into this issue with my project. What are the next steps something like this fix in @stephenh ? Thanks!

@@ -1004,42 +1011,49 @@ export const SimpleWithMap = {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.entitiesById ||= [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all the properties under this SimpleWithMap be instantiated with an empty object, i.e. {} instead of array?

@@ -736,7 +736,7 @@ function generateBaseInstanceFactory(
: isMapType(ctx, messageDesc, field)
? '{}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to account the map case as well?

@stephenh
Copy link
Owner

Hi @pbhuynh , just taking a look--sorry @alexeyten , you had some great work here, and I must not have had time to review it/think about it when you first submitted the PR.

In terms of approach, I think if I was personally using usePrototypeForDefaults with repeated fields all day, every day, I'd probably try to implement @alexeyten 's "auto-set on read" ideas, which seem pretty neat/ergonomic.

That said, I think what the current PR is doing, just making the repeated fields undefined, is probably more straight-forward/an easier path to getting merged.

Just in general @pbhuynh , I think next steps would be 1) getting the PR rebased and 2) have a clear "failed before, passing now" test/reproduction in the integration tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

usePrototypeForDefaults cause issues with repeated fields
3 participants