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

Add end to end test for Suspense #260

Closed
wants to merge 2 commits into from
Closed

Conversation

bz2
Copy link
Contributor

@bz2 bz2 commented Sep 18, 2020

Lack of a Delayed item in the tree appears to be a bug.

Following up from #250 seems Suspense is the likely culprit as it also messes up the tree display components. Start of a test to reproduce/validate behaviour. Passes in current form, need to add some validations that fail.

@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2020

💥 No Changeset

Latest commit: ed7dcf4

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@@ -15,7 +15,7 @@
"archive": "git archive --format zip --output dist/source-code.zip master",
"lint": "eslint 'src/**/*.{ts,tsx}' 'test-e2e/**/*.ts'",
"test": "mochette -c tsconfig.cjs.json 'src/**/*.test.{ts,tsx}'",
"test-e2e": "TS_NODE_PROJECT=tsconfig.cjs.json yarn ts-node test-e2e/run.ts --default-timeout 2000",
"test-e2e": "TS_NODE_PROJECT=tsconfig.cjs.json ts-node test-e2e/run.ts --default-timeout 2000",
Copy link
Member

Choose a reason for hiding this comment

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

Good catch 👍

@marvinhagemeister
Copy link
Member

marvinhagemeister commented Sep 18, 2020

Took a look why the Suspense component doesn't have the correct name in the elements panel and it's caused by a missing mangling property name in vnode.ts. There is even a comment about that, but it looks like I didn't get around to fix it earlier. Here is a patch that fixes it and displays Suspense components as "Suspense" as one expects it to.

--- a/src/adapter/10/vnode.ts
+++ b/src/adapter/10/vnode.ts
@@ -57,8 +57,13 @@ export function hasDom(x: any): boolean {
  */
 export function isSuspenseVNode(vnode: VNode): boolean {
 	const c = getComponent(vnode) as any;
-	// FIXME: Mangling of `_childDidSuspend` is not stable in Preact
-	return c != null && c._childDidSuspend;
+	return !!(
+		c != null &&
+		(c._childDidSuspend || // < Preact 10.3.0, mangling name was unstable
+			// >= Preact 10.3.0
+			c._pendingSuspensionCount ||
+			c.__u)
+	);
 }
 
 /**
@@ -185,6 +190,11 @@ export function getDisplayName(vnode: VNode, config: RendererConfig10): string {
 					return `${ctx.displayName}.Provider`;
 				}
 			}
+
+			// Suspense
+			if (isSuspenseVNode(vnode)) {
+				return "Suspense";
+			}
 		}
 
 		return type.displayName || type.name || "Anonymous";

@bz2
Copy link
Contributor Author

bz2 commented Sep 18, 2020

@marvinhagemeister Thanks! Had wondered if it was mangling related but not found the right bit of code yet. Your diff does fix the display of Suspense and probably worth landing that and this test as step one regardless, but two bits of follow up:

  1. Is the right check c._pendingSuspensionCount >= 0 || c.__u >= 0? Could do !!c.__c but several things are mangled to __c so perhaps there's overlap?

  2. The contents of Suspense in the devtools still needs some fixing. Currently it's Suspense > m > Skeleton before the timeout, and Suspense > m after with none of the final content displayed. Need to do a bit more peeking into Suspense internals? Though, it should be props.children that's the final result.

@bz2 bz2 force-pushed the test_e2e_suspense branch from a7bdbc6 to 449a04e Compare September 18, 2020 23:40
@bz2 bz2 marked this pull request as ready for review September 18, 2020 23:40
@bz2 bz2 force-pushed the test_e2e_suspense branch from 449a04e to 6c8e464 Compare September 18, 2020 23:41
@marvinhagemeister
Copy link
Member

@bz2 Agree about landing the change as is. Whenever there is a bit of activity in this repo I tend to roll out releases on a weekly basis and having the proper Suspense name show up is already an improvement worth releasing.

Regarding your questions:

  1. Is the right check c._pendingSuspensionCount >= 0 || c.__u >= 0? Could do !!c.__c but several things are mangled to __c so perhaps there's overlap?

Ah good point! I've checked it again and we're save to use __c here. With the mangling naming in Preact we're very attentive to only re-use the same mangling name, if the underlying object is different. You're suggestion to use !!c.__c is the best one in my opinion 👍

  1. The contents of Suspense in the devtools still needs some fixing. Currently it's Suspense > m > Skeleton before the timeout, and Suspense > m after with none of the final content displayed. Need to do a bit more peeking into Suspense internals? Though, it should be props.children that's the final result.

I'm a huge fan of splitting work up in chunks. It's totally ok if this PR solves the detection of Suspense and the next one deals with the actual implementation 👍

bz2 and others added 2 commits September 19, 2020 15:30
Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
Basics of a Suspense node appearing are validated, but not yet all
details as devtools does not display final children yet.
@bz2 bz2 force-pushed the test_e2e_suspense branch from 6c8e464 to ed7dcf4 Compare September 19, 2020 14:33
@bz2 bz2 changed the title WIP: Add end to end test for Suspense Add end to end test for Suspense Sep 19, 2020
@marvinhagemeister
Copy link
Member

Good news: I've made a branch based of this one and added commits that finish the Suspense integration, se #265. Kept the commit history intact, so the changes in this PR landed with it. Therefore this PR can be closed.

Another PR for toggling suspense state is also incoming 👍

@bz2
Copy link
Contributor Author

bz2 commented Sep 22, 2020

@marvinhagemeister Amazing! Thanks for chasing down.

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.

2 participants