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: don't use .fromBinary on import #681

Closed
wants to merge 3 commits into from
Closed

Conversation

nohehf
Copy link

@nohehf nohehf commented Jan 29, 2024

This PR fixes #680, by transforming the b64 feature set to a JSON string describing the message, at buildtime (bootstrap step / npm run -w packages/protobuf bootstrap:featureset-defaults).
This allows to import @bufbuild/protobuf in a context that doesn't provide a TextEncoder globally.
Please let me know if you have any feedback :)

@CLAassistant
Copy link

CLAassistant commented Jan 29, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! I think the dependence cycle is problematic, see comment below.

const r = inject(content, ` "${defaults.toString("base64url")}" `);
const base64String = defaults.toString("base64url");
const buffer = protoBase64.dec(base64String);
const featureSetDefaults = FeatureSetDefaults.fromBinary(buffer);
Copy link
Member

Choose a reason for hiding this comment

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

Depending on our own runtime can be an issue here, because we need this package to bootstrap it 😓

I'm not completely sure it'll be problem in practice now or in the future, but I'm sure that not using our own runtime within this helper package avoids the problem 100% 🙂

Copy link
Author

Choose a reason for hiding this comment

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

Yep I did think about it, but as we only depend on some google types, it didn't seem to be an issue. However I do agree it's best to avoid it :)

@timostamm
Copy link
Member

So I realized this was an issue when I saw #663 last week and wrote a fix, but didn't get to pushing it up until today. You beat me to it - but #683 avoids the dependency cycle. Could you confirm that it works for you?

@timostamm
Copy link
Member

Superseded by #683, but thanks for the PR ❤️

@timostamm timostamm closed this Jan 29, 2024
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.

Calling FeatureSetDefaults.fromBinary in a non nodejs runtime fails importing @bufbuild/protobuf
3 participants