Skip to content

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 25, 2017

This fixes #10265.
Verified by running SSR fixture with the fix (I no longer see the erroneous warnings).

I think we should get this in before the beta because otherwise SSR is somewhat unusable due to the false positives on every event.

The fix itself is rather gross. But it‘s the minimal one that works, and I don’t want to change too much before the beta. We know it will work because in principle it just reverts the DEV build to what it was before #10173.

I will start working on an alternative fix that forks injections instead of reusing them now. But I think this is an easier/safer thing to get in now.

I’ll also need to understand why tests didn’t catch this. Probably because event plugins are in a shared module so the list is singleton for both ReactDOM and ReactDOMServer in tests. And they share it even though actual bundles would not.

I understand it now. See followup comment.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

I split the fix in two commits now.

The first one fixes an issue with our integration tests. Client and server renderers used to share some modules (e.g. event plugin list), and so the test was not representative of what happened in the wild. I added resetModules() for extra isolation between client and server, and this uncovered the bug (the tests were failing both for Stack and Fiber).

In the second commit, I have a crude fix that’s enough to get the tests passing again.

Client and server renderers still share some modules, including injections.
This means they have shared state in this test, potentially missing issues that would occur in real world.

After this change, the client and server modules are completely isolated in the test.
This makes the tests fail due to facebook#10265 (a real issue that was missed).
@gaearon gaearon force-pushed the fix-ssr-injection branch from 07c9fc4 to 0352c93 Compare July 25, 2017 14:41
@gaearon gaearon force-pushed the fix-ssr-injection branch from 0352c93 to c58ae24 Compare July 25, 2017 14:55
@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

After chatting with @spicyj I pushed a different fix. Instead of injecting the plugins in DEV, I skip on* property validation if no event plugins have been injected. This means you won’t get warnings about unknown events in SSR (but you’ll still see them on the client). Seems like okay compromise to me.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

I think the change to ReactDOMUnknownPropertyHook looks reasonable.

The ReactDOMServerIntegration-test is pretty dense and hard to follow. Too many levels of chained method calls between what we're testing and asserting, in this case. I tried to poke around a bit and verify that I can break the test but I didn't have much luck. I wonder if we should refactor this test to be more verbose but easier to follow?

Just an observation, but this test takes ~30 seconds to run in master and ~50 seconds to run in this branch.

@gaearon gaearon merged commit 4c46b6c into facebook:master Jul 25, 2017
@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

Just an observation, but this test takes ~30 seconds to run in master and ~50 seconds to run in this branch.

We can probably split it into multiple tests. Then multiple workers can run it instead of blocking a single worker for a super giant test file.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

I tried to poke around a bit and verify that I can break the test but I didn't have much luck.

(Follow up: we chatted and couldn’t reproduce this issue. The test seems to fail consistently if unknown attributes are added.)

@gaearon gaearon deleted the fix-ssr-injection branch July 25, 2017 16:02
// TODO: this is a hack for testing dynamic injection. Remove this when we decide
// how to do static injection instead.
// Now we reset the modules again to load the server renderer.
// Resetting is important because we want to avoid any shared state
Copy link
Collaborator

Choose a reason for hiding this comment

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

(y)

if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) {
return true;
}
if (EventPluginRegistry.plugins.length === 0 && name.indexOf('on') === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be nice to do /^on[A-Z]/.test(name) here -- that is, only counting properties with a capital letter after "on". Then onions={true} is caught. Since this is SSR only I guess it isn't a big deal.

lgtm otherwise, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, thanks for pointing it out! I totally did not think about the onions. 😛

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I considered this but thought it wasn't worth the tradeoff- (regex is much slower)- given that the DOM render would warn about onions when the client took over.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regex shouldn't be that much slower in practice.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's probably not enough of a difference to actually matter. And it's dev-only anyway I guess.

https://jsperf.com/asdiohsd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid "unknown prop" warnings for SSR

4 participants