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

Update MomentJS dependency #9382

Merged
merged 10 commits into from Apr 22, 2022

Conversation

budnix
Copy link
Member

@budnix budnix commented Apr 7, 2022

Context

The PR upgrades the moment library to 2.29.2. The PR applies all changes from the origin PR added by the bot (#9376), adds necessary changelog entry, and updates the package-lock.json file.

Migration guide

If I remember correctly, some of the users that use the MomentJS library within their apps struggle with an issue where the library was double transpiled in the bundle file. One version for the developer's app and one for Handsontable dependency. The workaround for that was using the same version of the library as Handsontable.

The PR changes the version, so it can be advisable to mention this in the migration guide.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Related issue(s):

  1. [Snyk] Security upgrade moment from 2.24.0 to 2.29.2 #9376
  2. fixes Moment library update, adapt to the changes in Moment's parsing of dates #9381

Affected project(s):

  • handsontable

Checklist:

@budnix budnix self-assigned this Apr 7, 2022
@budnix budnix marked this pull request as ready for review April 7, 2022 11:09
expect(getDataAtRow(2)).toEqual(['BMW', '320i Coupe', '07/24/2011', 30500]);
expect(getDataAtRow(3)).toEqual(['Audi', 'A4 Avant', '11/19/2011', 33900]);
expect(getDataAtRow(4)).toEqual(['Citroen', 'C4 Coupe', '12/01/2008', 8330]);
expect(getDataAtRow(0)).toEqual(['Opel', 'Astra', '02/02/2004', 7000]);
Copy link
Member

@warpech warpech Apr 7, 2022

Choose a reason for hiding this comment

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

I need some root-cause analysis of why is this changed.

Maybe the reviewer (@jansiegel) can explain this? I know that @budnix is busy with other issues.

Copy link
Member Author

@budnix budnix Apr 8, 2022

Choose a reason for hiding this comment

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

It seems that before updating the lib, the date values sorting does not work correctly. At least in that test case. For example, the results for sorting rows ascending:

Before (it's sorted without any noticeable pattern):

'01/14/2006'
'02/02/2004'
'07/24/2011'
'11/19/2011'
'12/01/2008'

After:

'02/02/2004'
'01/14/2006'
'12/01/2008'
'07/24/2011'
'11/19/2011'

Copy link
Member

@warpech warpech Apr 8, 2022

Choose a reason for hiding this comment

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

I am sorry, but this is not the root cause. The root cause seems related to the fact that the test, despite its name, provided wrongly formatted data to Moment.js, and tested that Moment.js does not sort in that case. After the change, Moment.js sorts even when it is given wrongly formatted data.

Compare the format given in line 1009 and the data provided in lines 996-1002

it('should sort date columns along with empty and null values', () => {
handsontable({
data: [
['Mercedes', 'A 160', '01/14/2006', 6999.9999],
['Citroen', 'C4 Coupe', '12/01/2008', 8330],
['Citroen', 'C4 Coupe null', null, 8330],
['Citroen', 'C4 Coupe empty', '', 8330],
['Audi', 'A4 Avant', '11/19/2011', 33900],
['Opel', 'Astra', '02/02/2004', 7000],
['BMW', '320i Coupe', '07/24/2011', 30500]
],
columns: [
{},
{},
{
type: 'date',
dateFormat: 'mm/dd/yy'

Copy link
Member

@jansiegel jansiegel Apr 8, 2022

Choose a reason for hiding this comment

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

it's sorted without any noticeable pattern

I think it was sorted kind of as a string, so in this case by the month number

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should use Moment.js in the strict mode? https://momentjs.com/guides/#/parsing/strict-mode/

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should use Moment.js in the strict mode? https://momentjs.com/guides/#/parsing/strict-mode/

I would be for it. It's better to only sort the date-type values based on the dateFormat. Without leaving the room for guesses.

Copy link
Member

@warpech warpech Apr 19, 2022

Choose a reason for hiding this comment

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

A partial root cause analysis by me:

TL;DR Moment team unknowingly changed the interpretation of incorrect dates. If we used strict, the problem would not appear. Because we didn't use strict, the problem slipped through.

I think we should enforce strict with an explanation in the migration guide.

Copy link
Member

Choose a reason for hiding this comment

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

I was advised that there are parts of Handsontable that treat the forgiving mode as a feature and we should not remove it. Discussion: https://handsoncode.slack.com/archives/C4PV4S33Q/p1650384660407479?thread_ts=1649328227.856499&cid=C4PV4S33Q

@warpech
Copy link
Member

warpech commented Apr 8, 2022

We discussed on the today's daily (https://kb.handsontable.com/pages/viewpage.action?pageId=56461739) that @jansiegel will take over this PR.

According to the notes from the daily, we need:

  1. much more tests to see what's changed
  2. specification what should happen when data does not match dateFormat (awaiting @krzysztofspilka)

@@ -1051,7 +1051,7 @@ describe('ColumnSorting', () => {
{},
{
type: 'date',
dateFormat: 'mm/dd/yy'
dateFormat: 'MM/DD/YYYY'
Copy link
Member

Choose a reason for hiding this comment

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

This file also uses the old notation dateFormat: 'mm/dd/yy' on lines 294, 1532 (and also in 2 places in multiColumnSorting.spec.js).

Why were other lines not affected?

Copy link
Member

@jansiegel jansiegel Apr 19, 2022

Choose a reason for hiding this comment

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

Those remaining tests seem to not be sorted by the column containing the dates, so the dateFormat is pretty much redundant, I'll change it, though.

@jansiegel jansiegel requested a review from warpech April 20, 2022 07:47
Copy link
Contributor

@kirszenbaum kirszenbaum left a comment

Choose a reason for hiding this comment

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

@jansiegel – I'm adding my changes in #9409

Just checking: should we update anything in the correctFormat API ref? https://handsontable.com/docs/api/options/#correctformat

@jansiegel
Copy link
Member

@kirszenbaum

Just checking: should we update anyting in the correctFormat API ref? https://handsontable.com/docs/api/options/#correctformat

I don't think so - our API didn't change, what has changed is some logic on Moment's side, so until we have a more detailed specification on what exactly we should allow being automatically corrected, I'd leave it as it is.

@kirszenbaum kirszenbaum self-requested a review April 22, 2022 08:25
@github-actions
Copy link

github-actions bot commented Apr 22, 2022

Launch the local version of documentation by running:

npm run docs:review 90dfc4f1d2b207457890fd44d2ff32ab27031c72

@jansiegel jansiegel merged commit 90dfc4f into develop Apr 22, 2022
@jansiegel jansiegel deleted the feature/snyk-fix-c3454c61088848cba1ba001bfb76870c branch April 22, 2022 09:28
jansiegel added a commit that referenced this pull request Apr 22, 2022
* Update MomentJS dependency

Origin: #9376

* Updating momentJS fixes an issue with sorting date values

The commit fixes the tests.

* Fix dateFormat pattern

* - Correct the date format on the remaining cases in multiColumnSorting.spec.js.

* Bump moment dependency for the 'handsontable' workspace and the root directory.

* Docs: Adding docs changes related to the Moment.js dependency update (#9409)

Co-authored-by: Jan Siegel <jansiegel@users.noreply.github.com>
Co-authored-by: Jan Siegel <js.ziggle@gmail.com>
Co-authored-by: Kuba Jakub <jakub.wisniewski@handsontable.com>
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.

None yet

4 participants