Skip to content

fix: load sequences in unit page #1867

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ihor-romaniuk
Copy link
Contributor

@ihor-romaniuk ihor-romaniuk commented Apr 28, 2025

Description

Handle loading errors when opening the course unit page via direct link as an unauthorized user.

Backport:

Screenshots

Case 1: Open course unit page
image

Case 2: Open Split Test xblock content
image

Unexpected Application Error!
Cannot read properties of undefined (reading 'upstreamLink')
TypeError: Cannot read properties of undefined (reading 'upstreamLink')
    at T2 (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/app.a1ce6d6e6800b33ff46c.js:1:5941058)
    at pa (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1924360)
    at ks (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1938398)
    at wu (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1984168)
    at gl (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1972553)
    at hl (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1972481)
    at pl (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1972344)
    at nl (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1969179)
    at tl (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1967735)
    at _ (https://app.pr-1788-ba9a65.sandboxes.opencraft.hosting/authoring/457.db97dc1cceb0d252ed30.js:2:1005861)

Testing instructions

  • Open the course unit page directly while not signed in.
  • Sign in to the system.
  • Case 1
    -- Verify that the course unit page loads correctly after authentication.
  • Case 2
    -- Add Split Test xBlock
    -- Open Split Test xBlock content page
    -- Verify that the Split Test xBlock content page loads correctly.

Other information

Settings

EDX_PLATFORM_REPOSITORY: https://github.com/openedx/edx-platform.git
EDX_PLATFORM_VERSION: master

TUTOR_GROVE_WAFFLE_FLAGS:
  - name: contentstore.new_studio_mfe.use_new_unit_page
    everyone: true

TUTOR_GROVE_NEW_MFES:
  authoring:
    port: 18000
    repository: https://github.com/raccoongang/frontend-app-course-authoring.git
    version: romaniuk/fix/load-sequences

TUTOR_GROVE_MFE_LMS_COMMON_SETTINGS: |
  MFE_CONFIG["ENABLE_UNIT_PAGE"] = True
  MFE_CONFIG["ENABLE_NEW_EDITOR_PAGES"] = True

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 28, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 28, 2025

Thanks for the pull request, @ihor-romaniuk!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks
Copy link

Thanks for the pull request, @ihor-romaniuk!

This repository is currently maintained by @openedx/2u-tnl.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.99%. Comparing base (01243af) to head (0a58ddf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1867      +/-   ##
==========================================
+ Coverage   93.98%   93.99%   +0.01%     
==========================================
  Files        1155     1155              
  Lines       24146    24123      -23     
  Branches     5116     5117       +1     
==========================================
- Hits        22693    22675      -18     
+ Misses       1385     1380       -5     
  Partials       68       68              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 28, 2025
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from d83432e to a6892c0 Compare April 29, 2025 14:57
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from a6892c0 to ad1b589 Compare April 29, 2025 15:25
@ihor-romaniuk ihor-romaniuk marked this pull request as ready for review April 29, 2025 15:27
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from ad1b589 to a079913 Compare April 29, 2025 15:36
@bradenmacdonald
Copy link
Contributor

bradenmacdonald commented Apr 29, 2025

Open the course unit page directly while not signed in.

I think you are missing the root cause here.

When I open a unit page directly and then log in, without accessing other Authoring MFE pages first, I see this in the network logs:

The second request fails because the studio_session_id cookie is not set, and the /xblock/container/:id endpoint is not a "proper" REST API endpoint - it doesn't use DRF and doesn't accept auth headers, only cookies.

So really, I think we need to fix this properly - either:

  1. Remove all calls to the old /xblock/container/ endpoint and use /api/contentstore/v1/container_handler/ everywhere instead - this will also speed up loading because we don't call two similar APIs but just one. Or:
  2. Fix the old /xblock/container/ endpoint so that it accepts header authentication. But I'd strongly prefer option 1 because the old /xblock/container/ endpoint is also very confusing - if you open it in your browser without sending the right JSON headers, it shows a 404 error even though it's a valid URL.

It seems like there's also duplicate requests being made to each of these endpoints, so in the long term we really should be using React Query to load the data since it will de-duplicate the requests better.


However, if you don't have time to fix this "properly" now, I'm fine with merging the fix you've made here - it is reasonable. But my big concern is that we're just going to get more errors like this until we fix the root cause, especially in code that's not using TypeScript so nobody has any idea if fields like upstreamInfo are always defined or not.

@@ -12,15 +12,15 @@ export function useSequenceNavigationMetadata(courseId, currentSequenceId, curre
const isLastUnit = !nextUrl;
const sequenceIds = useSelector(getSequenceIds);
const sequenceIndex = sequenceIds.indexOf(currentSequenceId);
const unitIndex = sequence.unitIds.indexOf(currentUnitId);
const unitIndex = sequence.unitIds?.indexOf(currentUnitId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding ? means that unitIndex can be undefined, and in that case we shouldn't be adding to it below on line 21. If you convert this to TypeScript it would show this as an error:

Screenshot showing error

@bradenmacdonald
Copy link
Contributor

@navinkarkera @rpenido @pomegranited FYI on this PR/error.

@PKulkoRaccoonGang PKulkoRaccoonGang added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Apr 30, 2025
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions May 1, 2025
@arbrandes
Copy link
Contributor

What @bradenmacdonald said:

we're just going to get more errors like this until we fix the root cause

What I suggest is for a new issue to be created with the relevant info, and for us to merge this one as a workaround for Teak in the meantime.

@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from 3629deb to ea6e13b Compare May 7, 2025 12:01
@ihor-romaniuk
Copy link
Contributor Author

@arbrandes @bradenmacdonald Thanks for your feedback.

I have replaced the old /xblock/container/ endpoint with the new /api/contentstore/v1/container_handler/.
It helps us to remove duplicate requests and avoid errors which I fixed initially.

@ihor-romaniuk ihor-romaniuk added create-sandbox open-craft-grove should create a sandbox environment from this PR and removed create-sandbox open-craft-grove should create a sandbox environment from this PR labels May 7, 2025
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@arbrandes
Copy link
Contributor

@ihor-romaniuk, I still see the error (or an error) when I go to the unit page directly while logged out, then immediately log in:

image

This is in this PR's sandbox, btw.

@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from 7a3b305 to ce05909 Compare May 7, 2025 20:01
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from e34311a to 08f5a95 Compare May 9, 2025 10:55
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@ihor-romaniuk ihor-romaniuk added create-sandbox open-craft-grove should create a sandbox environment from this PR and removed create-sandbox open-craft-grove should create a sandbox environment from this PR labels May 9, 2025
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from 08f5a95 to 238faeb Compare May 9, 2025 14:11
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@ihor-romaniuk
Copy link
Contributor Author

@arbrandes I’ve finally resolved the issue with the instance.

The problem was caused by deploying from the wrong repository. We were deploying from the RG space frontend-app-course-authoring, but no changes were visible because the MFE ID was set to course-authoring instead of authoring.

I added a custom configuration to the sandbox settings, and everything is now working as expected:

TUTOR_GROVE_NEW_MFES:
  authoring:
    port: 18000
    repository: https://github.com/raccoongang/frontend-app-course-authoring.git
    version: romaniuk/fix/load-sequences

Please take a look when you get a chance.

@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from 238faeb to 598cbf6 Compare May 9, 2025 16:13
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@mphilbrick211 mphilbrick211 moved this from Ready for Review to In Eng Review in Contributions May 12, 2025
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from a98f89e to 7745430 Compare May 16, 2025 10:29
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@pomegranited
Copy link
Contributor

This is looking ready for CC review now -- @navinkarkera or @ChrisChV can you review? I'm not CC on this repo :)

@pomegranited
Copy link
Contributor

Hi @ihor-romaniuk , could you add a bit of test coverage to fix the code coverage?

@bradenmacdonald
Copy link
Contributor

@arbrandes Would you be able to take another look at this soon? I think it's a pretty high priority bugfix. Or do you need someone else to take on the review?

And yes, @ihor-romaniuk , we'll need the codecov check passing to be able to merge this.

@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/fix/load-sequences branch from 73cc156 to c5cda97 Compare May 27, 2025 20:44
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@ihor-romaniuk
Copy link
Contributor Author

@pomegranited @bradenmacdonald @arbrandes Test coverage was updated and it's ready for review.

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Nice! It's looking good and it fixes the bugs that I have seen. Since it's such a big refactor I'm not sure if we should backport it to Teak though. Perhaps just the

Screenshot 2025-05-28 at 12 01 09 PM

part, or some smaller bit like that is what we backport?

Edit: that's done - #2042

const courseSectionVerticalData = normalizeCourseSectionVerticalData(data);
courseSectionVerticalData.xblockInfo.readOnly = isUnitReadOnly(courseSectionVerticalData.xblockInfo);

return courseSectionVerticalData;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This function getCourseSectionVerticalData has a confusing name. The docstring just says "Get an object containing course section vertical data" but even as an expert on Open edX I wouldn't really know what "course section vertical data" is. How is that different from just "vertical data"? I think it's not.

Since we're using this function a lot more now, could we rename it to getVerticalData or getContainerData? That's way more clear, and matches what it's actually doing - it calls the container_handler endpoint which says "View for container xblock requests to get vertical data."

Copy link
Contributor

Choose a reason for hiding this comment

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

@ihor-romaniuk What do you think about renaming this before we merge?

@bradenmacdonald
Copy link
Contributor

@arbrandes would you be able to take a quick look here too before we merge, or no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

7 participants