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(storage-plugin): access local and session storages globals only in browser #2034

Merged
merged 1 commit into from Jul 13, 2023

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Jul 12, 2023

This commit modifies the factory functions for the LOCAL_STORAGE_ENGINE
and SESSION_STORAGE_ENGINE tokens. Previously, these functions resolved
to localStorage and sessionStorage, which caused an error when executing
the code in a server-side environment where localStorage is not defined.
To address this, we have implemented a check to determine if the code is
running in a browser environment before retrieving the localStorage.

if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
for (const { key, engine } of this._keysWithEngines) {
let storedValue = nextState;
if (isInitOrUpdateAction && !hasMigration) {
Copy link
Member Author

Choose a reason for hiding this comment

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

no updates here, just made an early return to make it more readable

@bundlemon
Copy link

bundlemon bot commented Jul 12, 2023

BundleMon

Unchanged files (3)
Status Path Size Limits
fesm2015/ngxs-store.js
94.47KB 125KB / +0.5%
fesm2015/ngxs-store-operators.js
6.23KB 15KB / +0.5%
fesm2015/ngxs-store-internals.js
3.57KB 20KB / +0.5%

No change in files bundle size

Unchanged groups (3)
Status Path Size Limits
@ngxs/store(esm2015)[gzip]
./esm2015/**/*.js
180.26KB +1%
@ngxs/store(umd)[gzip]
./bundles/*.umd.js
36.55KB +1%
@ngxs/store(fesm2015)[gzip]
./fesm2015/*.js
25.02KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Jul 12, 2023

BundleMon (NGXS Plugins)

Files updated (2)
Status Path Size Limits
Plugins(fesm2015)[gzip]
storage-plugin/fesm2015/ngxs-storage-plugin.j
s
3.67KB (+31B +0.83%) +1%
Plugins(umd)[gzip]
storage-plugin/bundles/ngxs-storage-plugin.um
d.js
7.94KB (-20B -0.25%) +1%
Unchanged files (12)
Status Path Size Limits
Plugins(umd)[gzip]
router-plugin/bundles/ngxs-router-plugin.umd.
js
7.41KB +1%
Plugins(umd)[gzip]
websocket-plugin/bundles/ngxs-websocket-plugi
n.umd.js
6.92KB +1%
Plugins(umd)[gzip]
hmr-plugin/bundles/ngxs-hmr-plugin.umd.js
6.89KB +1%
Plugins(umd)[gzip]
form-plugin/bundles/ngxs-form-plugin.umd.js
3.44KB +1%
Plugins(fesm2015)[gzip]
router-plugin/fesm2015/ngxs-router-plugin.js
3.09KB +1%
Plugins(umd)[gzip]
devtools-plugin/bundles/ngxs-devtools-plugin.
umd.js
2.75KB +1%
Plugins(fesm2015)[gzip]
form-plugin/fesm2015/ngxs-form-plugin.js
2.67KB +1%
Plugins(fesm2015)[gzip]
hmr-plugin/fesm2015/ngxs-hmr-plugin.js
2.65KB +1%
Plugins(fesm2015)[gzip]
websocket-plugin/fesm2015/ngxs-websocket-plug
in.js
2.59KB +1%
Plugins(umd)[gzip]
logger-plugin/bundles/ngxs-logger-plugin.umd.
js
2.53KB +1%
Plugins(fesm2015)[gzip]
devtools-plugin/fesm2015/ngxs-devtools-plugin
.js
2.17KB +1%
Plugins(fesm2015)[gzip]
logger-plugin/fesm2015/ngxs-logger-plugin.js
2.01KB +1%

Total files change +11B +0.02%

Groups updated (3)
Status Path Size Limits
All Plugins(esm2015)[gzip]
./-plugin/esm2015/**/.js
108.83KB (+128B +0.11%) +1%
All Plugins(fesm2015)[gzip]
./-plugin/fesm2015/.js
18.85KB (+31B +0.16%) +1%
All Plugins(umd)[gzip]
./-plugin/bundles/.umd.js
37.89KB (-20B -0.05%) +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Jul 12, 2023

BundleMon (Integration Projects)

Files updated (2)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng13-ivy/dist-integration/main.(h
ash).js
69.85KB (+35B +0.05%) +1%
Main bundles(Gzip)
hello-world-ng14-ivy/dist-integration/main.(h
ash).js
64.84KB (+32B +0.05%) +1%
Unchanged files (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng12-ivy/dist-integration/main.(h
ash).js
67.99KB +1%

Total files change +74B +0.04%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@arturovt arturovt force-pushed the fix/storage-plugin-ssr branch 2 times, most recently from 6304652 to a002c2b Compare July 12, 2023 20:38
@arturovt arturovt marked this pull request as ready for review July 12, 2023 20:38
@nx-cloud
Copy link

nx-cloud bot commented Jul 12, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit b3ea53c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

Copy link
Contributor

@Carniatto Carniatto left a comment

Choose a reason for hiding this comment

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

LGTM. Would be nice to add a small PR description with 1 or 2 lines of motivation. What are the usages that we don't have a browser?

…n browser

This commit modifies the factory functions for the `LOCAL_STORAGE_ENGINE`
and `SESSION_STORAGE_ENGINE` tokens. Previously, these functions resolved
to `localStorage` and `sessionStorage`, which caused an error when executing
the code in a server-side environment where localStorage is not defined.
To address this, we have implemented a check to determine if the code is
running in a browser environment before retrieving the `localStorage`.
@codeclimate
Copy link

codeclimate bot commented Jul 13, 2023

Code Climate has analyzed commit b3ea53c and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 2

The test coverage on the diff in this pull request is 86.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 96.7% (0.0% change).

View more on Code Climate.

@arturovt arturovt merged commit 68ac7b5 into master Jul 13, 2023
17 of 18 checks passed
@arturovt arturovt deleted the fix/storage-plugin-ssr branch July 13, 2023 15:50
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.

None yet

2 participants