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

Replace narrow non break space with normal space #87

Merged
merged 2 commits into from
Mar 13, 2023

Conversation

brookslybrand
Copy link
Collaborator

A simpler alternative to #84

To test

  • Enable JS in root.tsx
  • Return the following from routes/index.tsx (since we don't have an upcoming event posted yet)
  return json({
    link: "meetup.com",
    nextEvent: {
      dateTime: "2022-01-01T01:00:00Z",
      going: 100,
      shortUrl: "meetup.com",
      title: "Awesome next meetup",
      venue: {
        name: "Online",
        address: "",
        city: "",
        state: "",
      },
    },
  });
  • Ensure there are no hydrate errors

Closes #83

Comment on lines 25 to 33
function formatDateTime(dateTime: string) {
const narrownNonBreakSpace = String.fromCharCode(8239);

// Discrepency between server and client, see https://github.com/remix-austin/remixaustin-com/issues/83#issuecomment-1450654389
return EVENT_TIME_FORMAT.format(new Date(dateTime)).replaceAll(
narrownNonBreakSpace,
" "
);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eventually we can pull this into a util file, but I'd rather wait to do that until I see multiple components/functions using it

Copy link
Collaborator

Choose a reason for hiding this comment

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

i'd expect there to be a corresponding test for this logic. (also, a nitpick would be to make narrownNonBreakSpace a constant outside the function somewhere (maybe in the utils?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was being lazy, thanks for calling this out. And yeah, definitely could make that a constant since it doesn't need to be reevaluated on each function call. I suppose I can go ahead and pull this out in a util file so I can easily test it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a test, if it looks good I'll go ahead and merge.

I wasn't able to figure out a good way to mock Intl.DateTimeFormat to force it to use the narrow non-break space. Didn't feel like it was worth much more time, but if someone has a solution I'm all ears. Otherwise will merge.

Copy link
Collaborator

@colbywhite colbywhite left a comment

Choose a reason for hiding this comment

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

i like this solution better. much simpler.

Comment on lines 25 to 33
function formatDateTime(dateTime: string) {
const narrownNonBreakSpace = String.fromCharCode(8239);

// Discrepency between server and client, see https://github.com/remix-austin/remixaustin-com/issues/83#issuecomment-1450654389
return EVENT_TIME_FORMAT.format(new Date(dateTime)).replaceAll(
narrownNonBreakSpace,
" "
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'd expect there to be a corresponding test for this logic. (also, a nitpick would be to make narrownNonBreakSpace a constant outside the function somewhere (maybe in the utils?)

@grantnorwood
Copy link
Collaborator

Pulled it down and it ran great! Thanks!

@brookslybrand brookslybrand merged commit f86e698 into main Mar 13, 2023
@brookslybrand brookslybrand deleted the bl/83/attempt-2 branch March 13, 2023 14:02
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.

Hydration errors when enabling JavaScript
3 participants