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

feat(root): wip refactor control compilation #7590

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

djabarovgeorge
Copy link
Contributor

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

linear bot commented Jan 27, 2025

Copy link

netlify bot commented Jan 27, 2025

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit 0bb7387
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/6797666df96612000895145b
😎 Deploy Preview https://deploy-preview-7590.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 27, 2025

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 0bb7387
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/6797666d040dad00081836cd
😎 Deploy Preview https://deploy-preview-7590.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Jan 27, 2025

Open in Stackblitz

npm i https://pkg.pr.new/novuhq/novu/@novu/framework@7590
npm i https://pkg.pr.new/novuhq/novu@7590

commit: 0bb7387

const templateControls = await this.createStepControls(step, event);

if (this.compileControls) {
controls = await this.renderTemplateControls(templateControls, event);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the framework compiles the controls by default. However, if the user prefers to compile the controls themselves, they have the option to do so.

* Whether to compile controls.
* Defaults to true.
*/
compileControls?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, this is a global option. However, we could make it more granular in the future, for example, configurable on a per-step basis.

@@ -33,7 +34,7 @@ export class EmailOutputRendererUsecase {

const liquifiedMaily = this.wrapMailyInLiquidUsecase.execute({ emailEditor: body });
const transformedMaily = await this.transformMailyContent(liquifiedMaily, renderCommand.fullPayloadForRender);
const parsedMaily = await this.parseMailyContentByLiquid(transformedMaily, renderCommand.fullPayloadForRender);
const parsedMaily = await parseLiquid(transformedMaily, renderCommand.fullPayloadForRender);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main purpose of this PR:

Previously, the framework would parse controls once before execution, and then parse them again during execution.

With this update, controls are parsed only once, improving efficiency.


// Only evaluate a skip condition when the step is the current step and not in preview mode.
if (!isPreview && stepId === event.stepId) {
const templateControls = await this.createStepControls(step, event);
const controls = await this.compileControls(templateControls, event);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change removes the second (for all client users) or third (for email Novu users) duplicate control compilation, simplifying the process.

Copy link
Contributor

@scopsy scopsy left a comment

Choose a reason for hiding this comment

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

Looks good, would love to hear some other thoughts on the compileControls terminology 🙏

return JSON.parse(renderedString);
}

export async function parseLiquidString(value: string, variables: object): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

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

A small question, is it possible some how to reuse the same liquid instance from the framework SDK? The reason I'm asking is because we might want to add custom liquid filters to the system, and in this case we will have to duplicate them twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, i thought about it as well, we need to find a good way to export it from @novu/framework.

@@ -86,6 +89,7 @@ export class Client {
apiUrl: resolveApiUrl(providedOptions?.apiUrl),
secretKey: resolveSecretKey(providedOptions?.secretKey),
strictAuthentication: !isRuntimeInDevelopment(),
compileControls: providedOptions?.compileControls ?? true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if compileControls is the most explaining terminology of what actually happens. As Compile can mean a lot of things 🤔 should we be more direct here: parseLiquidControls or smth? I do remember that we wanted to allow to replace the liquid with other custom parsers tho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point. This was the most fragile change in the i n this PR. As we think of the future evolution of this package, it’s essential to design it properly.

I wouldn’t go with parseLiquidControls, as it’s too specific. As you mentioned, other libraries could handle control compilation, so we need a more generic approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants