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

Disable the Hydrate task on client only configs #58

Merged
merged 2 commits into from
Jan 14, 2021
Merged

Disable the Hydrate task on client only configs #58

merged 2 commits into from
Jan 14, 2021

Conversation

robinmetral
Copy link
Contributor

@robinmetral robinmetral commented Nov 13, 2020

Closes #57

There are obviously several ways to do this. I chose not to do it in preset/client.tsx because it would have required to export a function (taking an allowedGroups param) instead of an object (which is the current export in both the client and server presets).

I think that filtering the tasks in get-groups is a good option because the allowedGroups is already in use there, but I realise that this introduces some extra complexity (it will break if we change the Hydrate task's name).

Happy to take any feedback!

@atlassian-cla-bot
Copy link

atlassian-cla-bot bot commented Nov 13, 2020

Hooray! All contributors have signed the CLA.

@DarkPurple141
Copy link
Contributor

Some initial thoughts here: Can we add a test for this - particularly with the hardcoded 'Hydrate'. These could potentially be better typed across the codebase as keys to facilitate this kind of behaviour in a smoother more typesafe way. Thanks for the contribution!

@DarkPurple141 DarkPurple141 self-requested a review December 4, 2020 00:21
@DarkPurple141 DarkPurple141 self-assigned this Dec 4, 2020
@robinmetral
Copy link
Contributor Author

Hi @DarkPurple141, sorry for my late reply and thanks for your feedback!

Totally agree this would be good to test. I've covered this as part of the group filtering spec, I think this is where it makes the most sense. Let me know what you think!

@alexreardon
Copy link
Collaborator

This is an interesting one for sure. A 'hydrate' task does not make sense when there is no 'server' component, as hydrate requires SSR to work. Hydrate seems to straddle the line between client and server.

Copy link
Collaborator

@alexreardon alexreardon left a comment

Choose a reason for hiding this comment

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

I am unsure if this is the best way to achieve this behaviour. I don't know exactly what the 'best way' would be right now

@@ -31,7 +31,13 @@ export function getGroups({
result.push(server);
}
if (allowedGroups.includes('client')) {
result.push(client);
const tasks = allowedGroups.includes('server')
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems brittle to me - what if we changed the task name in the future?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to allow hydrate both server and client needs to be in the allowed groups

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see, this condition is inside a block that is checking for client and server

Can we add a comment to the code explaining that hydrate can only be run if both client and server is allowed?

@@ -15,7 +15,7 @@ import server from '../../src/tasks/preset/server';
it('should allow filtering of tasks (client only)', () => {
// 1: Initial render
const channel: Channel = new Channel({ async: false });
const { container, queryByText } = render(
const { container, queryByText, debug } = render(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think debug is needed now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about this, my editor probably forgot to warn me about it

@alexreardon
Copy link
Collaborator

Hydrate is not a client task: it requires renderToString
Hydrate is not a server task: it requires client side ReactDOM.hydrate

🤔

@@ -31,7 +31,13 @@ export function getGroups({
result.push(server);
}
if (allowedGroups.includes('client')) {
result.push(client);
const tasks = allowedGroups.includes('server')
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to allow hydrate both server and client needs to be in the allowed groups

@alexreardon
Copy link
Collaborator

Perhaps a string match on the task name "hydrate" is the best we can do for now...

@alexreardon
Copy link
Collaborator

I think the string matching on the task name is the best we can do at this stage without much larger changes. Only minor changes left then:

  • add a small comment to the code explaining why the hydrate task is being excluded from client tasks when server is not an allowed group
  • remove debug from the test file

@alexreardon
Copy link
Collaborator

Thanks for your work on this @robinmetral!! ❤️

@AndrewOCC AndrewOCC merged commit 6a9876f into atlassian-labs:master Jan 14, 2021
@AndrewOCC
Copy link
Contributor

I've merged this PR and will raise another one to make these minor changes – thanks @robinmetral 🎉

AndrewOCC added a commit that referenced this pull request Jan 14, 2021
…y-followup

Follow-up changes from "Disable the Hydrate task on client only configs" (#58)
@robinmetral robinmetral deleted the disable-hydrate-on-client-only branch January 14, 2021 14:47
@robinmetral
Copy link
Contributor Author

robinmetral commented Jan 14, 2021

Thanks everyone, sorry I couldn't address the last small comments before the merge, the discussion happened in the middle of the night for me 🙈

Thank you for picking it up @AndrewOCC!

Last small note, I think the new version 0.14 didn't get released to NPM, is this expected?

Thanks again for the great tool 🚀

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.

Hydrate is run when only client tasks are allowed
4 participants