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 Google Translate issues with React #1382

Merged
merged 9 commits into from
Apr 5, 2023
Merged

Conversation

lukaw3d
Copy link
Member

@lukaw3d lukaw3d commented Apr 4, 2023

Fixes #1354

Comment on lines +58 to +122
// Ban `condition && text node`
{
selector:
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' +
'[right.type!="JSXElement"][right.type!="JSXFragment"]',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban `condition && <>text node</>`
{
selector:
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' +
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban text nodes before or after a condition `text {condition && <span/>} text`
{
selector:
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' +
' > JSXText[value!=/^\\s+$/]',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.',
},
// Ban variables before or after `{var} {condition && <span/>} {var}` (just in case they return a string)
{
selector:
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' +
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.',
},

// Ban `condition ? text node : <span/>`
{
selector:
'JSXElement > JSXExpressionContainer > ConditionalExpression' +
' > :matches(.consequent, .alternate):not(JSXElement, JSXFragment)',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban `condition ? <>text node</> : <span/>`
{
selector:
'JSXElement > JSXExpressionContainer > ConditionalExpression' +
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban text nodes before or after a condition `text {condition ? <span/> : <span/>} text`
{
selector:
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' +
' > JSXText[value!=/^\\s+$/]',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.',
},
// Ban variables before or after `{var} {condition ? <span/> : <span/>} {var}` (just in case they return a string)
{
selector:
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' +
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.',
},
Copy link
Member Author

Choose a reason for hiding this comment

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

This probably covers most potential issues, but there is a possibility of undetectable:

const a = condition ? 'aa' : <span>bb</span>
return <Box>{a}</Box>

Copy link
Member Author

Choose a reason for hiding this comment

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

We should later make a package out of it, and reuse it on explorer

@github-actions
Copy link

github-actions bot commented Apr 4, 2023

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 32 0 0.11s
✅ JAVASCRIPT eslint 1 0 0 4.73s
✅ REPOSITORY checkov yes no 19.48s
✅ REPOSITORY git_diff yes no 0.0s
✅ TSX eslint 13 0 0 8.67s
✅ TYPESCRIPT eslint 1 0 0 5.65s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@buberdds
Copy link
Contributor

buberdds commented Apr 4, 2023

snapshots

@cloudflare-pages
Copy link

cloudflare-pages bot commented Apr 4, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: dbc2d1f
Status: ✅  Deploy successful!
Preview URL: https://cdae65d4.oasis-wallet.pages.dev
Branch Preview URL: https://lw-google-translate-crashes.oasis-wallet.pages.dev

View logs

@lukaw3d lukaw3d force-pushed the lw/google-translate-crashes branch from 65c087f to 2121514 Compare April 4, 2023 17:14
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #1382 (65c087f) into master (82bf662) will decrease coverage by 0.91%.
The diff coverage is 17.54%.

❗ Current head 65c087f differs from pull request most recent head dbc2d1f. Consider uploading reports for the commit dbc2d1f to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1382      +/-   ##
==========================================
- Coverage   84.32%   83.41%   -0.91%     
==========================================
  Files         143      144       +1     
  Lines        3687     3732      +45     
  Branches      674      710      +36     
==========================================
+ Hits         3109     3113       +4     
- Misses        578      619      +41     
Flag Coverage Δ
cypress 51.28% <14.28%> (-0.04%) ⬇️
jest 78.36% <17.54%> (-0.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../AccountPage/Features/TransactionHistory/index.tsx 85.71% <ø> (ø)
.../app/pages/ParaTimesPage/ParaTimeContent/index.tsx 100.00% <ø> (ø)
...pp/pages/ParaTimesPage/ParaTimeSelection/index.tsx 90.00% <ø> (ø)
...pp/pages/ParaTimesPage/TransactionAmount/index.tsx 96.82% <ø> (ø)
...pages/StakingPage/Features/ValidatorList/index.tsx 79.24% <0.00%> (ø)
src/locales/i18n.ts 100.00% <ø> (ø)
src/utils/eslint-test-no-restricted-syntax.tsx 0.00% <0.00%> (ø)
src/app/components/Transaction/index.tsx 78.82% <50.00%> (-0.94%) ⬇️
src/app/components/AmountFormatter/index.tsx 100.00% <100.00%> (ø)
src/app/components/Sidebar/index.tsx 87.03% <100.00%> (ø)
... and 3 more

... and 1 file with indirect coverage changes

@lukaw3d
Copy link
Member Author

lukaw3d commented Apr 4, 2023

fixed

Copy link
Contributor

@buberdds buberdds left a comment

Choose a reason for hiding this comment

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

  • src/app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal/index.tsx
    L~144 can we wrap {t('openWallet.importAccounts.pageNumber' with span so pagination counter is working when translation is on

  • Would add translate="no" to AmmountFormatter ticker ~L60

<Language />
</Box>
<Box pad="small" flex="grow">
<Text>Language</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

missing i18n label

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we want to keep this one international. Otherwise if someone gets into French, they can't get out

{!hideTicker && (
<Text size={size} {...tickerProps}>
{' '}
{ticker}
<NoTranslate>{` ${ticker}`}</NoTranslate>
Copy link
Member Author

Choose a reason for hiding this comment

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

Would add translate="no" to AmmountFormatter ticker ~L60

Added, tho I found ticker translation cute

Comment on lines +144 to +145
<span>
{t('openWallet.importAccounts.pageNumber', 'Page {{ pageNum }} of {{ totalPages }}', {
Copy link
Member Author

Choose a reason for hiding this comment

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

src/app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal/index.tsx
L~144 can we wrap {t('openWallet.importAccounts.pageNumber' with span so pagination counter is working when translation is on

Added. Nice, it works. No idea why it works.

@lukaw3d lukaw3d force-pushed the lw/google-translate-crashes branch from e1b1ae0 to dbc2d1f Compare April 5, 2023 14:41
@lukaw3d lukaw3d merged commit 1c7a44b into master Apr 5, 2023
@lukaw3d lukaw3d deleted the lw/google-translate-crashes branch April 5, 2023 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants