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

Upgrade perseus to npm published version. #9759

Merged
merged 12 commits into from
Jun 20, 2024

Conversation

rtibbles
Copy link
Member

@rtibbles rtibbles commented Oct 4, 2022

Summary

  • Upgrades our perseus version to the most recently published version on NPM after Khan Academy re-open sourced the code base.
  • Adds required dependency components KatexProvider and TeX for handling rendering, borrowing the latter from the the deprecated Khan React components
  • Updates the build scripts to simplify to just vendoring the Perseus JS and CSS for small tweaks and monkey patches
  • Moves some of the monkey patching into runtime code to simplify this and make more apparent
  • Uses specific imports from React and React-DOM to be clear about which elements we are using
  • Updates translation extraction to pull from the typescript files that Perseus packages have that expose the strings
  • Uses updated React context injection to provide strings for Perseus.
  • Removes the standalone webpack config for prebuilding the Perseus dist, and removes all dependencies related to that
  • Removes all previously patched globals that Perseus no longer relies on

Reviewer guidance

Test exercises in lots of different languages, and with lots of different exercise types! The most problematic are probably the more complex mathematical ones - graphs, lots of mathematical formulae etc.


Fixes #8362

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@rtibbles rtibbles added the TODO: needs review Waiting for review label Oct 4, 2022
@pcenov
Copy link
Member

pcenov commented Oct 6, 2022

Hi @rtibbles, I was able to identify just the following issues by extensively testing various perseus exercises in multiple languages (valid in quiz, lesson or library context):

Issue Screenshot
Multiple choice questions - It's not possible to deselect a selected answer 2022-10-06_18-03-43
:-------------------------: :-------------------------:
Fields with option to enter exponents or fractions are not keeping the selected value 2022-10-06_17-00-57
:-------------------------: :-------------------------:
Multiple "Not allowed to use local resource" errors in the console with seemingly no user facing consequences 2022-10-06_18-22-50
:-------------------------: :-------------------------:

The issues above can be replicated by importing Khan Academy (English - US curriculum) > Math by grade > 8th Grade > Illustrative Mathematics

@rtibbles
Copy link
Member Author

rtibbles commented Oct 6, 2022

Thanks @pcenov - I assumed that there is no way this could have gone as smoothly as I thought it had! Will look into these issues, thanks for the precise reference for replication.

nucleogenesis
nucleogenesis previously approved these changes Oct 17, 2022
Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Code LGTM so long as it passes manual QA. Added comments for context are much appreciated (probably mostly by you some years later when you find the need to revendor Perseus).

Comment on lines 129 to 62
// Keep a global register of all image URLs at the module level,
// so that even if we have multiple instances of the PerseusRenderer
// instantiated at once, we can still render images from all of them.
// This also allows us to only monkey patch the Util functions once as
// well, and prevent duelling components from overriding each other.
Copy link
Member

Choose a reason for hiding this comment

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

Multi-modal friendliness <3

@rtibbles rtibbles dismissed nucleogenesis’s stale review October 17, 2022 22:33

Dismissing to block merge until manual QA finalized.

@pcenov
Copy link
Member

pcenov commented Jan 4, 2023

Hi @rtibbles, after testing the latest build the issue with the exponents and fractions disappearing is still valid while the one with the single/multiple choice questions is partially fixed as it is now possible to deselect a selected answer but there are some blue lines displayed each time I make a selection, a yellow border displayed if I deselect a selected answer and also if I navigate to another question after having deselected my answer when I go back to the same question the answer is selected again. Videos:

Issue Screenshot
Single/Multiple choice questions issues https://user-images.githubusercontent.com/79847249/210579142-8453ea15-e769-443d-8953-cbdf8c3d0f5b.mp4
:-------------------------: :-------------------------:
Fields with option to enter exponents or fractions are not keeping the selected value https://user-images.githubusercontent.com/79847249/210579236-32854c6d-8582-4e02-a991-a837b73d434a.mp4
:-------------------------: :-------------------------:

@pcenov
Copy link
Member

pcenov commented Jan 6, 2023

@rtibbles following a discussion in Slack I tested the reported issue with the missing bar graph and I can confirm that I am able to replicate it both at https://content-demo.learningequality.org/en/learn/#/topics/t/b18a118b93dc52fe9f1c68f9e418aaf5/search and when using the latest build from this PR.
The difference is that at content-demo the bar graph is not being displayed at all while it is partially displayed in the latest build:

2023-01-06_17-26-28

Here's also a video of what is being displayed in the latest build:

2023-01-06_17-41-13.mp4

I also noticed an issue with one multiple-select question where the text for the number of answers that need to be selected is not displayed correctly:

2023-01-06_18-00-47

@pcenov
Copy link
Member

pcenov commented Jun 17, 2024

Hi @rtibbles - I confirm that the keyboard is displayed now and it works correctly when viewing an exercise from the Library page. However when you create a quiz and attempt to fill in an answer the keyboard is displayed too high and also doesn't fit the screen properly (at least on my Note 10 Samsung phone which has a very large screen) so that the Back and Close button are invisible to the user unless the user drags the keyboard to the left. See the video:

quiz.view.mp4

@rtibbles
Copy link
Member Author

Hi @pcenov I think I came up with a solution that seems to work well for both the exercise and quiz contexts, hopefully this is robust!

image

@pcenov
Copy link
Member

pcenov commented Jun 18, 2024

Hi @rtibbles I confirm that now the keyboard fits better withing the screen in the Android app. Here's how it looks when compared to the previous implementation - might be worth investigating whether it can be further improved in a follow-up PR:

2024-06-18_14-32-58

Also when testing the .deb build if I shrink the browser width to less than 820px the on-screen keyboard pops up, which shouldn't be so, right:

2024-06-18_14-53-50

@rtibbles
Copy link
Member Author

@pcenov this seems to have been a change by Khan Academy within perseus to display the keypad even on desktop - I think I'm ok with leaving it in, as it still allows use of the regular keys to enter the response. I think this may be a replacement for some of the previous tooltips they used to suggest permissable values (like pi, etc).

@rtibbles
Copy link
Member Author

Oh.. or maybe not, as although it pops up, it doesn't actually allow input via the keypad.

@rtibbles
Copy link
Member Author

OK, I have updated it so that the keypad does always show, regardless of modality, due to the lack of tooltips to offer prompts for how to answer, but in doing so, have also made sure that it works regardless of modality, and can still do keyboard input as well.

Copy link
Member

@marcellamaki marcellamaki left a comment

Choose a reason for hiding this comment

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

minimal feedback so far. I think reading commit by commit, the code is.... as comprehensible as it can be (most of the complexity related to our use of perseus in general, not the method of implementation)

line-height: 1.2;
}

table.periodic-table td.element div.atomic-num {
Copy link
Member

Choose a reason for hiding this comment

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

Is this intentionally empty? (it looks like one of the few places there were more recent modifications which is why I ask)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah - the dist files are just directly copied from KA's npm packages, so 🤷 - I take no responsibility for these, except the minor manipulations we make to have valid font file URLs in them.

@pcenov
Copy link
Member

pcenov commented Jun 19, 2024

Hi @rtibbles,
I confirm that the onscreen keyboard is now always displayed in both full-screen of a desktop browser and in mobile view. It works correctly in the Android app, but it's best to further discuss what can be improved there from usability point of view as for some exercises the keyboard is pushed at the lower end of the screen and the user has to be smart enough to scroll up in order to use it. :)

Also spotted the following issues:

  1. I was having trouble with installing the latest build assets, getting the following error when I run Kolibri:

Ubuntu:

Running migrations:
  Applying morango.0003_auto_20170519_0543...Error: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/kolibri/utils/cli.py", line 189, in invoke
    initialize(**get_initialize_params())
  File "/usr/lib/python3/dist-packages/kolibri/utils/main.py", line 342, in initialize
    update(version, kolibri.__version__)
  File "/usr/lib/python3/dist-packages/kolibri/utils/main.py", line 396, in update
    _migrate_databases()
  File "/usr/lib/python3/dist-packages/kolibri/utils/main.py", line 109, in _migrate_databases
    call_command("migrate", interactive=False, database=database)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/management/commands/migrate.py", line 246, in handle
    fake_initial=fake_initial,
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/migrations/operations/fields.py", line 353, in database_forwards
    to_model._meta.get_field(self.new_name),
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/db/backends/sqlite3/schema.py", line 115, in alter_field
    ) % (model._meta.db_table, old_field_name))
django.db.utils.NotSupportedError: Renaming the 'morango_scopedefinition'.'scope_id' column while in a transaction is not supported on SQLite < 3.26 because it would break referential integrity. Try adding `atomic = False` to the Migration class.

Windows:

C:\Users\Kolibri>kolibri start --foreground
←[37mINFO     2024-06-19 17:13:58,310 Option DEBUG in section [Server] being overridden by environment variable KOLIBRI_DEBUG←[0m
←[37mINFO     2024-06-19 17:13:58,313 Option DEBUG_LOG_DATABASE in section [Server] being overridden by environment variable KOLIBRI_DEBUG_LOG_DATABASE←[0m
←[37mINFO     2024-06-19 17:13:58,313 Option RUN_MODE in section [Deployment] being overridden by environment variable KOLIBRI_RUN_MODE←[0m
←[37mINFO     2024-06-19 17:13:58,313 Attempting to setup using pre-migrated databases←[0m
c:\python36\lib\site-packages\kolibri\dist\morango\models\fields\crypto.py:23: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.backends import default_backend
←[37mINFO     2024-06-19 17:14:01,438 Running Kolibri with the following settings: kolibri.deployment.default.settings.base←[0m
←[37mINFO     2024-06-19 17:14:01,750 New install, version: 0.17.0a0.dev0+git.43.gf4569e12←[0m
←[37mINFO     2024-06-19 17:14:01,750 Running update routines for new version...←[0m
Operations to perform:
  Apply all migrations: analytics, auth, bookmarks, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, notifications, sessions
Running migrations:
  Applying morango.0003_auto_20170519_0543...Error: Traceback (most recent call last):
  File "c:\python36\lib\site-packages\kolibri\utils\cli.py", line 189, in invoke
    initialize(**get_initialize_params())
  File "c:\python36\lib\site-packages\kolibri\utils\main.py", line 342, in initialize
    update(version, kolibri.__version__)
  File "c:\python36\lib\site-packages\kolibri\utils\main.py", line 396, in update
    _migrate_databases()
  File "c:\python36\lib\site-packages\kolibri\utils\main.py", line 109, in _migrate_databases
    call_command("migrate", interactive=False, database=database)
  File "c:\python36\lib\site-packages\kolibri\dist\django\core\management\__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "c:\python36\lib\site-packages\kolibri\dist\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "c:\python36\lib\site-packages\kolibri\dist\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "c:\python36\lib\site-packages\kolibri\dist\django\core\management\commands\migrate.py", line 246, in handle
    fake_initial=fake_initial,
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\migrations\migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\migrations\operations\fields.py", line 353, in database_forwards
    to_model._meta.get_field(self.new_name),
  File "c:\python36\lib\site-packages\kolibri\dist\django\db\backends\sqlite3\schema.py", line 115, in alter_field
    ) % (model._meta.db_table, old_field_name))
django.db.utils.NotSupportedError: Renaming the 'morango_scopedefinition'.'scope_id' column while in a transaction is not supported on SQLite < 3.26 because it would break referential integrity. Try adding `atomic = False` to the Migration class.
  1. I did manage to install the build in another Ubuntu VM and the issues I am seeing with the on-screen keyboard are:
  • when answering the questions in a quiz it seems that the focus is not in the input field so that the selected value from the keyboard is not entered in the field. But even if I manually input it sometimes it just disappears when I revisit the question:
2024-06-19_17-30-06.mp4

Here's the error in the console:
browser-console-error.log

  • When using the TAB key to navigate if I close the onscreen keyboard that's treated as an incorrect answer:
tab.mp4

@rtibbles
Copy link
Member Author

1 is definitely not related to the changes here, I have filed a follow up issue for it here: learningequality/morango#224

@rtibbles
Copy link
Member Author

@pcenov I have fixed the inadvertent submission error you saw when dismissing the keypad, I was unable to replicate the other issue, and have filed a follow up here: #12322 if you could post the database from there so I can replicate, that would be helpful.

The error that is occurring is due to the answer not matching to the question, so I am trying to work out how that has happened.

@marcellamaki
Copy link
Member

re-testing of the mobile keyboard close input confirms that issue Peter noted is resolved

Copy link
Member

@marcellamaki marcellamaki left a comment

Choose a reason for hiding this comment

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

Thank you, @rtibbles - with my last manual QA test, I've confirmed the remaining bug that Peter found is resolved

@rtibbles rtibbles merged commit 0e1ff08 into learningequality:develop Jun 20, 2024
31 checks passed
@rtibbles rtibbles deleted the medusa branch June 20, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: frontend DEV: renderers HTML5 apps, videos, exercises, etc. DEV: tools Internal tooling for development SIZE: very large TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

upgrade KA simple-markdown for perseus-viewer
4 participants