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

[STRF-10120] paper-handlebars - resource hints should include the proper values for PreloadResourceType #212

Merged
merged 2 commits into from
Oct 19, 2022

Conversation

rafa-avila-bc
Copy link
Contributor

What? Why?

  • fixes issues of duplicated hint returning undefined.

How was it tested?

  • unit tests

cc @bigcommerce/storefront-team

@rafa-avila-bc rafa-avila-bc self-assigned this Oct 18, 2022
@@ -48,11 +48,11 @@ function addResourceHint(globals, path, rel, type, cors) {

let index = globals.resourceHints.findIndex(({src}) => path === src);
if (index >= 0) {
return;
return path;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There may be scenarios where nested templates include helpers that produce preload hints for the same resource where only the 1st usage of the helper will have the correct effect and the rest, will have unexpected results.

As an example let's take stylesheet, also, think that there is 1 common-resources (nested) template that is included in a base template. The nested template includes the {{{ stylesheet '/asset/css/theme.css' }}} helper which base template also includes but, in a linear order, the nested template is rendered before the occurrence of the stylesheet helper in the base template. For the nested template, the produced link tag will be correct, it will include a valid href attribute. The stylesheet in the base template:

  • (with return;) will produce a href="undefined"
  • (with the proposed change) will produce a valid href attribute, with the correct URL.

@@ -37,6 +37,35 @@ describe('stylesheet helper', () => {
});
});

it('should render both link tags correclty but produce only one resource hint', done => {
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 test exemplifies what's described in this comment https://github.com/bigcommerce/paper-handlebars/pull/212/files#r998713714

jairo-bc
jairo-bc previously approved these changes Oct 19, 2022
…per values for PreloadResourceType

- fixes issues of duplicated hint returning undefined.
…per values for PreloadResourceType

- pr fixes
@rafa-avila-bc rafa-avila-bc merged commit 95542ba into bigcommerce:master Oct 19, 2022
@rafa-avila-bc rafa-avila-bc deleted the STRF-10120.1 branch October 19, 2022 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants