-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add "key" attribute to suppress react "key" warnings (#238)
Fixes #233 * fix: add key attribute to placeholder template element To suppress react key warnings in SSR. * fix(client): add key attribute to each nested element in runtime To suppress react key warnings in runtime. * refactor: use `createElement` instead of `jsx` for compatibility with react
- Loading branch information
Showing
8 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { buildCreateChildrenFn } from './runtime' | ||
|
||
describe('buildCreateChildrenFn', () => { | ||
it('should set key for children', async () => { | ||
const createElement = vi.fn() | ||
const importComponent = vi.fn() | ||
const createChildren = buildCreateChildrenFn(createElement, importComponent) | ||
|
||
const div = document.createElement('div') | ||
div.innerHTML = '<span>test</span><div>test2</div>' | ||
const result = await createChildren(div.childNodes) | ||
expect(createElement).toHaveBeenNthCalledWith(1, 'SPAN', { | ||
children: ['test'], | ||
key: 1, | ||
}) | ||
expect(createElement).toHaveBeenNthCalledWith(2, 'DIV', { | ||
children: ['test2'], | ||
key: 2, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { HonoXIsland } from './honox-island' | ||
|
||
const TestComponent = () => <div>Test</div> | ||
|
||
describe('HonoXIsland', () => { | ||
it('should set key for children', () => { | ||
const element = HonoXIsland({ | ||
componentName: 'Test', | ||
componentExport: 'Test', | ||
Component: () => <div>Test</div>, | ||
props: { | ||
children: <TestComponent />, | ||
}, | ||
}) | ||
// XXX: tested by internal implementation | ||
expect((element as any).children[1][0].key).toBe('children') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters