Editing a Markdown file in a public share fails: TextContextProviderFactory::__construct(): Argument #5 ($userId) must be of type string, null given

Open Beginner friendly
#8,729 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php

Research direction

Start with lib/Provider/TextContextProviderFactory.php and lib/Provider/TextContextProvider.php, then check how PermissionService handles a null user ID. Add a regression test in tests/unit/Provider/TextContextProviderFactoryTest.php for factory construction with null and verify build() and buildForCard() return valid contexts. Done means public share editing no longer fails with this TypeError and the regression test passes.

Written by the indexing model from the issue text.

Description

0. Needs triage bug

Summary

After upgrading Nextcloud (35.0.2.2), editing a Markdown file in a public share fails with a 500 error. Deck's TextContextProviderFactory is resolved by the Text app for every registered text context, and on public shares there is no logged-in user, so the DI container injects null into the non-nullable string $userId constructor parameter.
Steps to reproduce

Create a public share link for a Markdown (.md) file
Open the share and start editing the file
The sync request POST /index.php/apps/text/public/session/<id>/sync fails

Error

OCA\Deck\Provider\TextContextProviderFactory::__construct(): Argument #5 ($userId) must be of type string, null given
in /nextcloud/apps/deck/lib/Provider/TextContextProviderFactory.php line 20

Relevant trace: OCA\Text\Controller\PublicSessionController::sync → ApiService::getContext → ContextManager::getContexts → dispatchTyped(RegisterContextEvent) → ServiceEventListener → SimpleContainer::resolve(TextContextProviderFactory::class) → TypeError.

Expected behavior
Editing a Markdown file in a public share works; Deck's context factory must not crash when no user is logged in.

Proposed solution
Widen the constructor parameter to nullable in both classes, since the downstream consumer already accepts null:

lib/Provider/TextContextProviderFactory.php:25: string $userId → ?string $userId
lib/Provider/TextContextProvider.php:34: string $userId → ?string $userId

PermissionService::checkPermission(..., $userId = null) (lib/Service/PermissionService.php:172) and userCan()/userIsBoardOwner() already handle null, so with no user the context simply resolves to read-only instead of throwing a TypeError. A regression test (tests/unit/Provider/TextContextProviderFactoryTest.php) constructs the factory with null userId and asserts build()/buildForCard() still return a valid context.

Environment
Nextcloud 35.0.2.2, Deck current master, Text app public share session

Dominant language
JavaScript
Stars
1.4k
Forks
363
Avg merge
1d 5h
Merged PRs (30d)
118

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud/deck

All issues in nextcloud/deck

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.