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: compatibility with latest versions of React and Next #55

Merged
merged 29 commits into from
Feb 26, 2024

Conversation

J3m5
Copy link
Collaborator

@J3m5 J3m5 commented Aug 3, 2023

close #54, close #56

JH added 7 commits August 4, 2023 15:55
…n project config environments

use ts file for jest config, add types file for common types, improve types
…deStream

data-reactroot attribute is not added on the root element since react 16
so it's no more needed to add add a root div to remove the attribute afterward
improve types
return a React element instead of a string and remove div from esi:include tag
improve environment checking in server.tsx
examples/express/package.json Outdated Show resolved Hide resolved
examples/express/src/components/MyFragment.jsx Outdated Show resolved Hide resolved
examples/express/src/components/MyFragment.jsx Outdated Show resolved Hide resolved
examples/express/src/pages/App.jsx Outdated Show resolved Hide resolved
examples/express/yarn-error.log Outdated Show resolved Hide resolved
examples/next/default.vcl Outdated Show resolved Hide resolved
src/__tests__/server/server.test.tsx Outdated Show resolved Hide resolved
src/server.tsx Show resolved Hide resolved
src/server.tsx Outdated Show resolved Hide resolved
@J3m5 J3m5 marked this pull request as ready for review August 15, 2023 13:19
@J3m5
Copy link
Collaborator Author

J3m5 commented Aug 15, 2023

Everything should be ok now @dunglas

Copy link
Owner

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

So cool! I left some minor comments, and we'll be able to merge.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
.prettierignore Outdated Show resolved Hide resolved
.prettierignore Show resolved Hide resolved
examples/next/compose.yaml Outdated Show resolved Hide resolved
examples/next/pages/index.tsx Outdated Show resolved Hide resolved
src/withESI.tsx Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@J3m5
Copy link
Collaborator Author

J3m5 commented Sep 6, 2023

I've applied the remaining suggestions.
I also tried to reintroduce the attribute escaping of the esi:include element but it seems that the escaping is happening 2 times.
This cause the URL to be invalid and make varnish fail to request the fragment.
I don't know exactly where the second escaping is happening, I'm currently checking it but I think this happening on the user side, react may be escaping the url attribute by itself as the tests passes with the original snapshots.

@J3m5
Copy link
Collaborator Author

J3m5 commented Sep 6, 2023

@J3m5
Copy link
Collaborator Author

J3m5 commented Sep 6, 2023

The attributes from the generated html is indeed correctly escaped

<div>
  <h1>React ESI demo app</h1>
  <esi:include 
    alt="&quot;&#x27;&lt;&amp;Alt&gt;&#x27;&quot;" 
    src="/_fragment?fragment=MyFragment&amp;props=%7B%22greeting%22%3A%22Hello%21%22%2C%22esi%22%3A%7B%22attrs%22%3A%7B%22alt%22%3A%22%5C%22%27%3C%26Alt%3E%27%5C%22%22%7D%7D%7D&amp;sign=c7102a792fa20beeb85c02081698c855c42f3cf575503202bbed224bce793845"
  >
  </esi:include>
</div>

I think this is because we are not using renderToString or/and dangerouslySetInnerHTML anymore.
The remaining problem is that the esi:include tag is rendered as not self-closed, it's working with Varnish but we are not spec compliant.
To fix it we'll probably need to create a PR on the react repository.

@dunglas
Copy link
Owner

dunglas commented Sep 6, 2023

As ESI is an XML vocabulary, using the long form instead of a self-closing element is most likely spec-compliant.

@J3m5
Copy link
Collaborator Author

J3m5 commented Sep 7, 2023

As ESI is an XML vocabulary, using the long form instead of a self-closing element is most likely spec-compliant.

The spec says

The include element specifies a fragment for assembly and allows for two optionally specified behaviors. include is an empty element; it does not have a closing tag.

It doesn't say that it MUST NOT have a closing tag so, yes, we're probably good.

@J3m5
Copy link
Collaborator Author

J3m5 commented Oct 19, 2023

Hi @dunglas
I can't merge, is there anything to do on your side?

Copy link
Owner

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

LGTM. I made some small changes directly to your branch and granted you the commit bit @J3m5. Feel free to merge!

examples/next/default.vcl Outdated Show resolved Hide resolved
@dunglas dunglas changed the title Maintenance feat: compatibility with latest versions of React and Next Jan 3, 2024
@gurnro
Copy link

gurnro commented Jan 6, 2024

<esi:include src="/_fragment?fragment=MyFragment&amp;props=%7B%22greeting%22%3A%22Hello%21%22%7D&amp;sign=69b6cc90a6744a633354c557183e6222cba2a3eae6f402cbe8eb2f525469f122" />

This is whats output to the page in the express example so matches the spec as per your conversation previously. All tests are passing this looks great. Wish I'd have seen this PR before checking out main - doh!

Excellent work!

@J3m5 J3m5 merged commit 8212165 into dunglas:main Feb 26, 2024
3 checks passed
@J3m5 J3m5 deleted the Maintenance branch February 26, 2024 14:40
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.

Maintenance: Dependencies, React 18, New Next.js Example, and Hook Implementation
3 participants