Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into translators
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-deriv committed Feb 21, 2024
2 parents c3e4546 + dada083 commit df7c4ed
Show file tree
Hide file tree
Showing 154 changed files with 7,077 additions and 3,746 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/generate-preview-link.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
name: Generate preview link

permissions:
actions: write
checks: write
contents: write
deployments: write
pull-requests: write
statuses: write

on:
pull_request_target:
types: [opened, synchronize]
Expand All @@ -24,6 +16,9 @@ concurrency:
jobs:
build_to_cloudflare_pages:
runs-on: Ubuntu-latest
permissions:
checks: write
pull-requests: write
steps:
- name: Verify user
uses: 'deriv-com/shared-actions/.github/actions/verify_user_in_organization@v1'
Expand All @@ -32,13 +27,13 @@ jobs:
token: ${{ secrets.PREVIEW_LINK_TOKEN }}

- name: Checkout to repo
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: 'Generate action link comment'
id: generate_action_url
uses: actions/github-script@v3
uses: actions/github-script@ffc2c79a5b2490bd33e0a41c1de74b877714d736
with:
github-token: ${{ github.token }}
script: |
Expand All @@ -53,7 +48,7 @@ jobs:
core.setOutput("comment", comment);
- name: Post Cloudflare Pages Preview comment
uses: marocchino/sticky-pull-request-comment@v2
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd
with:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
header: Cloudflare Pages Preview Comment
Expand All @@ -62,7 +57,7 @@ jobs:
recreate: true

- name: Setup node
uses: actions/setup-node@v2
uses: actions/setup-node@7c12f8017d5436eb855f1ed4399f037a36fbd9e8

- name: Create npmrc file
shell: bash
Expand All @@ -73,7 +68,7 @@ jobs:
run: echo '//npm.pkg.github.com/:_authToken=${{ secrets.READ_DERIV_COM_ORG_PACKAGES }}' >> .npmrc

- name: Get build output from master cache
uses: actions/cache/restore@v3
uses: actions/cache/restore@e12d46a63a90f2fae62d114769bbf2a179198b5c
with:
key: master-cache-public
restore-keys: |
Expand All @@ -83,7 +78,7 @@ jobs:
public
- name: Get cached dependencies
id: cache-npm
uses: actions/cache/restore@v3
uses: actions/cache/restore@e12d46a63a90f2fae62d114769bbf2a179198b5c
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
Expand Down Expand Up @@ -146,7 +141,7 @@ jobs:
- name: 'Generate preview link comment'
if: success()
id: generate_preview_url
uses: actions/github-script@v3
uses: actions/github-script@ffc2c79a5b2490bd33e0a41c1de74b877714d736
with:
github-token: ${{ github.token }}
script: |
Expand All @@ -165,7 +160,7 @@ jobs:
- name: 'Generate failure comment'
if: failure()
id: generate_failure_comment
uses: actions/github-script@v3
uses: actions/github-script@ffc2c79a5b2490bd33e0a41c1de74b877714d736
with:
github-token: ${{ github.token }}
script: |
Expand All @@ -180,7 +175,7 @@ jobs:
core.setOutput("comment", comment);
- name: Post Cloudflare Pages Preview comment
if: success() || failure()
uses: marocchino/sticky-pull-request-comment@v2
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd
with:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
header: Cloudflare Pages Preview Comment
Expand All @@ -189,7 +184,7 @@ jobs:
recreate: true

- name: Upload PR information to artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2
with:
name: 'pr-${{github.run_id}}'
path: .pr
144 changes: 28 additions & 116 deletions crowdin/messages.json

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions documents/avoid-minified-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
## Avoid minified error

When we updated our React version to the latest we had many console errors which was related to React Hydration

React rehydration errors (`uncaught error: minified React error #423 and #418`) happen when the client render doesn't match the server render. This can happen when using SSR or SSG, often done with Gatsby or Next.js.

### Most common causes of hydration error:

#### Table element is missing <thead> and <tbody>

I have found out that if you don't include the `<thead>` and `<tbody>` elements on your table, React will give you a hydration error. Those elements are optional, so normally aren't required in HTML, but they are required when doing SSR / SSG with React. The reason for that is that the two elements will be added by browsers to the DOM if they are missing, but client-side rendering doesn't add them to React's shadow DOM. This gives a mismatch of the table data between the static HTML data DOM and client side render, resulting in a hydration error.

Note: we are not allowed to use div element inside tr, th, td

#### Repeating your code won't return the same result

For example generating a random number can't be replicated. The code has to return the same thing when it is run on build time and on client-side. A fix for this is to either make the code repeatable or make it only run on client-side.

#### Missing closing tag for an element

If you forget to close an element, it can give a hydration error.

#### Invalid HTML structure

Invalid HTML structure can give a hydration error. For example this is incorrect HTML: `<p><h1>This is a heading</h1></p>`. What makes that invalid is the fact that headings can't be placed inside paragraphs.

Another common mistake is accidentally double quoting paragraphs, this is invalid: `<p><p>Paragraph</p></p>`

since we are using `Localize` components we are using this bad practice in many places for example we are passing a Localize inside our `p` element and we are passing a div as a component to the Localize :sweat_smile:

```javascript
// bad practice

content: {
text: '_t_Our GitHub repositories: <0>github.com/binary-com</0>_t_',
components: [<Header key={0} type="paragraph-2" weight="normal" as="p" />],
},
```

Please pass the key to the right element :sweat_smile: and make sure that the key is unique

```javascript
// bad practice

{items.map(({ translation_text, translation_components, sub_items, img }) => (
<>
<ListItem
key={translation_text}
margin_top={margin_top}
first_child_margin_top={first_child_margin_top}
size={size || '1.6rem'}
</>
))}
```

#### React.useEffect doesn't work like this in the React 18

```javascript
useEffect(() => setSelected(default_step), [items, default_step])
```

You will get destroy is not a function error!

Instead you should use it like this:

```javascript
useEffect(() => {
setSelected(default_step)
}, [items, default_step])
```

#### Content Change based on region

The regional conditions for EU and ROW content have changed. First, we adjust a local state, and subsequently update the content based on that state.

**This will give error:**

```javascript
const { is_eu } = useRegion()
return (
<NavigationBlock
renderButtons={MainNavigationButtons}
renderLogo={MainNavigationLogo}
items={is_eu ? mainEuNavItems : mainRowNavItems}
/>
)
```

**Do this insted:**

```javascript
const { is_eu } = useRegion()
const [items, setItems] = useState(mainRowNavItems)

useEffect(() => {
if (is_eu) setItems(mainEuNavItems)
}, [is_eu])

return (
<NavigationBlock
renderButtons={MainNavigationButtons}
renderLogo={MainNavigationLogo}
items={items}
/>
)
```

**Or do this:**

```javascript
const { is_eu } = useRegion()
const [show_digital_options, setShowDigitalOptions] = useState(true)

useEffect(() => {
if (is_eu) {
setShowDigitalOptions(false)
}
}, [is_eu])

return (
<AvailableTrades
DigitalOptions={
show_digital_options && <p>Digital options content</p>
}
/>
)
```
20 changes: 10 additions & 10 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import Cookies from 'js-cookie'
import { isMobile } from 'react-device-detect'
import { Analytics } from '@deriv-com/analytics'
Expand All @@ -23,13 +22,6 @@ import '@deriv-com/blocks/style.css';

const is_browser = typeof window !== 'undefined'

export const replaceHydrateFunction = () => {
return (element, container) => {
const root = createRoot(container)
root.render(element)
}
}

const checkDomain = () => {
return eval(
decodeURIComponent(
Expand Down Expand Up @@ -99,11 +91,19 @@ export const onClientEntry = () => {
? process.env.GATSBY_RUDDERSTACK_STAGING_KEY
: process.env.GATSBY_RUDDERSTACK_PRODUCTION_KEY,
})
const utm_data = JSON?.parse(
Cookies?.get('utm_data') ||
`{"utm_source":"common","utm_medium":"common","utm_campaign":"common"}`,
)
Analytics?.setAttributes({
country: Cookies.get('clients_country') || Cookies.getJSON('website_status'),
user_language: Cookies.get('user_language') || getLanguage(),
country: Cookies?.get('clients_country') || Cookies?.getJSON('website_status'),
user_language: Cookies?.get('user_language') || getLanguage(),
device_language: navigator?.language || ' ',
device_type: isMobile ? 'mobile' : 'desktop',
utm_source: utm_data?.['utm_source'],
utm_medium: utm_data?.['utm_medium'],
utm_campaign: utm_data?.['utm_campaign'],
is_authorised: !!Cookies?.get('client_information'),
})
//datadog
const dd_options = {
Expand Down
10 changes: 0 additions & 10 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,5 @@ module.exports = {
collectionTypes: strapi_config,
},
},
{
resolve: 'gatsby-plugin-env-variables',
options: {
allowList: [
'GATSBY_RUDDERSTACK_URL',
'GATSBY_RUDDERSTACK_STAGING_KEY',
'GATSBY_RUDDERSTACK_PRODUCTION_KEY',
],
},
},
],
}
42 changes: 21 additions & 21 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,30 +420,32 @@ exports.onCreateWebpackConfig = ({ stage, actions, loaders, getConfig }, { ...op
const config = getConfig()
const isProduction = config.mode === 'production'

const splitChunks = {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: -10,
},
bundle: {
test: /\.(js|ts|tsx)$/,
name: 'bundle',
chunks: 'all',
priority: -20,
enforce: true,
},
},
}

actions.setWebpackConfig({
devtool: isProduction ? false : 'inline-source-map', // enable/disable source-maps
mode: isProduction ? 'production' : 'development',
optimization: {
minimize: isProduction,
minimizer: [new TerserPlugin()],
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: -10,
},
bundle: {
test: /\.(js|ts|tsx)$/,
name: 'bundle',
chunks: 'all',
priority: -20,
enforce: true,
},
},
},
...(isProduction && { splitChunks }),
mangleExports: 'size',
mangleWasmImports: true,

Expand All @@ -462,9 +464,7 @@ exports.onCreateWebpackConfig = ({ stage, actions, loaders, getConfig }, { ...op
providedExports: true,
usedExports: true,
},
plugins: [
new StylelintPlugin({ ...style_lint_options, ...options }),
],
plugins: [new StylelintPlugin({ ...style_lint_options, ...options })],
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
Expand Down
2 changes: 1 addition & 1 deletion i18n-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},
th: {
path: 'th',
display_name: 'Thai',
display_name: 'ไทย',
short_name: 'TH',
affiliate_lang: 12,
},
Expand Down
Loading

0 comments on commit df7c4ed

Please sign in to comment.