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

Fix instance where renderToStringAsync returns a promise of a promise #378

Merged
merged 14 commits into from
Jul 17, 2024

Conversation

ccouzens
Copy link
Contributor

Fixes #377

I have had this happen with a project I work on. This includes a minimal test reproduction of it.

ccouzens added 8 commits July 15, 2024 17:39
I want to test this in my project to see if this change fixes it.

All being well, I'll then add a test here and submit it for review
I'm unclear why the previous didn't seem to work for me
So far no luck actually reproducing the issue.

I will take a different tact and remove code from my app until the issue
goes away, to figure out what causes the behaviour.
Copy link

changeset-bot bot commented Jul 17, 2024

🦋 Changeset detected

Latest commit: 7bd6b29

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-render-to-string Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -175,4 +175,46 @@ describe('Async renderToString', () => {
const rendered = await promise;
expect(rendered).to.equal('<p>ok</p>');
});

it('should render JSX after a urql component', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

We might also want to try a test where it's triple-y nested as it might warrant a loop similar to the Array.isArray one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think this would look like?

If I do something like:

		const Context = createContext();

		let c = 0;

		const Fetcher = ({ children }) => {
			c++;
			if (c === 1) {
				throw Promise.resolve();
			}
			return <Fragment>{children}</Fragment>;
		};

		const LazyComponent = lazy(
			async () =>
				function ImportedComponent() {
					return <div>2</div>;
				}
		);

		const NestedLazyComponent = lazy(
			async () =>
				function ImportedComponent() {
					return (
						<Context.Provider>
							<Fetcher>
								<LoadableComponent />
							</Fetcher>
						</Context.Provider>
					);
				}
		);

		const LoadableComponent = ({}) => (
			<Suspense fallback={'...loading'}>
				<LazyComponent />
			</Suspense>
		);

		const NestedLoadableComponent = ({}) => (
			<Suspense fallback={'...loading'}>
				<NestedLazyComponent />
			</Suspense>
		);

		const rendered = await renderToStringAsync(
			<Context.Provider>
				<Fetcher>
					<NestedLoadableComponent />
				</Fetcher>
			</Context.Provider>
		);

		expect(rendered).to.equal(`<div>2</div>`);

Then the current solution continues to work

createSuspender();
const { Suspender: SuspenderTwo, suspended: suspendedTwo } =
createSuspender();
const {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The git commit formatter hook makes these changes. Let me know if you want me to keep them as is.

@JoviDeCroock
Copy link
Member

Have you tried breaking it by increasing the nesting even further? Just wondering 😅

@JoviDeCroock JoviDeCroock merged commit 054dae0 into preactjs:main Jul 17, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Jul 17, 2024
@ccouzens ccouzens deleted the patch-1 branch July 17, 2024 23:24
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.

renderToStringAsync can be confused by a Promise from _renderToString
2 participants