Fix rehype accessible table plugins - #2493
Conversation
✅ Deploy Preview for expressjscom-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
krzysdz
left a comment
There was a problem hiding this comment.
Somehow this PR breaks multiple things (other plugins?).
The tables in "Moving to Express 4" don't have scope on <th> elements, because :<tbody> is missing
If I'm reading the code (and old comments) correctly these should have scope="row" (according to code, not really how it should be). On a closer look scope seems to be missing everywhere (e.g. in the routing guide).
As a side note, I've noticed that the HTML <table>s have <p>s inside cells if the text is multiline. In the big tables ("behind proxies") this is may not be obvious, but in "Migrating to Express 4" only some rows have <p> elements and this causes them to have much bigger padding than other rows - rewriting them to Markdown (#2485) lets us avoid this and fixes the table structure (missing <thead>).
| }), | ||
| accessibleTablesIntegration(), | ||
| mdx(), | ||
| mdx({ rehypePlugins: [rehypeAccessibleTables] }), |
There was a problem hiding this comment.
Something in this PR breaks syntax highlighting and adding <a> to headers (all plugins?) and I think this may be the culprit.
There was a problem hiding this comment.
Good catch, and thanks for the note. I only checked that scroll bars were being added for both HTML and Markdown-generated tables, and I m +1 on rewriting the two tables in #2485 to Markdown (Markdown tables render as semantic HTML in MDX and will produce thead/tbody structures). That approach makes sense and I support including those Markdown table changes from #2485. Converting every raw-HTML table across the site isn’t economical to do immediately we will keep converting pages over time as we come across them.
There was a problem hiding this comment.
Something in this PR breaks syntax highlighting and adding to headers (all plugins?) and I think this may be the culprit.
fixed in 6cde5c8
|
|
||
| parent.children.splice(index, 1, wrapper); | ||
| // Skip the inserted wrapper so we don't revisit the table inside it | ||
| return [SKIP, index + 1]; |
There was a problem hiding this comment.
Since now there is only a single visit() call, we must not skip visiting the children of inserted node (the <table> may be visited twice, but there is a parentAlreadyWrapped check) or the scope won't be added. However, there's a line in unist-util-visit readme that makes me think that using something else than SKIP when replacing a node may lead to problems:
Replacing
nodeitself, ifSKIPis not returned, still causes its descendants to be walked (which is a bug).
Maybe it would be safer to use a separate visit() call for adding the scope? I know that this comes with a performance hit (the website already takes a while to build), but it sounds like a better idea.
Even with this fixed, the tables in "Moving to Express 4" don't have the scope, because there is neither <thead> nor <tbody> in the source file - the <table> is directly followed by <tr>s:
expressjs.com/src/content/pages/en/guide/migrating-4.mdx
Lines 46 to 51 in f7b0338
Will you copy the rewritten tables from #2485 to this PR, or should I just remove the added lines with wrapper (from "behind proxies") and make #2485 just a rewrite of those 2 HTML tables to markdown?
There was a problem hiding this comment.
Maybe it would be safer to use a separate visit() call for adding the scope? I know that this comes with a performance hit (the website already takes a while to build), but it sounds like a better idea.
I am aware of this and may be optimize will improve build time. https://docs.astro.build/en/guides/integrations-guide/mdx/#optimize
make #2485 just a rewrite of those 2 HTML tables to markdown?
yes, rewrite tables from behind proxies. Rewritten markdown tables in "Moving to Express 4" LGTM.
…es and wrap tables without affecting traversal
|
4e49d37 Uses separate passes to keep AST traversal predictable while supporting both HAST and MDX JSX tables. Build time remains unchanged. |
| /* | ||
| * Don't continue traversing into the table after moving it. | ||
| * Scope processing has already happened in the previous passes. | ||
| */ | ||
| return; |
There was a problem hiding this comment.
Returning undefined will cause the visit() to check also the children nodes. SKIP should be returned if we don't want to traverse the children nodes.
I tested adding return SKIP here, in line 136, after line 116 and after line 93 - everything still works, no observable improvement in build time (the plugins probably don't affect it very much).
There was a problem hiding this comment.
SKIP should be returned if we don't want to traverse the children nodes.
It's bug you mentioned earlier.
This will be handled by expressjs#2493
|
This wrapper from a table in 5.1 release post can also be removed. It doesn't do anything, because the |
Co-authored-by: krzysdz <12915102+krzysdz@users.noreply.github.com>
|
removed html wrapper in 07c9eca
|
|
|



This plugin was failing because it only handled standard Hypertext Abstract Syntax Tree format table nodes and missed tables authored as raw HTML inside MDX/Markdown (mdxJsxFlowElement, mdxJsxTextElement).
The fix registers the plugin in both Markdown and MDX pipelines and updates the transform to support both raw HTML and standard table nodes, ensuring consistent scrollable table behavior.
This fixes the missing wrapper for raw HTML tables: https://deploy-preview-2493--expressjscom-preview.netlify.app/en/5x/guide/behind-proxies/
and markdown-generated tables: https://deploy-preview-2493--expressjscom-preview.netlify.app/en/resources/middleware/
closes #2484