Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into add-config-max-a…
Browse files Browse the repository at this point in the history
…ttempt
  • Loading branch information
cnviradiya committed Jul 10, 2019
2 parents 7395f61 + 7f3a027 commit f6a22e6
Show file tree
Hide file tree
Showing 34 changed files with 198 additions and 230 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Shipping address is saved as default when not logged in user chooses to create account during checkout - @iwonapiotrowska (#2636)
- Can set transition style for Modal content - @grimasod (#3146)
- Added stock to cart items - @cheeerd (#3166)
- Moves theme specific stores and components into themes - @michasik (#3139)
- Decreased the `localStorage` quota usage + error handling by introducing new config variables: `config.products.disablePersistentProductsCache` to not store products by SKU (by default it's on). Products are cached in ServiceWorker cache anyway so the `product/list` will populate the in-memory cache (`cache.setItem(..., memoryOnly = true)`); `config.seo.disableUrlRoutesPersistentCache` - to not store the url mappings; they're stored in in-memory cache anyway so no additional requests will be made to the backend for url mapping; however it might cause some issues with url routing in the offline mode (when the offline mode PWA installed on homescreen got reloaded, the in-memory cache will be cleared so there won't potentially be the url mappings; however the same like with `product/list` the ServiceWorker cache SHOULD populate url mappings anyway); `config.syncTasks.disablePersistentTaskQueue` to not store the network requests queue in service worker. Currently only the stock-check and user-data changes were using this queue. The only downside it introuces can be related to the offline mode and these tasks will not be re-executed after connectivity established, but just in a case when the page got reloaded while offline (yeah it might happen using ServiceWorker; `syncTasks` can't be re-populated in cache from SW) - @pkarw (#3180)
- Translation file improvements - @vishal-7037 (#3198)
- Added configuration for max attempt task & cart by pass - @cnviradiya (#3193)

Expand Down
10 changes: 7 additions & 3 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
},
"seo": {
"useUrlDispatcher": true
"useUrlDispatcher": true,
"disableUrlRoutesPersistentCache": true
},
"console": {
"showErrorOnProduction" : false,
Expand All @@ -46,7 +47,7 @@
"csrTimeout": 5000,
"ssrTimeout": 1000,
"queryMethod": "GET",
"disableLocalStorageQueriesCache": true,
"disablePersistentQueriesCache": true,
"searchScoring": {
"attributes": {
"attribute_code": {
Expand Down Expand Up @@ -260,6 +261,7 @@
"applycoupon_endpoint": "/api/cart/apply-coupon?token={{token}}&cartId={{cartId}}&coupon={{coupon}}"
},
"products": {
"disablePersistentProductsCache": true,
"useMagentoUrlKeys": true,
"setFirstVarianAsDefaultInURL": false,
"configurableChildrenStockPrefetchStatic": false,
Expand Down Expand Up @@ -339,7 +341,6 @@
"wishlist": "LOCALSTORAGE",
"categories": "LOCALSTORAGE",
"attributes": "LOCALSTORAGE",
"products": "INDEXEDDB",
"elasticCache": "LOCALSTORAGE",
"claims": "LOCALSTORAGE",
"syncTasks": "LOCALSTORAGE",
Expand Down Expand Up @@ -395,6 +396,9 @@
}
]
},
"syncTasks": {
"disablePersistentTaskQueue": true
},
"i18n": {
"defaultCountry": "US",
"defaultLanguage": "EN",
Expand Down
4 changes: 3 additions & 1 deletion core/build/webpack.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export default {
'theme/resource': themeResources,

// Backward compatible
'@vue-storefront/core/store/lib/multistore': path.resolve(__dirname, '../lib/multistore.ts')
'@vue-storefront/core/store/lib/multistore': path.resolve(__dirname, '../lib/multistore.ts'),
'src/modules/order-history/components/UserOrders': path.resolve(__dirname, '../../core/modules/order/components/UserOrdersHistory'),
'@vue-storefront/core/modules/social-share/components/WebShare': path.resolve(__dirname, '../../src/themes/default/components/theme/WebShare.vue')
}
},
module: {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const quickSearchByQuery = async ({ query = {}, start = 0, size = 50, ent
const res = searchAdapter.entities[Request.type].resultPorcessor(resp, start, size)

if (res) { // otherwise it can be just a offline mode
cache.setItem(cacheKey, res, null, config.elasticsearch.disableLocalStorageQueriesCache).catch((err) => { console.error('Cannot store cache for ' + cacheKey + ', ' + err) })
cache.setItem(cacheKey, res, null, config.elasticsearch.disablePersistentQueriesCache).catch((err) => { console.error('Cannot store cache for ' + cacheKey + ', ' + err) })
if (!servedFromCache) { // if navigator onLine == false means ES is unreachable and probably this will return false; sometimes returned false faster than indexedDb cache returns result ...
Logger.debug('Result from ES for ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))()
res.cache = false
Expand Down
2 changes: 1 addition & 1 deletion core/lib/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function queue (task) {
if (err) Logger.error(err, 'sync')()
Vue.prototype.$bus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue
resolve(task)
}).catch((reason) => {
}, config.syncTasks.disablePersistentTaskQueue).catch((reason) => {
Logger.error(reason, 'sync')() // it doesn't work on SSR
reject(reason)
})
Expand Down
6 changes: 0 additions & 6 deletions core/modules/catalog/hooks/beforeRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ export function beforeRegistration ({ Vue, config, store, isServer }) {
storeName: 'elasticCache',
driver: localForage[config.localForage.defaultDrivers['elasticCache']]
}), true, config.server.elasticCacheQuota)

Vue.prototype.$db.productsCollection = new UniversalStorage(localForage.createInstance({
name: dbNamePrefix + 'shop',
storeName: 'products',
driver: localForage[config.localForage.defaultDrivers['products']]
}))
}
8 changes: 7 additions & 1 deletion core/modules/catalog/store/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,15 @@ const actions: ActionTree<ProductState, RootState> = {
}
const cacheKey = entityKeyName(cacheByKey, prod[(cacheByKey === 'sku' && prod['parentSku']) ? 'parentSku' : cacheByKey]) // to avoid caching products by configurable_children.sku
if (isCacheable) { // store cache only for full loads
cache.setItem(cacheKey, prod)
cache.setItem(cacheKey, prod, null, config.products.disablePersistentProductsCache)
.catch((err) => {
Logger.error('Cannot store cache for ' + cacheKey, err)()
if (
err.name === 'QuotaExceededError' ||
err.name === 'NS_ERROR_DOM_QUOTA_REACHED'
) { // quota exceeded error
cache.clear() // clear products cache if quota exceeded
}
})
}
if ((prod.type_id === 'grouped' || prod.type_id === 'bundle') && prefetchGroupProducts && !isServer) {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/compare/store/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function plugin (mutation, state) {

if (type.includes(types.COMPARE_ADD_ITEM) || type.includes(types.COMPARE_DEL_ITEM)) { // check if this mutation is comapre related
cacheStorage.setItem('current-compare', state.compare.items).catch((reason) => {
Logger.error(reason, 'compare') // it doesn't work on SSR
Logger.error(reason, 'compare')
})
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import MyOrders from '@vue-storefront/core/compatibility/components/blocks/MyAccount/MyOrders'
import { mapGetters } from 'vuex';
import onBottomScroll from '@vue-storefront/core/mixins/onBottomScroll'

export default {
name: 'UserOrders',
name: 'UserOrdersHistory',
mixins: [MyOrders, onBottomScroll],
data () {
return {
Expand Down
12 changes: 11 additions & 1 deletion core/modules/url/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as types from './mutation-types'
// you can use this storage if you want to enable offline capabilities
import { cacheStorage } from '../'
import queryString from 'query-string'
import config from 'config'
import SearchQuery from '@vue-storefront/core/lib/search/searchQuery'
import { processDynamicRoute, normalizeUrlPath, parametrizeRouteData } from '../helpers'
import { storeCodeFromRoute, removeStoreCodeFromRoute } from '@vue-storefront/core/lib/multistore'
Expand All @@ -13,7 +14,16 @@ export const actions: ActionTree<UrlState, any> = {
// if you want to use cache in your module you can load cached data like this
async registerMapping ({ commit }, { url, routeData }: { url: string, routeData: any}) {
commit(types.REGISTER_MAPPING, { url, routeData })
await cacheStorage.setItem(url, routeData)
try {
await cacheStorage.setItem(url, routeData, null, config.seo.disableUrlRoutesPersistentCache)
} catch (err) {
if (
err.name === 'QuotaExceededError' ||
err.name === 'NS_ERROR_DOM_QUOTA_REACHED'
) { // quota exceeded error
cacheStorage.clear() // clear the url cache if quota has been exceeded
}
}
return routeData
},
/**
Expand Down
10 changes: 9 additions & 1 deletion core/store/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class LocalForageCacheDriver {
private _persistenceErrorNotified: boolean;
private _useLocalCacheByDefault: boolean;
private cacheErrorsCount: any;
private localCache: any;
private _storageQuota: number;

public constructor (collection, useLocalCacheByDefault = true, storageQuota = 0) {
Expand Down Expand Up @@ -128,6 +127,14 @@ class LocalForageCacheDriver {
}
}

public getLastError () {
return this._lastError
}

public getDbName () {
return this._dbName
}

// Retrieve an item from the store. Unlike the original async_storage
// library in Gaia, we don't modify return values at all. If a key's value
// is `undefined`, we pass that value to the callback function.
Expand Down Expand Up @@ -313,6 +320,7 @@ class LocalForageCacheDriver {
}).catch(err => {
isResolved = true
this._lastError = err
throw err
}))
setTimeout(() => {
if (!isResolved) { // this is cache time out check
Expand Down
52 changes: 44 additions & 8 deletions docs/guide/upgrade-notes/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
# Upgrade notes

We're trying to keep the upgrade process as easy as possible. Unfortunately, sometimes manual code changes are required. Before pulling out the latest version, please take a look at the upgrade notes below:
## 1.10 -> 1.11
- `UserOrder` component has been renamed to `UserOrderHistory` and moved from `src/modules/order-history/components/UserOrders` to `@vue-storefront/core/modules/order/components/UserOrdersHistory`. This component was used in `MyOrders` component found here: `src/themes/default/components/core/blocks/MyAccount/MyOrders.vue`. In this file the `import` path has to be updated.
- `claims`, `promoted-offers`, `homepage` adn `ui` modules have been moved from `@vue-storefront/src/modules` to `src/themes/default/store/` and reduced to stores only.<br>
Delete those folders:<br>
-- `src/modules/claims`<br>
-- `src/modules/promoted-offers`<br>
-- `src/modules/homepage`<br>
-- `src/modules/ui-store`<br>
Copy folder `theme/store/` from `theme default`.<br>
Register the stores copied in previous step in `src/themes/default/index.js`. To do that, import them along with `initCacheStorage` method, used to replace `claims beforeRegistration hook`.
```js
import { initCacheStorage } from '@vue-storefront/core/helpers/initCacheStorage';
import { store as claimsStore } from 'theme/store/claims'
import { store as homeStore } from 'theme/store/homepage'
import { store as uiStore } from 'theme/store/ui'
import { store as promotedStore } from 'theme/store/promoted-offers'
```
Next, inside `initTheme` method use `store.registerModule` method to register the stores.
```js
Vue.prototype.$db.claimsCollection = initCacheStorage('claims');
store.registerModule('claims', claimsStore);
store.registerModule('homepage', homeStore);
store.registerModule('ui', uiStore);
store.registerModule('promoted', promotedStore);
```
- `WebShare` moved from `@vue-storefront/core/modules/social-share/components/WebShare.vue` to `@vue-storefront/src/themes/default/components/theme/WebShare.vue`. This component was used in `Product` component found here: `src/themes/default/pages/Product.vue`. In this file the `import` path has to be updated.

## 1.10 -> 1.11

We've decreased the `localStorage` quota usage + error handling by introducing new config variables:

- `config.products.disablePersistentProductsCache` to not store products by SKU (by default it's on). Products are cached in ServiceWorker cache anyway so the `product/list` will populate the in-memory cache (`cache.setItem(..., memoryOnly = true)`);
- `config.seo.disableUrlRoutesPersistentCache` - to not store the url mappings; they're stored in in-memory cache anyway so no additional requests will be made to the backend for url mapping; however it might cause some issues with url routing in the offline mode (when the offline mode PWA installed on homescreen got reloaded, the in-memory cache will be cleared so there won't potentially be the url mappings; however the same like with `product/list` the ServiceWorker cache SHOULD populate url mappings anyway);
- `config.syncTasks.disablePersistentTaskQueue` to not store the network requests queue in service worker. Currently only the stock-check and user-data changes were using this queue. The only downside it introuces can be related to the offline mode and these tasks will not be re-executed after connectivity established, but just in a case when the page got reloaded while offline (yeah it might happen using ServiceWorker; `syncTasks` can't be re-populated in cache from SW)

If by some reasons you wan't to have the `localStorage` back on for `Products by SKU`, `Url Routes` and `SyncTasks` - please juset set these variables back to `false` in your `config/local.json`.

## 1.9 -> 1.10
- Event `application-after-init` is now emitted by event bus instead of root Vue instance (app), so you need to listen to `Vue.prototype.$bus` (`Vue.prototype.$bus.$on()`) now
Expand All @@ -10,16 +46,16 @@ We're trying to keep the upgrade process as easy as possible. Unfortunately, som
- The `cart/addItem` is no longer displaying the error messages - please use the `diffLog.clientNorifications` to update the UI instead (take a look at the `AddToCart.ts` for a reference)

## 1.8 -> 1.9
- The Url Dispatcher feature added for friendly URLs. When `config.seo.useUrlDispatcher` set to true the `product.url_path` and `category.url_path` fields are used as absolute URL addresses (no `/c` and `/p` prefixes anymore). Check the latest `mage2vuestorefront` snapshot and **reimport Your products** to properly set `url_path` fields
- The Url Dispatcher feature added for friendly URLs. When `config.seo.useUrlDispatcher` set to true the `product.url_path` and `category.url_path` fields are used as absolute URL addresses (no `/c` and `/p` prefixes anymore). Check the latest `mage2vuestorefront` snapshot and **reimport Your products** to properly set `url_path` fields
- `cart.multisiteCommonCart` config property changed to `storeViews.commonCache`
- Way of creating VS Modules was changed to use factory method instead of explict object creation. Even though the feature is backward compatible we highly encourage all developers to refactor their modules to use new syntax.

The process of creating a new module with the factory method looks like the following:
````js
import { createModule } from '@vue-storefront/core/lib/module'

const moduleConfig: VueStorefrontModuleConfig = {
// VS module config
const moduleConfig: VueStorefrontModuleConfig = {
// VS module config
}

const module = createModule(moduleConfig)
Expand All @@ -31,7 +67,7 @@ const module = createModule(moduleConfig)
- Added validation for UTF8 alpha and alphanumeric characters in most checkout fields
- Update your local.json config and set default `api.url` path, without it you may have problems with elasticsearch queries.

### Troubleshooting
### Troubleshooting
- In case of CORS problem after upgrade check your elasticsearch url in config file. Best practice for that change can be found [here](https://github.com/DivanteLtd/vue-storefront/commit/77fc9c2765068303879c75ef9ed4a4b98f6763b6)

- In case of app crashing, especially when opening `vue devtools` in browser, try setting `storeViews.commonCache` to `false`.
Expand All @@ -54,14 +90,14 @@ Full changelog is available [here](https://github.com/DivanteLtd/vue-storefront/
Starting from Vue Storefront 1.7, we changed the caching strategy and offline-ready features:
- By default, the Elasticsearch Queries are executed using `GET` method and therefore are cached by Service Worker (`config.elasticsearch.queryMethod` — set it to POST for the previous behavior and if you're using graphql).
- By default, products and queries cache is set in `LocalStorage` with a quota set to 4MB (`config.server.elasticCacheQuota`). If the storage quota is set, the cache purging is executed every 30 seconds using the LRU algorithm. Local Storage is limited to 5MB in most browsers.
- We added `config.server. disableLocalStorageQueriesCache`, which is set to `true` by default. When this option is on, we're not storing the Elasticsearch results in the local cache because results are by default cached in the Service Worker cache anyway.
- We added `config.server. disablePersistentQueriesCache`, which is set to `true` by default. When this option is on, we're not storing the Elasticsearch results in the local cache because results are by default cached in the Service Worker cache anyway.
- `module.extend` has been changed to `extendModule`. You can find usage examples in `src/modules/index.ts`.
- [routes](https://github.com/patzick/vue-storefront/commit/a97eb11868de2915e86d57c4279caf944d4de422#diff-a334a7caeb7f61836f8c1178d92de3e0), [layouts](https://github.com/patzick/vue-storefront/commit/a97eb11868de2915e86d57c4279caf944d4de422#diff-48863b9fe31d7713222ec5709ef5a4fa), and component, which are not visible at page rendering are now loaded when they are needed.
- Every store manipulation should be done by dispatching actions. Invoke store dispatch on `category/mergeSearchOptions` when manipulating `store.state.category.current_product_query` somewhere.
- [here](https://github.com/patzick/vue-storefront/commit/a97eb11868de2915e86d57c4279caf944d4de422) are all changes in default themes

Backward compatibility: To reverse to the 1.0–1.6 behavior:
- Set `config.server.disableLocalStorageQueriesCache` = `false`,
- Set `config.server.disablePersistentQueriesCache` = `false`,
- Set `config.elasticsearch.queryMethod` = `POST`
- Set `config.localForage.defaultDrivers.elasticCache` = `INDEXEDDB`

Expand Down Expand Up @@ -250,7 +286,7 @@ We added Reviews support, however, Magento 2 is still lacking Reviews support in
- **removeCoupon** -> **clearCoupon** - removing coupon by dispatch removeCoupon API method and toggle coupon form
- **applyCoupon** -> **setCoupon** - submit coupon form by dispatch applyCoupon API method
- **enterCoupon** - was removed, because @keyup="enterCoupon" we changed to @keyup.enter="setCoupon"

3. We moved $emit with notification about appliedCoupon and removedCoupon from Vuex store to the default theme. Now applyCoupon and removeCoupon returns promise, which you can handle by yourself.

4. We moved VueOfflineMixin and onEscapePress mixins to the theme component. The core component is clean from UI stuff now.
Expand Down Expand Up @@ -370,7 +406,7 @@ export default {
</script>
```

4. We've added Multistore support. It shouldn't imply any breaking changes to the existing themes / extensions (by default it's just disabled).
4. We've added Multistore support. It shouldn't imply any breaking changes to the existing themes / extensions (by default it's just disabled).
## 1.0RC-2 -> 1.0RC-3 ([release notes](https://github.com/DivanteLtd/vue-storefront/releases/tag/v1.0.0-rc.3))
Expand Down
14 changes: 0 additions & 14 deletions src/modules/claims/hooks/beforeRegistration.ts

This file was deleted.

Loading

0 comments on commit f6a22e6

Please sign in to comment.