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

New headless mode feature #105 #106

Merged
merged 1 commit into from
Aug 1, 2023
Merged

New headless mode feature #105 #106

merged 1 commit into from
Aug 1, 2023

Conversation

reisfmb
Copy link
Contributor

@reisfmb reisfmb commented Jul 27, 2023

Summary:

My approach was to implement a lib "metadata" that abstracts the logic on the page processor.

That lib is then used on the page processor, without changing the logic previously defined.

This same lib is also used in a new "metadata" service, which purpose is to provide an endpoint that mimics the logic on the page processor having in mind the headless approach, i.e, returns a json in which the frontend can consume and inject the proper metadata:

image

Finally, to avoid hydration errors, a new "headless mode" checkbox config was set. If set to false (default value), then the app will work in the same way as it was. If set to true, then page processor will do nothing and the "metadata" service will be available:

image

@reisfmb reisfmb self-assigned this Jul 27, 2023
@reisfmb reisfmb linked an issue Jul 27, 2023 that may be closed by this pull request
@reisfmb
Copy link
Contributor Author

reisfmb commented Jul 27, 2023

Points for improvements:

  • Improve name of this function. Suggestions?
  • Both getMetaData and getTitle depends on site, siteContent and siteConfig, which are returned from the get function. Since both are executed on the same scope on the page processor, we can improve it making both getMetaData and getTitle functions accept site, siteContent and siteConfig as props, and only run the current get function once.

@reisfmb
Copy link
Contributor Author

reisfmb commented Jul 27, 2023

Here is an example of the usage of the app on headless mode in site-enonic-next

@alansemenov
Copy link
Member

Improve name of this function. Suggestions?

getContentAndSite or getContentProps

Both getMetaData and getTitle depends on site, siteContent and siteConfig, which are returned from the get function. Since both are executed on the same scope on the page processor, we can improve it making both getMetaData and getTitle functions accept site, siteContent and siteConfig as props, and only run the current get function once.

Yes, we should do that.

I would also stay clear of one-character variable names, unless it's a simple counter.

const g = get(contentPath);

Should be something like

const contentAndSite = getContentAndSite(contentPath);

@reisfmb
Copy link
Contributor Author

reisfmb commented Jul 31, 2023

@alansemenov

Implemented those improvements + helpful console warnings in case of service failing to retrieve data.

Tested the usage of the app on site market locally, with headless mode enabled and disabled and it seems to be working just fine!

If approved, I think we're good to go with a release.

@reisfmb reisfmb merged commit 45658f6 into master Aug 1, 2023
2 checks passed
@alansemenov alansemenov deleted the 105 branch August 1, 2023 13:25
Comment on lines +10 to +14
<input name="headless" type="CheckBox">
<label>Headless mode</label>
<help-text>If enabled, page processor will do nothing and its logic will be available in "metadata" service.</help-text>
<occurrences minimum="0" maximum="1"/>
</input>
Copy link
Contributor

Choose a reason for hiding this comment

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

The frontend should disable page processing. As we do in the nextxp proxy: enonic/lib-nextxp@fc72d37

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

You usually don't want the backend to modify your frontend html. (Currently headless often only does this inside xp/content studio rendering and not live)
The extension of this app is made to access the data for the frontend.

I guess it boils down to if you want to disable this on every app or one global place for all headless to disable. I think the fontend should deal with it.

@sigdestad
Copy link
Member

sigdestad commented Aug 7, 2023

I did not read through all the details here, but I'm confident we should not have checkbox called "headless mode". Basically, the preview can prevent injections from this app by setting the "post processing = false" in the response object.

At least if SEO metafields makes uses this feature to inject markup

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.

Feature: implement headless mode
4 participants