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(store-devtools): replace direct with indirect eval #4216

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

rainerhahnekamp
Copy link
Contributor

@rainerhahnekamp rainerhahnekamp commented Jan 26, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

From my perspective, this removes the unnecessary eval method to get an action's payload.

If somebody knows why the eval was there in the first place (no test is failing), we could provide a safer, alternative version of unwrapAction.

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #4213

What is the new behavior?

The payload is directly used.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

`unwrapAction` internally runs `eval` if the argument
is of type `string`.

It is unclear why that `unwrapAction` was necessary
in the first place, and it looks like an artifact
from a older codebase. The line was added
in 2018.

Since `eval` is not best practice and according to ngrx#4213,
esbuild has issues with it, it is removed.
Copy link

netlify bot commented Jan 26, 2024

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 14021d2
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/65ba3dd081f8730008a0e526
😎 Deploy Preview https://deploy-preview-4216--ngrx-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

The eval is probably there because you can dispatch an action via the DevTools. I assume this is just a string, and eval parses it to an action object.

IIRC manually dispatching actions didn't completely work with the NgRx global store.
I'll test/verify this later this week, if that's the case we can also resort to the alternatives mentioned in https://esbuild.github.io/content-types/#direct-eval

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

My assumption was correct, via de DevTools you can dispatch an action.
This will be a string.

image

Because of this, I think we need to keep parsing the string using eval, but with the workaround mentioned in https://esbuild.github.io/content-types/#direct-eval

@rainerhahnekamp
Copy link
Contributor Author

Got it, will do and also add a unit tests so that in the future it is clear why we require that kind of feature.

@rainerhahnekamp
Copy link
Contributor Author

Okay, @timdeschryver, the updated version with tests has been pushed.

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

Thanks @rainerhahnekamp !

@markostanimirovic
Copy link
Member

@rainerhahnekamp is the PR title still relevant? I guess we should update it since eval and unwrapAction are still there.

@rainerhahnekamp rainerhahnekamp changed the title fix(store-devtools): remove eval and unwrapAction fix(store-devtools): replace direct with indirect eval Jan 31, 2024
@rainerhahnekamp
Copy link
Contributor Author

@markostanimirovic, you're right. I've renamed the title.

Copy link
Member

@markostanimirovic markostanimirovic left a comment

Choose a reason for hiding this comment

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

Thanks Rainer!

@markostanimirovic markostanimirovic merged commit 1df0eb5 into ngrx:main Jan 31, 2024
5 checks passed
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.

warning generated when using esbuild
3 participants