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

[BUG] Web SDK hooks can return a promise? #630

Closed
toddbaert opened this issue Oct 31, 2023 · 8 comments · Fixed by #671
Closed

[BUG] Web SDK hooks can return a promise? #630

toddbaert opened this issue Oct 31, 2023 · 8 comments · Fixed by #671
Assignees
Labels
bug Something isn't working

Comments

@toddbaert
Copy link
Member

toddbaert commented Oct 31, 2023

Both the web and server SDK use a hook interface defined in /shared aka core.
In web, the hook calls are not awaited, so the promise is somewhat useless.

I'm fairly certain this is a bug. We can allow the server to return both promises and non, but the web SDK cannot return Promises in hooks because it doesn't await them and has a synchronous API.

cc @beeme1mr @lukas-reining

@toddbaert toddbaert added the bug Something isn't working label Oct 31, 2023
@lukas-reining
Copy link
Member

Ya, and after having a look I also found that the "hook modified context" is not merged into the flag evaluation context, while it is in the server SDK. In the tests we have a test checking for evaluationContext must be mutable and EvaluationContext must be passed to next "before" hook but not for the client that the before hooks change the context.
I could fix that if we decide that this is really a bug.

@toddbaert
Copy link
Member Author

toddbaert commented Nov 11, 2023

Ya, and after having a look I also found that the "hook modified context" is not merged into the flag evaluation context, while it is in the server SDK. In the tests we have a test checking for evaluationContext must be mutable and EvaluationContext must be passed to next "before" hook but not for the client that the before hooks change the context. I could fix that if we decide that this is really a bug.

I don't think it's valid that the before hooks in the client change the context in the client implementations. The static context should only be change via the api.setContext method, which is reconciles in the on context changed handler; otherwise things will get mismatched between the context and the reconciled state in the provider. We should probably put 3.2.3 under the same condition as the previous 2 points. Does this make sense to you as well, @beeme1mr ?

@beeme1mr
Copy link
Member

Yes, that makes sense to me. Hooks should not be able to modify context in the client SDK.

@lukas-reining
Copy link
Member

Ah yes totally missed that we specified this.
But then the type of the beforeHook is even more confusing.

The current type is:
before?(hookContext: BeforeHookContext, hookHints?: HookHints): Promise<EvaluationContext | void> | EvaluationContext | void

This is correct for the server SDK, for the client I would say it should be just void then:
before?(hookContext: BeforeHookContext, hookHints?: HookHints): void

What do you think @beeme1mr @toddbaert? I could change this then.

@beeme1mr
Copy link
Member

Yes, that looks how I would expect.

@lukas-reining lukas-reining self-assigned this Nov 13, 2023
@lukas-reining
Copy link
Member

@toddbaert I think this should also be under the condition that we are using dynamic context:
https://openfeature.dev/specification/sections/hooks#requirement-414

@toddbaert
Copy link
Member Author

@toddbaert I think this should also be under the condition that we are using dynamic context: https://openfeature.dev/specification/sections/hooks#requirement-414

Yes, I think you're right about that.

@toddbaert
Copy link
Member Author

@lukas-reining opened: open-feature/spec#217

github-merge-queue bot pushed a commit that referenced this issue Nov 21, 2023
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR

Fixes return type of hooks in client SDK. 

Maybe we should make this more clear in the spec @toddbaert.

### Related Issues
Fixes #630 

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks
<!-- anything that is related to this PR but not done here should be
noted under this section -->
<!-- if there is a need for a new issue, please link it here -->

### How to test
<!-- if applicable, add testing instructions under this section -->

---------

Signed-off-by: Lukas Reining <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants