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

chore: update react-email deps #7840

Merged
merged 5 commits into from
Nov 14, 2024
Merged

chore: update react-email deps #7840

merged 5 commits into from
Nov 14, 2024

Conversation

KenLSM
Copy link
Contributor

@KenLSM KenLSM commented Nov 4, 2024

Problem

Closes #7833, Closes #7834

Solution

  1. Updates several related packages.
  • "@react-email/components"
  • "@react-email/render"
  • "react-email"
  1. Explicitly install react-dom as react-email/render has removed react-dom from its deps, i.e., it is no longer transitively installed, thus we have to add it ourselves.

  2. Wrapped render with fromPromise as it is now async.

Breaking Changes

  • No - this PR is backwards compatible

@KenLSM KenLSM force-pushed the chore/react-email-update branch from de8910a to 97ef4d6 Compare November 4, 2024 12:12
@KenLSM KenLSM changed the title chore: update deps chore: update react-email deps Nov 5, 2024
@KenLSM KenLSM changed the title chore: update react-email deps (wip) chore: update react-email deps Nov 5, 2024
@KenLSM KenLSM force-pushed the chore/react-email-update branch from c4f10a2 to e821b13 Compare November 13, 2024 17:21
@KenLSM KenLSM changed the title (wip) chore: update react-email deps chore: update react-email deps Nov 13, 2024
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Nov 13, 2024

Datadog Report

Branch report: chore/react-email-update
Commit report: 1541326
Test service: formsg

✅ 0 Failed, 1375 Passed, 1 Skipped, 3m 47.56s Total duration (2m 12.97s time saved)

@@ -1079,19 +1093,30 @@ export class MailService {
responseUrl,
}

const html = render(MrfWorkflowEmail(htmlData))
console.log(render(MrfWorkflowEmail(htmlData)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray console.log found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 1541326

@KenLSM KenLSM requested a review from kevin9foong November 14, 2024 05:14
Copy link
Contributor

@kevin9foong kevin9foong left a comment

Choose a reason for hiding this comment

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

Just a few questions for my understanding, otherwise lgtm

"test:backend": "env-cmd -f __tests__/setup/.test-env jest",
"test:backend:ci": "env-cmd -f __tests__/setup/.test-env jest --maxWorkers=2 --logHeapUsage --workerIdleMemoryLimit=0.2",
"test:backend:watch": "env-cmd -f __tests__/setup/.test-env jest --watch",
"test:backend": "env-cmd -f __tests__/setup/.test-env node --experimental-vm-modules node_modules/jest/bin/jest.js",
Copy link
Contributor

@kevin9foong kevin9foong Nov 14, 2024

Choose a reason for hiding this comment

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

Trying to understand this change - why did we need to add this experimental-vm-modules flag? based on my research, it has something to do with ESM vs commonJS modules - did the new bump in deps change to using ESM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

react-email@v1 introduced the use of dynamic imports. i.e., at runtime doing requires('somePackage'). This is something that jest isn't very happy with.

For non-jest usage, we're running them through a different bundler / transpiler. While for tests, we're directly running it through jest.

Copy link
Contributor

Choose a reason for hiding this comment

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

for more context, react email v3.0.2 does an ES modules dynamic import syntax const { default: reactDOMServer } = await import("react-dom/server");. Since we are using jest, it does not support ES module syntax out of the box and requires the experimental-vm-modules flag to support this ESM syntax

@@ -224,6 +226,7 @@
"maildev": "^2.1.0",
"mockdate": "^3.0.5",
"prettier": "^3.3.3",
"react-dom": "^18.3.1",
Copy link
Contributor

@kevin9foong kevin9foong Nov 14, 2024

Choose a reason for hiding this comment

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

Trying to understand the usage of react-dom as well - I'm seeing usage of react-dom in some stories and index.tsx
However, they dont seem to be importing from react-email previously, so im wondering why the removal of react-dom from react-email/render causes us to have to install react-dom?

Copy link
Contributor

@kevin9foong kevin9foong Nov 14, 2024

Choose a reason for hiding this comment

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

Rationale:

  • react-email used to have react-dom as a dependency in v2.x.x but they switched it to a peer dependency in v3.0.2 (react-email uses react-dom internally)

Peer dependency means it is the responsibility of the 'peer' = aka FormSG in this case to install it as a dependency -> hence we add react-dom to our dependencies.

@KenLSM KenLSM merged commit e51e6dc into develop Nov 14, 2024
16 of 18 checks passed
@KenLSM KenLSM deleted the chore/react-email-update branch November 14, 2024 06:30
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.

2 participants